fix deadlock condition varaible use in netfabb wrapper
This commit is contained in:
parent
24dc0317a2
commit
04ac99a54e
@ -326,9 +326,8 @@ public:
|
|||||||
// fix_result containes a message if fixing failed
|
// fix_result containes a message if fixing failed
|
||||||
bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, wxProgressDialog& progress_dialog, const wxString& msg_header, std::string& fix_result)
|
bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, wxProgressDialog& progress_dialog, const wxString& msg_header, std::string& fix_result)
|
||||||
{
|
{
|
||||||
std::mutex mutex;
|
std::mutex mtx;
|
||||||
std::condition_variable condition;
|
std::condition_variable condition;
|
||||||
std::unique_lock<std::mutex> lock(mutex);
|
|
||||||
struct Progress {
|
struct Progress {
|
||||||
std::string message;
|
std::string message;
|
||||||
int percent = 0;
|
int percent = 0;
|
||||||
@ -347,8 +346,8 @@ bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, wxPro
|
|||||||
// (It seems like wxWidgets initialize the COM contex as single threaded and we need a multi-threaded context).
|
// (It seems like wxWidgets initialize the COM contex as single threaded and we need a multi-threaded context).
|
||||||
bool success = false;
|
bool success = false;
|
||||||
size_t ivolume = 0;
|
size_t ivolume = 0;
|
||||||
auto on_progress = [&mutex, &condition, &ivolume, &volumes, &progress](const char *msg, unsigned prcnt) {
|
auto on_progress = [&mtx, &condition, &ivolume, &volumes, &progress](const char *msg, unsigned prcnt) {
|
||||||
std::lock_guard<std::mutex> lk(mutex);
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
progress.message = msg;
|
progress.message = msg;
|
||||||
progress.percent = (int)floor((float(prcnt) + float(ivolume) * 100.f) / float(volumes.size()));
|
progress.percent = (int)floor((float(prcnt) + float(ivolume) * 100.f) / float(volumes.size()));
|
||||||
progress.updated = true;
|
progress.updated = true;
|
||||||
@ -424,6 +423,7 @@ bool fix_model_by_win10_sdk_gui(ModelObject &model_object, int volume_idx, wxPro
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
while (! finished) {
|
while (! finished) {
|
||||||
|
std::unique_lock<std::mutex> lock(mtx);
|
||||||
condition.wait_for(lock, std::chrono::milliseconds(250), [&progress]{ return progress.updated; });
|
condition.wait_for(lock, std::chrono::milliseconds(250), [&progress]{ return progress.updated; });
|
||||||
// decrease progress.percent value to avoid closing of the progress dialog
|
// decrease progress.percent value to avoid closing of the progress dialog
|
||||||
if (!progress_dialog.Update(progress.percent-1, msg_header + _(progress.message)))
|
if (!progress_dialog.Update(progress.percent-1, msg_header + _(progress.message)))
|
||||||
|
Loading…
Reference in New Issue
Block a user