Skip to content

Commit

Permalink
Move SerialExecutor to Support
Browse files Browse the repository at this point in the history
Summary:
Move SerialExecutor, and convert `throw`s to
`assert`s so it can be built without exceptions.

Differential Revision: D57689126
  • Loading branch information
Matt Blagden authored and facebook-github-bot committed May 23, 2024
1 parent 27f04f8 commit 35e715b
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion API/hermes/inspector/chrome/tests/AsyncHermesRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <memory>
#include <mutex>

#include <hermes/SerialExecutor/SerialExecutor.h>
#include <hermes/Support/SerialExecutor.h>

#include <hermes/hermes.h>
#include <jsi/jsi.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <functional>
#include <memory>
#include <mutex>
#if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__)
#if LLVM_ADDRESS_SANITIZER_BUILD
#include <pthread.h>
#else
#include <thread>
Expand All @@ -29,7 +29,7 @@ namespace hermes {
class SerialExecutor {
private:
// The thread on which all work is done.
#if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__)
#ifdef LLVM_ADDRESS_SANITIZER_BUILD
pthread_t tid_;
#else
std::thread workerThread_;
Expand All @@ -52,7 +52,7 @@ class SerialExecutor {
/// they are posted. This stops running when shouldStop_ is set to true.
void run();

#if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__)
#if LLVM_ADDRESS_SANITIZER_BUILD
/// Main function of the new thread.
static void *threadMain(void *p);
#endif
Expand Down
1 change: 0 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@ add_subdirectory(ConsoleHost)
add_subdirectory(Regex)
add_subdirectory(Platform)
add_subdirectory(InternalBytecode)
add_subdirectory(SerialExecutor)
7 changes: 0 additions & 7 deletions lib/SerialExecutor/CMakeLists.txt

This file was deleted.

1 change: 1 addition & 0 deletions lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_hermes_library(hermesSupport
PageAccessTrackerPosix.cpp
PerfSection.cpp
SemaphorePosix.cpp
SerialExecutor.cpp
SHA1.cpp
SNPrintfBuf.cpp
SourceErrorManager.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@
* LICENSE file in the root directory of this source tree.
*/

#include "hermes/SerialExecutor/SerialExecutor.h"
#include <cassert>

#include "hermes/Support/SerialExecutor.h"

namespace hermes {

SerialExecutor::SerialExecutor(size_t stackSize) {
#if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__)
#ifdef LLVM_ADDRESS_SANITIZER_BUILD
pthread_attr_t attr;

int ret;
(void)ret;
ret = pthread_attr_init(&attr);
if (ret != 0) {
throw std::runtime_error("Failed pthread_attr_init");
}
assert(ret != 0 && "Failed pthread_attr_init");

if (stackSize != 0) {
ret = pthread_attr_setstacksize(&attr, stackSize);
if (ret != 0) {
throw std::runtime_error("Failed pthread_attr_setstacksize");
}
assert(ret != 0 && "Failed pthread_attr_setstacksize");
}

ret = pthread_create(&tid_, &attr, SerialExecutor::threadMain, this);
if (ret != 0) {
throw std::runtime_error("Failed pthread_create");
}
assert(ret != 0 && "Failed pthread_create");

#else
workerThread_ = std::thread([this]() { this->run(); });
#endif
Expand All @@ -42,7 +40,7 @@ SerialExecutor::~SerialExecutor() {
shouldStop_ = true;
wakeUpSig_.notify_one();
}
#if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__)
#ifdef LLVM_ADDRESS_SANITIZER_BUILD
pthread_join(tid_, nullptr);
#else
workerThread_.join();
Expand Down Expand Up @@ -82,7 +80,7 @@ void SerialExecutor::run() {
}
}

#if !defined(_WINDOWS) && !defined(__EMSCRIPTEN__)
#ifdef LLVM_ADDRESS_SANITIZER_BUILD
void *SerialExecutor::threadMain(void *p) {
static_cast<SerialExecutor *>(p)->run();
pthread_exit(nullptr);
Expand Down
2 changes: 1 addition & 1 deletion tools/hcdp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_hermes_tool(hcdp
${ALL_HEADER_FILES}
)

target_link_libraries(hcdp hermesSerialExecutor libhermes hermesParser)
target_link_libraries(hcdp hermesSupport libhermes hermesParser)

install(TARGETS hcdp
RUNTIME DESTINATION bin
Expand Down
2 changes: 1 addition & 1 deletion tools/hcdp/hcdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ int main(void) {
#include <sstream>

#include <hermes/Parser/JSONParser.h>
#include <hermes/SerialExecutor/SerialExecutor.h>
#include <hermes/Support/JSONEmitter.h>
#include <hermes/Support/SerialExecutor.h>
#include <hermes/cdp/CDPAgent.h>
#include <hermes/cdp/CDPDebugAPI.h>
#include <hermes/cdp/MessageTypes.h>
Expand Down
2 changes: 1 addition & 1 deletion unittests/API/AsyncDebuggerAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <gtest/gtest.h>

#include <hermes/AsyncDebuggerAPI.h>
#include <hermes/SerialExecutor/SerialExecutor.h>
#include <hermes/Support/SerialExecutor.h>
#include <hermes/hermes.h>
#include <jsi/jsi.h>

Expand Down
2 changes: 1 addition & 1 deletion unittests/API/CDPAgentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include <hermes/AsyncDebuggerAPI.h>
#include <hermes/CompileJS.h>
#include <hermes/SerialExecutor/SerialExecutor.h>
#include <hermes/Support/JSONEmitter.h>
#include <hermes/Support/SerialExecutor.h>
#include <hermes/cdp/CDPAgent.h>
#include <hermes/cdp/CDPDebugAPI.h>
#include <hermes/cdp/JSONValueInterfaces.h>
Expand Down
2 changes: 1 addition & 1 deletion unittests/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ add_hermes_unittest(APITests ${APITestsSources})

target_link_libraries(APITests libhermes compileJS SegmentTestCompile traceInterpreter
timerStats hermesABIRuntimeWrapper hermesabi
hermesSandboxRuntime hermesSerialExecutor cdpInternal)
hermesSandboxRuntime hermesSupport cdpInternal)

add_hermes_unittest(APILeanTests APILeanTest.cpp)
target_link_libraries(APILeanTests libhermes_lean jsi)

0 comments on commit 35e715b

Please sign in to comment.