From 347daceced3a516fec8080e0fe640f68c137db76 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 5 Dec 2019 16:15:30 -0500 Subject: use pipe to emulate eventfd on mac; add install script --- .gitignore | 1 + CMakeLists.txt | 4 ++++ include/salticidae/event.h | 37 ++++++++----------------------------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index eff5651..35ec756 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ include/salticidae/config.h *.gch /Makefile core +install_manifest.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 29a99ff..c0769dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,10 +48,12 @@ if(BUILD_SHARED) add_library(salticidae_shared SHARED $) set_target_properties(salticidae_shared PROPERTIES OUTPUT_NAME "salticidae") target_link_libraries(salticidae_shared uv crypto ssl pthread) + install(TARGETS salticidae_shared DESTINATION lib) endif() add_library(salticidae_static STATIC $) set_target_properties(salticidae_static PROPERTIES OUTPUT_NAME "salticidae") target_link_libraries(salticidae_static uv crypto ssl pthread) +install(TARGETS salticidae_static DESTINATION lib) option(BUILD_TEST "build test binaries." OFF) if(BUILD_TEST) @@ -73,3 +75,5 @@ configure_file(src/config.h.in include/salticidae/config.h @ONLY) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -W -Wall -Wextra -pedantic -Wsuggest-override") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -W -Wall -Wextra -pedantic -Wsuggest-override") + +install(DIRECTORY include/ DESTINATION include) diff --git a/include/salticidae/event.h b/include/salticidae/event.h index fe94c0a..52cb058 100644 --- a/include/salticidae/event.h +++ b/include/salticidae/event.h @@ -577,7 +577,10 @@ class NotifyFd { throw SalticidaeError(SALTI_ERROR_FD); } bool reset() { - return read(fds[0], dummy, 8) == 8; + // clear the pipe buffer (not atomically) + while (read(fds[0], dummy, 8) > 0); + // may not work for MPMC, but salticidae currently doesn't use that + return true; } void notify() { write(fds[1], dummy, 8); @@ -597,28 +600,18 @@ template class MPSCQueueEventDriven: public MPSCQueue { private: std::atomic wait_sig; - //int fd; NotifyFd nfd; FdEvent ev; public: MPSCQueueEventDriven(): - wait_sig(true) { - //fd(eventfd(0, EFD_NONBLOCK)) { - //if (fd == -1) throw SalticidaeError(SALTI_ERROR_FD); - } - ~MPSCQueueEventDriven() { - //close(fd); - unreg_handler(); - } + wait_sig(true) {} + ~MPSCQueueEventDriven() { unreg_handler(); } template void reg_handler(const EventContext &ec, Func &&func) { ev = FdEvent(ec, nfd.read_fd(), [this, func=std::forward(func)](int, int) { - //fprintf(stderr, "%x\n", std::this_thread::get_id()); - //uint64_t t; - //read(fd, &t, 8); nfd.reset(); // the only undesirable case is there are some new items // enqueued before recovering wait_sig to true, so the consumer @@ -629,7 +622,6 @@ class MPSCQueueEventDriven: public MPSCQueue { wait_sig.exchange(true, std::memory_order_acq_rel); if (func(*this)) nfd.notify(); - //write(fd, &dummy, 8); }); ev.add(FdEvent::READ); } @@ -644,7 +636,6 @@ class MPSCQueueEventDriven: public MPSCQueue { if (wait_sig.exchange(false, std::memory_order_acq_rel)) { //SALTICIDAE_LOG_DEBUG("mpsc notify"); - //write(fd, &dummy, 8); nfd.notify(); } return true; @@ -658,33 +649,22 @@ template class MPMCQueueEventDriven: public MPMCQueue { private: std::atomic wait_sig; - //int fd; NotifyFd nfd; std::vector evs; public: MPMCQueueEventDriven(): - wait_sig(true) { - //fd(eventfd(0, EFD_NONBLOCK)) { - //if (fd == -1) throw SalticidaeError(SALTI_ERROR_FD); - } - ~MPMCQueueEventDriven() { - //close(fd); - unreg_handlers(); - } + wait_sig(true) {} + ~MPMCQueueEventDriven() { unreg_handlers(); } // this function is *NOT* thread-safe template void reg_handler(const EventContext &ec, Func &&func) { FdEvent ev(ec, nfd.read_fd(), [this, func=std::forward(func)](int, int) { - //fprintf(stderr, "%x\n", std::this_thread::get_id()); - uint64_t t; - //if (read(fd, &t, 8) != 8) return; if (!nfd.reset()) return; // only one consumer should be here a a time wait_sig.exchange(true, std::memory_order_acq_rel); if (func(*this)) - //write(fd, &dummy, 8); nfd.notify(); }); ev.add(FdEvent::READ); @@ -701,7 +681,6 @@ class MPMCQueueEventDriven: public MPMCQueue { if (wait_sig.exchange(false, std::memory_order_acq_rel)) { //SALTICIDAE_LOG_DEBUG("mpmc notify"); - //write(fd, &dummy, 8); nfd.notify(); } return true; -- cgit v1.2.3