Skip to content

Commit 98685e8

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: Using RuntimeExecutor in concrete EventBeats
Summary: Now we use RuntimeExecutor instead of MessageQueue; that's more clear and remove a dependency from Bridge. Reviewed By: sahrens Differential Revision: D12837226 fbshipit-source-id: 0ea3782ce2f49c7f3a91425880863e3b3ea37712
1 parent 0a39cda commit 98685e8

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

React/Fabric/RCTSurfacePresenter.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#import <fabric/uimanager/ContextContainer.h>
3131

3232
#import "MainRunLoopEventBeat.h"
33-
#import "MessageQueueEventBeat.h"
33+
#import "RuntimeEventBeat.h"
3434
#import "RCTConversions.h"
3535

3636
using namespace facebook::react;
@@ -165,12 +165,12 @@ - (RCTScheduler *)_scheduler
165165
});
166166
};
167167

168-
EventBeatFactory synchronousBeatFactory = [messageQueueThread]() {
169-
return std::make_unique<MainRunLoopEventBeat>(messageQueueThread);
168+
EventBeatFactory synchronousBeatFactory = [runtimeExecutor]() {
169+
return std::make_unique<MainRunLoopEventBeat>(runtimeExecutor);
170170
};
171171

172-
EventBeatFactory asynchronousBeatFactory = [messageQueueThread]() {
173-
return std::make_unique<MessageQueueEventBeat>(messageQueueThread);
172+
EventBeatFactory asynchronousBeatFactory = [runtimeExecutor]() {
173+
return std::make_unique<RuntimeEventBeat>(runtimeExecutor);
174174
};
175175

176176
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");

React/Fabric/Utils/MainRunLoopEventBeat.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <CoreFoundation/CoreFoundation.h>
99
#include <CoreFoundation/CFRunLoop.h>
10-
#include <cxxreact/MessageQueueThread.h>
10+
#include <fabric/uimanager/FabricUIManager.h>
1111
#include <fabric/events/EventBeat.h>
1212

1313
namespace facebook {
@@ -21,15 +21,15 @@ class MainRunLoopEventBeat final:
2121
public EventBeat {
2222

2323
public:
24-
MainRunLoopEventBeat(std::shared_ptr<MessageQueueThread> messageQueueThread);
24+
MainRunLoopEventBeat(RuntimeExecutor runtimeExecutor);
2525
~MainRunLoopEventBeat();
2626

2727
void induce() const override;
2828

2929
private:
30-
void blockMessageQueueAndThenBeat() const;
30+
void lockExecutorAndBeat() const;
3131

32-
std::shared_ptr<MessageQueueThread> messageQueueThread_;
32+
const RuntimeExecutor runtimeExecutor_;
3333
CFRunLoopObserverRef mainRunLoopObserver_;
3434
};
3535

React/Fabric/Utils/MainRunLoopEventBeat.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
namespace facebook {
1212
namespace react {
1313

14-
MainRunLoopEventBeat::MainRunLoopEventBeat(std::shared_ptr<MessageQueueThread> messageQueueThread):
15-
messageQueueThread_(std::move(messageQueueThread)) {
14+
MainRunLoopEventBeat::MainRunLoopEventBeat(RuntimeExecutor runtimeExecutor):
15+
runtimeExecutor_(std::move(runtimeExecutor)) {
1616

1717
mainRunLoopObserver_ =
1818
CFRunLoopObserverCreateWithHandler(
@@ -25,7 +25,7 @@
2525
return;
2626
}
2727

28-
this->blockMessageQueueAndThenBeat();
28+
this->lockExecutorAndBeat();
2929
}
3030
);
3131

@@ -45,11 +45,11 @@
4545
}
4646

4747
RCTExecuteOnMainQueue(^{
48-
this->blockMessageQueueAndThenBeat();
48+
this->lockExecutorAndBeat();
4949
});
5050
}
5151

52-
void MainRunLoopEventBeat::blockMessageQueueAndThenBeat() const {
52+
void MainRunLoopEventBeat::lockExecutorAndBeat() const {
5353
// Note: We need the third mutex to get back to the main thread before
5454
// the lambda is finished (because all mutexes are allocated on the stack).
5555

@@ -61,7 +61,7 @@
6161
mutex2.lock();
6262
mutex3.lock();
6363

64-
messageQueueThread_->runOnQueue([&]() {
64+
runtimeExecutor_([&](jsi::Runtime &runtime) {
6565
mutex1.unlock();
6666
mutex2.lock();
6767
mutex3.unlock();

React/Fabric/Utils/MessageQueueEventBeat.h renamed to React/Fabric/Utils/RuntimeEventBeat.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,28 @@
77

88
#include <CoreFoundation/CoreFoundation.h>
99
#include <CoreFoundation/CFRunLoop.h>
10-
#include <cxxreact/MessageQueueThread.h>
10+
#include <fabric/uimanager/FabricUIManager.h>
1111
#include <fabric/events/EventBeat.h>
1212

1313
namespace facebook {
1414
namespace react {
1515

1616
/*
17-
* Event beat that associated with MessageQueueThread.
17+
* Event beat associated with JavaScript runtime.
18+
* The beat is called on `RuntimeExecutor`'s thread induced by the main thread
19+
* event loop.
1820
*/
19-
class MessageQueueEventBeat:
21+
class RuntimeEventBeat:
2022
public EventBeat {
2123

2224
public:
23-
MessageQueueEventBeat(const std::shared_ptr<MessageQueueThread> &messageQueueThread);
24-
~MessageQueueEventBeat();
25+
RuntimeEventBeat(RuntimeExecutor runtimeExecutor);
26+
~RuntimeEventBeat();
2527

2628
void induce() const override;
2729

2830
private:
29-
const std::shared_ptr<MessageQueueThread> messageQueueThread_;
31+
const RuntimeExecutor runtimeExecutor_;
3032
CFRunLoopObserverRef mainRunLoopObserver_;
3133
mutable std::atomic<bool> isBusy_ {false};
3234
};

React/Fabric/Utils/MessageQueueEventBeat.mm renamed to React/Fabric/Utils/RuntimeEventBeat.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include "MessageQueueEventBeat.h"
8+
#include "RuntimeEventBeat.h"
99

1010
namespace facebook {
1111
namespace react {
1212

13-
MessageQueueEventBeat::MessageQueueEventBeat(const std::shared_ptr<MessageQueueThread> &messageQueueThread):
14-
messageQueueThread_(messageQueueThread) {
13+
RuntimeEventBeat::RuntimeEventBeat(RuntimeExecutor runtimeExecutor):
14+
runtimeExecutor_(std::move(runtimeExecutor)) {
1515

1616
mainRunLoopObserver_ =
1717
CFRunLoopObserverCreateWithHandler(
@@ -31,12 +31,12 @@
3131
CFRunLoopAddObserver(CFRunLoopGetMain(), mainRunLoopObserver_, kCFRunLoopCommonModes);
3232
}
3333

34-
MessageQueueEventBeat::~MessageQueueEventBeat() {
34+
RuntimeEventBeat::~RuntimeEventBeat() {
3535
CFRunLoopRemoveObserver(CFRunLoopGetMain(), mainRunLoopObserver_, kCFRunLoopCommonModes);
3636
CFRelease(mainRunLoopObserver_);
3737
}
3838

39-
void MessageQueueEventBeat::induce() const {
39+
void RuntimeEventBeat::induce() const {
4040
if (!isRequested_ || isBusy_) {
4141
return;
4242
}
@@ -58,7 +58,7 @@
5858
#endif
5959

6060
isBusy_ = true;
61-
messageQueueThread_->runOnQueue([=]() mutable {
61+
runtimeExecutor_([=](jsi::Runtime &runtime) mutable {
6262
this->beat();
6363
isBusy_ = false;
6464
#ifndef NDEBUG

0 commit comments

Comments
 (0)