| 200 | } |
| 201 | |
| 202 | flushId = _batchFlushId; |
| 203 | // Increase flush id sequence, so that if there is a beginBatch() call |
| 204 | // that occurs while we are flushing the tasks of this batch, the tasks |
| 205 | // will be flushed on the next main thread tick. |
| 206 | _flushIdSequence++; |
| 207 | } |
| 208 | |
| 209 | // Flush all pending tasks. |
| 210 | flushTasksWithId(flushId); |
| 211 | |
| 212 | // Disable batching |
| 213 | std::lock_guard<std::mutex> lockGuard(_mutex); |
| 214 | SC_ASSERT(_batchCount == 1, "Unbalanced beginBatch() endBatch() call"); |
| 215 | _batchCount = 0; |
| 216 | _quiescenceCondition.notify_all(); |
| 217 | |
| 218 | if (flushId != _batchFlushId) { |
| 219 | // Our batch flush id changed, which means that a main thread batch task |
| 220 | // has been enqueued while we were flushing the tasks. We should flush |
| 221 | // them on the next main thread tick. |
| 222 | scheduleFlush(_batchFlushId, false); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void MainThreadManager::onIdle(const Ref<ValueFunction>& callback) { |
| 227 | std::lock_guard<std::mutex> lockGuard(_mutex); |
| 228 | _onIdleCallbacks.emplace_back(callback); |
| 229 | |
| 230 | if (!_idleFlushScheduled) { |
| 231 | _idleFlushScheduled = true; |
| 232 | |
| 233 | scheduleFlushIdleCallbacks(); |
| 234 | } |
no test coverage detected