| 50 | } |
| 51 | |
| 52 | void ThreadedDispatchQueue::sync(const Valdi::DispatchFunction& function) { |
| 53 | if (_disableSyncCallsInCallingThread) { |
| 54 | std::promise<void> promise; |
| 55 | auto future = promise.get_future(); |
| 56 | |
| 57 | async([&function, &promise, this]() { |
| 58 | _runningSync = true; |
| 59 | function(); |
| 60 | |
| 61 | promise.set_value(); |
| 62 | _runningSync = false; |
| 63 | }); |
| 64 | |
| 65 | future.get(); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | _taskQueue->barrier([&]() { |
| 70 | auto* previousCurrent = current; |
| 71 | current = this; |
| 72 | _runningSync = true; |
| 73 | function(); |
| 74 | current = previousCurrent; |
| 75 | _runningSync = false; |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | void ThreadedDispatchQueue::async(Valdi::DispatchFunction function) { |
| 80 | auto task = _taskQueue->enqueue(std::move(function)); |