diff --git a/atomicops.h b/atomicops.h index b103bc6..f55cbdc 100644 --- a/atomicops.h +++ b/atomicops.h @@ -363,6 +363,8 @@ extern "C" { #include #elif defined(__unix__) #include +#elif defined(__HAIKU__) +#include #elif defined(FREERTOS) #include #include @@ -581,6 +583,64 @@ namespace moodycamel } } }; +#elif defined(__HAIKU__) + //--------------------------------------------------------- + // Semaphore (Haiku) + //--------------------------------------------------------- + class Semaphore + { + private: + sem_id m_sema; + + Semaphore(const Semaphore& other); + Semaphore& operator=(const Semaphore& other); + + public: + AE_NO_TSAN Semaphore(int initialCount = 0) : m_sema() + { + assert(initialCount >= 0); + m_sema = create_sem(initialCount, ""); + assert(m_sema >= B_OK); + } + + AE_NO_TSAN ~Semaphore() + { + delete_sem(m_sema); + } + + bool wait() AE_NO_TSAN + { + // accquire the semaphore + status_t rc; + rc = acquire_sem(m_sema); + return rc == B_NO_ERROR; + } + + bool try_wait() AE_NO_TSAN + { + // accquire the semaphore + status_t rc; + rc = acquire_sem_etc(m_sema, 1, B_RELATIVE_TIMEOUT, 0); + return rc == B_NO_ERROR; + } + + bool timed_wait(std::uint64_t usecs) AE_NO_TSAN + { + status_t rc; + rc = acquire_sem_etc(m_sema, 1, B_RELATIVE_TIMEOUT, (bigtime_t) usecs); + return rc == B_NO_ERROR; + } + + void signal() AE_NO_TSAN + { + release_sem(m_sema); + } + + void signal(int count) AE_NO_TSAN + { + release_sem_etc(m_sema, count, 0); + } + }; #elif defined(FREERTOS) //--------------------------------------------------------- // Semaphore (FreeRTOS) diff --git a/tests/stabtest/makefile b/tests/stabtest/makefile index 13795ab..ee1f778 100644 --- a/tests/stabtest/makefile +++ b/tests/stabtest/makefile @@ -1,24 +1,28 @@ ifeq ($(OS),Windows_NT) EXT=.exe PLATFORM_OPTS=-static - PLATFORM_LD_OPTS=-Wl,--no-as-needed + PLATFORM_LD_OPTS=-pthread -Wl,--no-as-needed else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) EXT= PLATFORM_OPTS= - PLATFORM_LD_OPTS= + PLATFORM_LD_OPTS=-pthread + else ifeq ($(UNAME_S),Haiku) + EXT= + PLATFORM_OPTS= + PLATFORM_LD_OPTS=-Wl,--no-as-needed else EXT= PLATFORM_OPTS= - PLATFORM_LD_OPTS=-lrt -Wl,--no-as-needed + PLATFORM_LD_OPTS=-pthread -lrt -Wl,--no-as-needed endif endif default: stabtest$(EXT) stabtest$(EXT): stabtest.cpp ../../readerwriterqueue.h ../../atomicops.h ../common/simplethread.h ../common/simplethread.cpp makefile - g++ $(PLATFORM_OPTS) -std=c++11 -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 stabtest.cpp ../common/simplethread.cpp -o stabtest$(EXT) -pthread $(PLATFORM_LD_OPTS) + g++ $(PLATFORM_OPTS) -std=c++11 -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 stabtest.cpp ../common/simplethread.cpp -o stabtest$(EXT) $(PLATFORM_LD_OPTS) run: stabtest$(EXT) ./stabtest$(EXT) diff --git a/tests/unittests/makefile b/tests/unittests/makefile index f681418..45779cd 100644 --- a/tests/unittests/makefile +++ b/tests/unittests/makefile @@ -3,17 +3,21 @@ ifeq ($(OS),Windows_NT) EXT=.exe PLATFORM_OPTS=-static - PLATFORM_LD_OPTS=-Wl,--no-as-needed + PLATFORM_LD_OPTS=-pthread -Wl,--no-as-needed else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) EXT= PLATFORM_OPTS= - PLATFORM_LD_OPTS= + PLATFORM_LD_OPTS=-pthread + else ifeq ($(UNAME_S),Haiku) + EXT= + PLATFORM_OPTS= + PLATFORM_LD_OPTS=-Wl,--no-as-needed else EXT= PLATFORM_OPTS= - PLATFORM_LD_OPTS=-lrt -Wl,--no-as-needed + PLATFORM_LD_OPTS=-pthread -lrt -Wl,--no-as-needed endif endif @@ -21,7 +25,7 @@ endif default: unittests$(EXT) unittests$(EXT): unittests.cpp ../../readerwriterqueue.h ../../readerwritercircularbuffer.h ../../atomicops.h ../common/simplethread.h ../common/simplethread.cpp minitest.h makefile - g++ $(PLATFORM_OPTS) -std=c++11 -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g unittests.cpp ../common/simplethread.cpp -o unittests$(EXT) -pthread $(PLATFORM_LD_OPTS) + g++ $(PLATFORM_OPTS) -std=c++11 -Wsign-conversion -Wpedantic -Wall -DNDEBUG -O3 -g unittests.cpp ../common/simplethread.cpp -o unittests$(EXT) $(PLATFORM_LD_OPTS) run: unittests$(EXT) ./unittests$(EXT)