Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/libslic3r/Format/bbs_3mf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8218,8 +8218,22 @@ class _BBS_Backup_Manager
}

void set_post_callback(std::function<void(int)> c) {
boost::lock_guard lock(m_mutex);
m_post_callback = c;
// serialize the swap with in-flight invocation in operator()()
{
boost::lock_guard post_lock(m_post_callback_mutex);
m_post_callback = c;
}
// catch-up: a task queued while the callback was null missed its
// size()==1 notification; re-announce it or backup stalls until exit
if (c) {
bool pending;
{
boost::lock_guard lock(m_mutex);
pending = !m_ui_tasks.empty();
}
if (pending)
c(0); // outside m_mutex: only this thread drains m_ui_tasks
}
}

void run_ui_tasks() {
Expand Down Expand Up @@ -8513,14 +8527,17 @@ class _BBS_Backup_Manager
continue;
}
m_tasks.pop_front();
auto callback = m_post_callback;
lock.unlock();
process_task(t);
lock.lock();
if (t.type > None) {
m_ui_tasks.push_back(t);
if (m_ui_tasks.size() == 1 && callback)
callback(0);
if (m_ui_tasks.size() == 1) {
// re-read under lock: shutdown may swap in nullptr during process_task()
boost::lock_guard post_lock(m_post_callback_mutex);
if (m_post_callback)
m_post_callback(0);
}
}
}
}
Expand Down Expand Up @@ -8558,13 +8575,19 @@ class _BBS_Backup_Manager
size_t m_task_seq = 0;
// param 0: should call run_ui_tasks
// param 1: should backup current project
// contract: invoked with m_mutex held (worker); must not re-enter this
// manager. duplicate param-0 calls are fine: run_ui_tasks() drains the
// whole queue, extras are no-ops
std::function<void(int)> m_post_callback;
long m_interval = 1 * 60;
boost::system_time m_next_backup;
Model m_temp_model; // visit only in main thread
bool m_other_changes = false; // visit only in main thread
bool m_other_changes_backup = false; // visit only in main thread
std::vector<std::pair<ModelObject*, size_t>> m_gaurd_objects;
// serializes m_post_callback swap vs worker invocation; lock order: m_mutex -> m_post_callback_mutex
// boost primitives to match the class's existing synchronization (m_cond waits need boost locks)
boost::mutex m_post_callback_mutex;
boost::thread m_thread;
};

Expand Down