JSExecutor* NativeToJsBridge::getExecutor(const ExecutorToken& executorToken) { std::lock_guard<std::mutex> registrationGuard(m_registrationMutex); auto it = m_executorMap.find(executorToken); if (it == m_executorMap.end()) { return nullptr; } return it->second.executor_.get(); }
MessageQueueThread* Bridge::getMessageQueueThread(const ExecutorToken& executorToken) { std::lock_guard<std::mutex> registrationGuard(m_registrationMutex); auto it = m_executorMap.find(executorToken); if (it == m_executorMap.end()) { return nullptr; } return it->second->messageQueueThread_.get(); }
ExecutorToken NativeToJsBridge::registerExecutor( ExecutorToken token, std::unique_ptr<JSExecutor> executor, std::shared_ptr<MessageQueueThread> messageQueueThread) { std::lock_guard<std::mutex> registrationGuard(m_registrationMutex); CHECK(m_executorTokenMap.find(executor.get()) == m_executorTokenMap.end()) << "Trying to register an already registered executor!"; m_executorTokenMap.emplace(executor.get(), token); m_executorMap.emplace( token, ExecutorRegistration(std::move(executor), messageQueueThread)); return token; }
ExecutorToken Bridge::registerExecutor( std::unique_ptr<JSExecutor> executor, std::shared_ptr<MessageQueueThread> messageQueueThread) { auto token = m_executorTokenFactory->createExecutorToken(); std::lock_guard<std::mutex> registrationGuard(m_registrationMutex); CHECK(m_executorTokenMap.find(executor.get()) == m_executorTokenMap.end()) << "Trying to register an already registered executor!"; m_executorTokenMap.emplace(executor.get(), token); m_executorMap.emplace( token, folly::make_unique<ExecutorRegistration>(std::move(executor), std::move(messageQueueThread))); return token; }
std::unique_ptr<JSExecutor> NativeToJsBridge::unregisterExecutor(JSExecutor& executor) { std::unique_ptr<JSExecutor> ret; { std::lock_guard<std::mutex> registrationGuard(m_registrationMutex); auto it = m_executorTokenMap.find(&executor); CHECK(it != m_executorTokenMap.end()) << "Trying to unregister an executor that was never registered!"; auto it2 = m_executorMap.find(it->second); ret = std::move(it2->second.executor_); m_executorTokenMap.erase(it); m_executorMap.erase(it2); } return ret; }
std::unique_ptr<JSExecutor> Bridge::unregisterExecutor(ExecutorToken executorToken) { std::unique_ptr<JSExecutor> executor; { std::lock_guard<std::mutex> registrationGuard(m_registrationMutex); auto it = m_executorMap.find(executorToken); CHECK(it != m_executorMap.end()) << "Trying to unregister an executor that was never registered!"; executor = std::move(it->second->executor_); m_executorMap.erase(it); m_executorTokenMap.erase(executor.get()); } m_callback->onExecutorUnregistered(executorToken); return executor; }
ExecutorToken NativeToJsBridge::getTokenForExecutor(JSExecutor& executor) { std::lock_guard<std::mutex> registrationGuard(m_registrationMutex); return m_executorTokenMap.at(&executor); }