| 18 | } |
| 19 | |
| 20 | void ExecuteMainThreadActions() |
| 21 | { |
| 22 | CCP_STATS_ZONE( __FUNCTION__ ); |
| 23 | |
| 24 | static std::vector<std::function<void()>> actionsToProcess; |
| 25 | |
| 26 | invocations++; |
| 27 | if( invocations > 1 ) |
| 28 | { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | ON_BLOCK_EXIT( [] { |
| 33 | invocations = 0; |
| 34 | actionsToProcess.clear(); |
| 35 | } ); |
| 36 | |
| 37 | while( invocations > 0 ) |
| 38 | { |
| 39 | { |
| 40 | std::lock_guard<std::mutex> lock( mainThreadActionsMutex ); |
| 41 | actionsToProcess.swap( mainThreadActions ); |
| 42 | } |
| 43 | { |
| 44 | ScopedBlockTrap blockTrap; |
| 45 | for( auto& action : actionsToProcess ) |
| 46 | { |
| 47 | action(); |
| 48 | } |
| 49 | } |
| 50 | actionsToProcess.clear(); |
| 51 | invocations--; |
| 52 | } |
| 53 | } |