Files
react-native/packages/react-native/ReactCxxPlatform/react/threading/MessageQueueThreadImpl.cpp
T
Andrew Datsenko 152fa171ee move rncxx threading (#50702)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50702

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D72865847

fbshipit-source-id: 0477670ca1f99089aece9b21feb2482b56f43936
2025-04-14 07:55:19 -07:00

39 lines
947 B
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "MessageQueueThreadImpl.h"
#include <functional>
namespace facebook::react {
void MessageQueueThreadImpl::runOnQueue(std::function<void()>&& runnable) {
if (!taskDispatchThread_.isRunning()) {
return;
}
taskDispatchThread_.runAsync(
[runnable = std::move(runnable)]() noexcept { runnable(); });
}
void MessageQueueThreadImpl::runOnQueueSync(std::function<void()>&& runnable) {
if (!taskDispatchThread_.isRunning()) {
return;
}
if (taskDispatchThread_.isOnThread()) {
runnable();
} else {
taskDispatchThread_.runSync(
[runnable = std::move(runnable)]() noexcept { runnable(); });
}
}
void MessageQueueThreadImpl::quitSynchronous() {
taskDispatchThread_.quit();
}
} // namespace facebook::react