mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert D64287526: batch sync events based on event beats
Differential Revision: D64287526 Original commit changeset: a5dc3b643ef1 Original Phabricator Diff: D64287526 fbshipit-source-id: 9c967bd2573dc69bfbde69a7a79046e9d58fcb21
This commit is contained in:
committed by
Facebook GitHub Bot
parent
538bff710f
commit
020e1b6e86
@@ -21,11 +21,6 @@ void EventBeat::request() const {
|
||||
isRequested_ = true;
|
||||
}
|
||||
|
||||
void EventBeat::requestSynchronous() const {
|
||||
isSynchronousRequested_ = true;
|
||||
request();
|
||||
}
|
||||
|
||||
void EventBeat::setBeatCallback(BeatCallback beatCallback) {
|
||||
beatCallback_ = std::move(beatCallback);
|
||||
}
|
||||
@@ -38,7 +33,7 @@ void EventBeat::induce() const {
|
||||
isRequested_ = false;
|
||||
isBeatCallbackScheduled_ = true;
|
||||
|
||||
auto beat = std::function<void(jsi::Runtime&)>(
|
||||
runtimeScheduler_.scheduleWork(
|
||||
[this, ownerBox = ownerBox_](jsi::Runtime& runtime) {
|
||||
auto owner = ownerBox->owner.lock();
|
||||
if (!owner) {
|
||||
@@ -50,13 +45,6 @@ void EventBeat::induce() const {
|
||||
beatCallback_(runtime);
|
||||
}
|
||||
});
|
||||
|
||||
if (isSynchronousRequested_) {
|
||||
isSynchronousRequested_ = false;
|
||||
runtimeScheduler_.executeNowOnTheSameThread(std::move(beat));
|
||||
} else {
|
||||
runtimeScheduler_.scheduleWork(std::move(beat));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -74,12 +74,6 @@ class EventBeat {
|
||||
*/
|
||||
virtual void request() const;
|
||||
|
||||
/*
|
||||
* Communicates to the Beat that a consumer is waiting synchronously for the
|
||||
* coming beat.
|
||||
*/
|
||||
virtual void requestSynchronous() const;
|
||||
|
||||
/*
|
||||
* The callback is must be called on the proper thread.
|
||||
*/
|
||||
@@ -99,7 +93,6 @@ class EventBeat {
|
||||
private:
|
||||
RuntimeScheduler& runtimeScheduler_;
|
||||
mutable std::atomic<bool> isBeatCallbackScheduled_{false};
|
||||
mutable std::atomic<bool> isSynchronousRequested_{false};
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -18,9 +18,11 @@ namespace facebook::react {
|
||||
EventDispatcher::EventDispatcher(
|
||||
const EventQueueProcessor& eventProcessor,
|
||||
std::unique_ptr<EventBeat> eventBeat,
|
||||
RuntimeScheduler& runtimeScheduler,
|
||||
StatePipe statePipe,
|
||||
std::weak_ptr<EventLogger> eventLogger)
|
||||
: eventQueue_(EventQueue(eventProcessor, std::move(eventBeat))),
|
||||
: eventQueue_(
|
||||
EventQueue(eventProcessor, std::move(eventBeat), runtimeScheduler)),
|
||||
statePipe_(std::move(statePipe)),
|
||||
eventLogger_(std::move(eventLogger)) {}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class EventDispatcher {
|
||||
EventDispatcher(
|
||||
const EventQueueProcessor& eventProcessor,
|
||||
std::unique_ptr<EventBeat> eventBeat,
|
||||
RuntimeScheduler& runtimeScheduler,
|
||||
StatePipe statePipe,
|
||||
std::weak_ptr<EventLogger> eventLogger);
|
||||
|
||||
|
||||
@@ -15,9 +15,11 @@ namespace facebook::react {
|
||||
|
||||
EventQueue::EventQueue(
|
||||
EventQueueProcessor eventProcessor,
|
||||
std::unique_ptr<EventBeat> eventBeat)
|
||||
std::unique_ptr<EventBeat> eventBeat,
|
||||
RuntimeScheduler& runtimeScheduler)
|
||||
: eventProcessor_(std::move(eventProcessor)),
|
||||
eventBeat_(std::move(eventBeat)) {
|
||||
eventBeat_(std::move(eventBeat)),
|
||||
runtimeScheduler_(&runtimeScheduler) {
|
||||
eventBeat_->setBeatCallback(
|
||||
[this](jsi::Runtime& runtime) { onBeat(runtime); });
|
||||
}
|
||||
@@ -77,14 +79,26 @@ void EventQueue::enqueueStateUpdate(StateUpdate&& stateUpdate) const {
|
||||
}
|
||||
|
||||
void EventQueue::onEnqueue() const {
|
||||
if (synchronousAccessRequested_) {
|
||||
// Sync flush has been scheduled, no need to request access to the runtime.
|
||||
return;
|
||||
}
|
||||
eventBeat_->request();
|
||||
}
|
||||
|
||||
void EventQueue::experimental_flushSync() const {
|
||||
eventBeat_->requestSynchronous();
|
||||
synchronousAccessRequested_ = true;
|
||||
runtimeScheduler_->executeNowOnTheSameThread([this](jsi::Runtime& runtime) {
|
||||
synchronousAccessRequested_ = false;
|
||||
onBeat(runtime);
|
||||
});
|
||||
}
|
||||
|
||||
void EventQueue::onBeat(jsi::Runtime& runtime) const {
|
||||
if (synchronousAccessRequested_) {
|
||||
// Sync flush has been scheduled, let's yield to it.
|
||||
return;
|
||||
}
|
||||
flushStateUpdates();
|
||||
flushEvents(runtime);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ class EventQueue {
|
||||
public:
|
||||
EventQueue(
|
||||
EventQueueProcessor eventProcessor,
|
||||
std::unique_ptr<EventBeat> eventBeat);
|
||||
std::unique_ptr<EventBeat> eventBeat,
|
||||
RuntimeScheduler& runtimeScheduler);
|
||||
|
||||
/*
|
||||
* Enqueues and (probably later) dispatch a given event.
|
||||
@@ -74,6 +75,10 @@ class EventQueue {
|
||||
mutable std::vector<RawEvent> eventQueue_;
|
||||
mutable std::vector<StateUpdate> stateUpdateQueue_;
|
||||
mutable std::mutex queueMutex_;
|
||||
|
||||
// TODO: T183075253
|
||||
RuntimeScheduler* runtimeScheduler_;
|
||||
mutable std::atomic_bool synchronousAccessRequested_{false};
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -101,6 +101,7 @@ Scheduler::Scheduler(
|
||||
EventQueueProcessor(
|
||||
eventPipe, eventPipeConclusion, statePipe, eventPerformanceLogger_),
|
||||
std::move(eventBeat),
|
||||
*runtimeScheduler,
|
||||
statePipe,
|
||||
eventPerformanceLogger_);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user