mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Tweak CxxMessageQueue to work with unique_ptr
Differential Revision: D4560164 fbshipit-source-id: 8975157f5a14d5849365a9e35922a02ac6dc185b
This commit is contained in:
committed by
Facebook Github Bot
parent
406a4c04d3
commit
6bce498bbc
@@ -192,6 +192,7 @@ class CxxMessageQueue::QueueRunner {
|
||||
}
|
||||
|
||||
void bindToThisThread() {
|
||||
// TODO: handle nested runloops (either allow them or throw an exception).
|
||||
if (tid_ != std::thread::id{}) {
|
||||
throw std::runtime_error("Message queue already bound to thread.");
|
||||
}
|
||||
@@ -290,9 +291,16 @@ MQRegistry& getMQRegistry() {
|
||||
}
|
||||
}
|
||||
|
||||
std::weak_ptr<CxxMessageQueue> CxxMessageQueue::current() {
|
||||
std::shared_ptr<CxxMessageQueue> CxxMessageQueue::current() {
|
||||
auto tid = std::this_thread::get_id();
|
||||
return getMQRegistry().find(tid);
|
||||
return getMQRegistry().find(tid).lock();
|
||||
}
|
||||
|
||||
std::function<void()> CxxMessageQueue::getUnregisteredRunLoop() {
|
||||
return [capture=qr_] {
|
||||
capture->bindToThisThread();
|
||||
capture->run();
|
||||
};
|
||||
}
|
||||
|
||||
std::function<void()> CxxMessageQueue::getRunLoop(std::shared_ptr<CxxMessageQueue> mq) {
|
||||
@@ -300,7 +308,6 @@ std::function<void()> CxxMessageQueue::getRunLoop(std::shared_ptr<CxxMessageQueu
|
||||
capture->bindToThisThread();
|
||||
auto tid = std::this_thread::get_id();
|
||||
|
||||
// TODO: handle nested runloops (either allow them or throw an exception).
|
||||
getMQRegistry().registerQueue(tid, weakMq);
|
||||
capture->run();
|
||||
getMQRegistry().unregister(tid);
|
||||
|
||||
Reference in New Issue
Block a user