Files
react-native/ReactCommon/hermes/inspector/detail/SerialExecutor.h
T
Andres Suarez aee88b6843 Tidy up license headers [3/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952693

fbshipit-source-id: 8fcb8e58a2e04e7a3169f4d525bffc00835768e6
2019-10-16 10:06:34 -07:00

58 lines
1.5 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.
*/
#pragma once
#include <condition_variable>
#include <mutex>
#include <queue>
#include <string>
#include <hermes/inspector/detail/Thread.h>
#include <folly/Executor.h>
namespace facebook {
namespace hermes {
namespace inspector {
namespace detail {
/// SerialExecutor is a simple implementation of folly::Executor that processes
/// work items serially on a worker thread. It exists for two reasons:
///
/// 1. Currently Hermes builds for the host as well as in fbandroid and
/// fbobjc, so we need an implementation of a serial executor that doesn't
/// use the SerialAsyncExecutorFactory from fbandroid or fbobjc.
/// 2. None of folly's Executor factories are included in the stripped-down
/// version of folly in xplat.
///
/// TODO: create a factory that uses SerialAsyncExecutorFactory if we're
/// building for fbandroid or fbobjc, and otherwise creates an instance of this
/// class.
class SerialExecutor : public folly::Executor {
public:
SerialExecutor(const std::string &name);
~SerialExecutor();
void add(folly::Func) override;
private:
void runLoop();
std::mutex mutex_;
std::queue<folly::Func> funcs_;
std::condition_variable wakeup_;
bool finish_;
Thread thread_;
};
} // namespace detail
} // namespace inspector
} // namespace hermes
} // namespace facebook