Commit Graph

7 Commits

Author SHA1 Message Date
Samuel Susla dbda1917cc Make RuntimeScheduler module compile in C++ 14
Summary:
changelog: [internal]

Don't use C++ 17 features in RuntimeScheduler module as it needs to be imported into C++14 module.

Also removes redundant dependency.

Reviewed By: ShikaSD

Differential Revision: D30485642

fbshipit-source-id: 0a20f85c596eebe193affc815c8ca851fc72e46d
2021-09-01 11:26:27 -07:00
Samuel Susla 74608417df Before removing a task from queue, make sure it was executed
Summary:
Changelog: [internal]

If task that is being executed schedules a new task with higher priority, the new task will be dropped from the queue. To fix this, we always check if the top of the queue is what was executed and only then remove it.

Example:
Let's say there is task A with priority "normal".

When we execute task A (which is not removed from the queue until later), it adds a task B with "immediate" priority.
So priority queue now has two tasks: [1: B, 2: A]

After task A finishes, inside workLoop, it will pop from top of the priority queue. But task A is no longer top of the priority queue (this is the bug) and it pops B. B is never executed and A is executed twice.

Reviewed By: ShikaSD

Differential Revision: D29841433

fbshipit-source-id: b2f1474fdfc7b3e2d42bae5b7f4ac7e6c3a37b54
2021-07-25 15:39:00 -07:00
Samuel Susla a8d0dd6646 Implement task continuation
Summary:
Changelog: [internal]

Scheduler's callback have option to add more work inside callback. This work stays on top of the priority queue and gives React ability to flush all work synchronously if need.

This diff adds use of `shouldYield_` to the workLoop. For now, it always evaluates to false. In the future when we allow access to the scheduler to native, it will allow yielding.

Relevant code in JavaScript:
https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L190

Reviewed By: mdvacca

Differential Revision: D27823528

fbshipit-source-id: 016101e41eb7c41c2ac5abb55f803814867b8517
2021-04-20 09:22:23 -07:00
Samuel Susla ed76719f24 Pass hardcoded false argument to scheduled callbacks
Summary:
changelog: [internal]

Callback function in React is expecting a boolean parameter indicating whether the callback timed out. React team is removing it, that's why we only pass in hardcoded false.

Reviewed By: mdvacca

Differential Revision: D27794562

fbshipit-source-id: b96a7b31560524b8f38ad3bb0dbdb3b3b32ac97b
2021-04-20 09:22:23 -07:00
Samuel Susla 06753d431a Add expiration date to Task and use it to determine priority
Summary:
Changelog: [internal]

To prevent starvation, this diff implements expiration time as a way to order tasks in priority queue. This stops higher priority tasks from preventing lower priority tasks from running. The same mechanism is implemented in [JavaScript's scheduler](https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js).

Reviewed By: mdvacca

Differential Revision: D27707887

fbshipit-source-id: 3dc734c856a166ef5c17c5045ebd429565ba79f0
2021-04-14 02:53:24 -07:00
Samuel Susla 08ef1df1ba Implement RuntimeScheduler::cancelTask
Summary:
Changelog: [internal]

Implement RuntimeScheduler::cancelTask and expose it through JSI.

JavaScript implementation:
https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L384-L397

Reviewed By: mdvacca

Differential Revision: D27648071

fbshipit-source-id: 91ae92b336017596fb658831824e971c7e047cd2
2021-04-13 01:55:04 -07:00
Samuel Susla 2779129434 Add minimal implementation of RuntimeScheduler::scheduleTask
Summary:
Changelog: [internal]

Add minimal implementation of schedule task. More features and proper scheduling will be added later.

Reviewed By: mdvacca

Differential Revision: D27622138

fbshipit-source-id: b2e4623d38e7217290a6a3c59ccc10a1c13e3a4f
2021-04-13 01:55:04 -07:00