From d13396127cb8644871b2bc52dda62e6871c33f36 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 1 Dec 2024 10:28:50 +0900 Subject: [PATCH] Delete Semaphore copy and move methods (#2613) This matches the macOS implementation. --- src/psemaphore.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/psemaphore.h b/src/psemaphore.h index 5143239..51008f9 100644 --- a/src/psemaphore.h +++ b/src/psemaphore.h @@ -79,6 +79,11 @@ class Semaphore public: explicit Semaphore(int value) { sem_init(&mutex, 0, value); } ~Semaphore() { sem_destroy(&mutex); } + Semaphore(const Semaphore&) = delete; + Semaphore(Semaphore&&) = delete; + Semaphore& operator=(const Semaphore&) = delete; + Semaphore& operator=(Semaphore&&) = delete; + void acquire() { int r; @@ -86,6 +91,7 @@ class Semaphore r = sem_wait(&mutex); } while (r == -1 && errno == EINTR); } + bool try_acquire() { int result; @@ -95,6 +101,7 @@ class Semaphore return (0 == result); } + void release() { sem_post(&mutex); } private: