File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,16 @@ class TestWorker : public AsyncProgressWorker<ProgressData> {
34
34
SetError (" test error" );
35
35
}
36
36
ProgressData data{0 };
37
- std::unique_lock<std::mutex> lock (_cvm);
37
+
38
38
for (int32_t idx = 0 ; idx < _times; idx++) {
39
39
data.progress = idx;
40
40
progress.Send (&data, 1 );
41
- _cv.wait (lock);
41
+
42
+ {
43
+ std::unique_lock<std::mutex> lk (_cvm);
44
+ _cv.wait (lk, [this ] { return dataSent; });
45
+ dataSent = false ;
46
+ }
42
47
}
43
48
}
44
49
@@ -48,7 +53,12 @@ class TestWorker : public AsyncProgressWorker<ProgressData> {
48
53
Number progress = Number::New (env, data->progress );
49
54
_progress.MakeCallback (Receiver ().Value (), {progress});
50
55
}
51
- _cv.notify_one ();
56
+
57
+ {
58
+ std::lock_guard<std::mutex> lk (_cvm);
59
+ dataSent = true ;
60
+ _cv.notify_one ();
61
+ }
52
62
}
53
63
54
64
private:
@@ -59,6 +69,8 @@ class TestWorker : public AsyncProgressWorker<ProgressData> {
59
69
: AsyncProgressWorker(cb, resource_name, resource) {
60
70
_progress.Reset (progress, 1 );
61
71
}
72
+
73
+ bool dataSent = false ;
62
74
std::condition_variable _cv;
63
75
std::mutex _cvm;
64
76
int32_t _times;
You can’t perform that action at this time.
0 commit comments