mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d7f5153cd8
Summary: Yesterday we shipped hermesengine.dev as part of the current 0.60 release. This PR brings those changes to master. ## Changelog [General] [Added] - Added support for Hermes Pull Request resolved: https://github.com/facebook/react-native/pull/25613 Test Plan: * CI is green both on GitHub and at FB * Creating a new app from source can use Hermes on Android Reviewed By: cpojer Differential Revision: D16221777 Pulled By: willholen fbshipit-source-id: aa6be10537863039cb666292465ba2e1d44b64ef
58 lines
1.1 KiB
C++
58 lines
1.1 KiB
C++
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
#include "SerialExecutor.h"
|
|
|
|
#include <pthread.h>
|
|
|
|
namespace facebook {
|
|
namespace hermes {
|
|
namespace inspector {
|
|
namespace detail {
|
|
|
|
SerialExecutor::SerialExecutor(const std::string &name)
|
|
: finish_(false), thread_(name, [this]() { runLoop(); }) {}
|
|
|
|
SerialExecutor::~SerialExecutor() {
|
|
{
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
finish_ = true;
|
|
wakeup_.notify_one();
|
|
}
|
|
|
|
thread_.join();
|
|
}
|
|
|
|
void SerialExecutor::add(folly::Func func) {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
funcs_.push(std::move(func));
|
|
wakeup_.notify_one();
|
|
}
|
|
|
|
void SerialExecutor::runLoop() {
|
|
bool shouldExit = false;
|
|
while (!shouldExit) {
|
|
folly::Func func;
|
|
|
|
{
|
|
std::unique_lock<std::mutex> lock(mutex_);
|
|
wakeup_.wait(lock, [this] { return finish_ || !funcs_.empty(); });
|
|
|
|
if (!funcs_.empty()) {
|
|
func = std::move(funcs_.front());
|
|
funcs_.pop();
|
|
}
|
|
|
|
shouldExit = funcs_.empty() && finish_;
|
|
}
|
|
|
|
if (func) {
|
|
func();
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace detail
|
|
} // namespace inspector
|
|
} // namespace hermes
|
|
} // namespace facebook
|