From 0aacee389fdb553ef9925d0135eefcb501a67726 Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Mon, 31 Aug 2009 11:31:32 +0200 Subject: [PATCH] POSIX threads don't use errno to report errors Fix simple_semaphore to follow POSIX threads convention for reporting errors. --- src/err.hpp | 9 +++++---- src/simple_semaphore.hpp | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/err.hpp b/src/err.hpp index 3854d8a0..c1b2916b 100644 --- a/src/err.hpp +++ b/src/err.hpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -81,10 +82,10 @@ namespace zmq }} while (false) // Provides convenient way to check for POSIX errors. -#define posix_assert(x) do {\ -fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\ -abort ();\ -} while (false) +#define posix_assert(x) do { if ((x)) {\ + fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\ + abort ();\ +}} while (false) // Provides convenient way to check for errors from getaddrinfo. #define gai_assert(x) do { if (x) {\ diff --git a/src/simple_semaphore.hpp b/src/simple_semaphore.hpp index b48a7f51..209ccb4a 100644 --- a/src/simple_semaphore.hpp +++ b/src/simple_semaphore.hpp @@ -53,32 +53,32 @@ namespace zmq inline simple_semaphore_t () { int rc = pthread_mutex_init (&mutex, NULL); - errno_assert (rc == 0); + posix_assert (rc); rc = pthread_mutex_lock (&mutex); - errno_assert (rc == 0); + posix_assert (rc); } // Destroy the semaphore. inline ~simple_semaphore_t () { int rc = pthread_mutex_unlock (&mutex); - errno_assert (rc == 0); + posix_assert (rc); rc = pthread_mutex_destroy (&mutex); - errno_assert (rc == 0); + posix_assert (rc); } // Wait for the semaphore. inline void wait () { int rc = pthread_mutex_lock (&mutex); - errno_assert (rc == 0); + posix_assert (rc); } // Post the semaphore. inline void post () { int rc = pthread_mutex_unlock (&mutex); - errno_assert (rc == 0); + posix_assert (rc); } private: