| 27 | } |
| 28 | |
| 29 | void uiThreadScheduleTime(int ms) |
| 30 | { |
| 31 | std::vector<Runnable> tmp; |
| 32 | { |
| 33 | std::lock_guard<std::mutex> l(uithread::mutex); |
| 34 | tmp.swap(uithread::tasks); |
| 35 | } |
| 36 | auto rt = std::chrono::high_resolution_clock::now(); |
| 37 | auto timeouted = false; |
| 38 | std::vector<Runnable> unrun; |
| 39 | unrun.reserve(tmp.size()); |
| 40 | for (auto& task : tmp) { |
| 41 | if( timeouted) |
| 42 | { |
| 43 | unrun.push_back(task); |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | task(); |
| 48 | auto dt = std::chrono::high_resolution_clock::now() - rt; |
| 49 | auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(dt).count(); |
| 50 | timeouted = elapsed >= ms; |
| 51 | } |
| 52 | } |
| 53 | if(!unrun.empty()) { |
| 54 | std::lock_guard<std::mutex> l(uithread::mutex); |
| 55 | uithread::tasks.insert(uithread::tasks.begin(), unrun.begin(), unrun.end()); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void uiThreadScheduleCount(size_t count) |
| 60 | { |