Commit 92def969a7308f9f4bba377ed6590ce5ff28dc65
1 parent
3746e3d8
Perform main thread tasks outside of eventMutex
Showing
1 changed file
with
12 additions
and
3 deletions
mainapp.cpp
| ... | ... | @@ -538,12 +538,21 @@ void MainApp::start() |
| 538 | 538 | uint64_t eventfd_value = 0; |
| 539 | 539 | check<std::runtime_error>(read(cur_fd, &eventfd_value, sizeof(uint64_t))); |
| 540 | 540 | |
| 541 | - std::lock_guard<std::mutex> locker(eventMutex); | |
| 542 | - for(auto &f : taskQueue) | |
| 541 | + std::forward_list<std::function<void()>> tasks; | |
| 542 | + | |
| 543 | + { | |
| 544 | + std::lock_guard<std::mutex> locker(eventMutex); | |
| 545 | + for (auto &f : taskQueue) | |
| 546 | + { | |
| 547 | + tasks.push_front(f); | |
| 548 | + } | |
| 549 | + taskQueue.clear(); | |
| 550 | + } | |
| 551 | + | |
| 552 | + for(auto &f : tasks) | |
| 543 | 553 | { |
| 544 | 554 | f(); |
| 545 | 555 | } |
| 546 | - taskQueue.clear(); | |
| 547 | 556 | } |
| 548 | 557 | } |
| 549 | 558 | catch (std::exception &ex) | ... | ... |