Files
react-native/ReactCommon/hermes/inspector/detail/SerialExecutor.cpp
T
Oleg Bogdanov 79c69bea02 hermes | inspector | Don't include posix headers on non-posix systems
Summary:
Changelog: [Internal]

Hermes inspector includes pthreads, arpa and sys headers on all OSes that would break vanilla Windows builds. This diff adds a check for posix-compliance before inclusion

(Note: this ignores all push blocking failures!)

Reviewed By: dulinriley

Differential Revision: D20564449

fbshipit-source-id: 8e264bc3104065dc4315bb291e8560609fe65184
2020-03-24 18:53:43 -07:00

61 lines
1.2 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "SerialExecutor.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