@@ -111,10 +111,10 @@ std::shared_ptr<Task> RuntimeScheduler_Modern::scheduleIdleTask(
111
111
}
112
112
113
113
bool RuntimeScheduler_Modern::getShouldYield () noexcept {
114
- std::shared_lock lock (schedulingMutex_);
115
-
116
114
markYieldingOpportunity (now_ ());
117
115
116
+ std::shared_lock lock (schedulingMutex_);
117
+
118
118
return syncTaskRequests_ > 0 ||
119
119
(!taskQueue_.empty () && taskQueue_.top ().get () != currentTask_);
120
120
}
@@ -152,13 +152,12 @@ void RuntimeScheduler_Modern::executeNowOnTheSameThread(
152
152
153
153
syncTaskRequests_++;
154
154
executeSynchronouslyOnSameThread_CAN_DEADLOCK (
155
- runtimeExecutor_,
156
- [this , currentTime, &task](jsi::Runtime& runtime) mutable {
155
+ runtimeExecutor_, [&](jsi::Runtime& runtime) mutable {
157
156
TraceSection s2 (" RuntimeScheduler::executeNowOnTheSameThread callback" );
158
157
159
158
syncTaskRequests_--;
160
159
runtimePtr = &runtime;
161
- runEventLoopTick (runtime, task, currentTime );
160
+ runEventLoopTick (runtime, task);
162
161
runtimePtr = nullptr ;
163
162
});
164
163
@@ -249,37 +248,29 @@ void RuntimeScheduler_Modern::scheduleTask(std::shared_ptr<Task> task) {
249
248
}
250
249
251
250
void RuntimeScheduler_Modern::scheduleEventLoop () {
252
- runtimeExecutor_ (
253
- [this ](jsi::Runtime& runtime) { runEventLoop (runtime, false ); });
251
+ runtimeExecutor_ ([this ](jsi::Runtime& runtime) { runEventLoop (runtime); });
254
252
}
255
253
256
- void RuntimeScheduler_Modern::runEventLoop (
257
- jsi::Runtime& runtime,
258
- bool onlyExpired) {
254
+ void RuntimeScheduler_Modern::runEventLoop (jsi::Runtime& runtime) {
259
255
TraceSection s (" RuntimeScheduler::runEventLoop" );
260
256
261
257
auto previousPriority = currentPriority_;
262
258
263
- auto currentTime = now_ ();
264
259
// `selectTask` must be called unconditionaly to ensure that
265
260
// `isEventLoopScheduled_` is set to false and the event loop resume
266
261
// correctly if a synchronous task is scheduled.
267
262
// Unit test normalTaskYieldsToSynchronousAccessAndResumes covers this
268
263
// scenario.
269
- auto topPriorityTask = selectTask (currentTime, onlyExpired );
264
+ auto topPriorityTask = selectTask ();
270
265
while (topPriorityTask && syncTaskRequests_ == 0 ) {
271
- runEventLoopTick (runtime, *topPriorityTask, currentTime);
272
-
273
- currentTime = now_ ();
274
- topPriorityTask = selectTask (currentTime, onlyExpired);
266
+ runEventLoopTick (runtime, *topPriorityTask);
267
+ topPriorityTask = selectTask ();
275
268
}
276
269
277
270
currentPriority_ = previousPriority;
278
271
}
279
272
280
- std::shared_ptr<Task> RuntimeScheduler_Modern::selectTask (
281
- HighResTimeStamp currentTime,
282
- bool onlyExpired) {
273
+ std::shared_ptr<Task> RuntimeScheduler_Modern::selectTask () {
283
274
// We need a unique lock here because we'll also remove executed tasks from
284
275
// the top of the queue.
285
276
std::unique_lock lock (schedulingMutex_);
@@ -294,20 +285,15 @@ std::shared_ptr<Task> RuntimeScheduler_Modern::selectTask(
294
285
}
295
286
296
287
if (!taskQueue_.empty ()) {
297
- auto task = taskQueue_.top ();
298
- auto didUserCallbackTimeout = task->expirationTime <= currentTime;
299
- if (!onlyExpired || didUserCallbackTimeout) {
300
- return task;
301
- }
288
+ return taskQueue_.top ();
302
289
}
303
290
304
291
return nullptr ;
305
292
}
306
293
307
294
void RuntimeScheduler_Modern::runEventLoopTick (
308
295
jsi::Runtime& runtime,
309
- Task& task,
310
- HighResTimeStamp taskStartTime) {
296
+ Task& task) {
311
297
TraceSection s (" RuntimeScheduler::runEventLoopTick" );
312
298
jsinspector_modern::tracing::EventLoopReporter performanceReporter (
313
299
jsinspector_modern::tracing::EventLoopPhase::Task);
@@ -318,6 +304,7 @@ void RuntimeScheduler_Modern::runEventLoopTick(
318
304
currentTask_ = &task;
319
305
currentPriority_ = task.priority ;
320
306
307
+ auto taskStartTime = now_ ();
321
308
lastYieldingOpportunity_ = taskStartTime;
322
309
longestPeriodWithoutYieldingOpportunity_ = HighResDuration::zero ();
323
310
0 commit comments