mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-19 18:03:50 +00:00
POSIX threads don't use errno to report errors
Fix simple_semaphore to follow POSIX threads convention for reporting errors.
This commit is contained in:
parent
72fdf47d16
commit
0aacee389f
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -81,10 +82,10 @@ namespace zmq
|
|||||||
}} while (false)
|
}} while (false)
|
||||||
|
|
||||||
// Provides convenient way to check for POSIX errors.
|
// Provides convenient way to check for POSIX errors.
|
||||||
#define posix_assert(x) do {\
|
#define posix_assert(x) do { if ((x)) {\
|
||||||
fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\
|
fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\
|
||||||
abort ();\
|
abort ();\
|
||||||
} while (false)
|
}} while (false)
|
||||||
|
|
||||||
// Provides convenient way to check for errors from getaddrinfo.
|
// Provides convenient way to check for errors from getaddrinfo.
|
||||||
#define gai_assert(x) do { if (x) {\
|
#define gai_assert(x) do { if (x) {\
|
||||||
|
@ -53,32 +53,32 @@ namespace zmq
|
|||||||
inline simple_semaphore_t ()
|
inline simple_semaphore_t ()
|
||||||
{
|
{
|
||||||
int rc = pthread_mutex_init (&mutex, NULL);
|
int rc = pthread_mutex_init (&mutex, NULL);
|
||||||
errno_assert (rc == 0);
|
posix_assert (rc);
|
||||||
rc = pthread_mutex_lock (&mutex);
|
rc = pthread_mutex_lock (&mutex);
|
||||||
errno_assert (rc == 0);
|
posix_assert (rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the semaphore.
|
// Destroy the semaphore.
|
||||||
inline ~simple_semaphore_t ()
|
inline ~simple_semaphore_t ()
|
||||||
{
|
{
|
||||||
int rc = pthread_mutex_unlock (&mutex);
|
int rc = pthread_mutex_unlock (&mutex);
|
||||||
errno_assert (rc == 0);
|
posix_assert (rc);
|
||||||
rc = pthread_mutex_destroy (&mutex);
|
rc = pthread_mutex_destroy (&mutex);
|
||||||
errno_assert (rc == 0);
|
posix_assert (rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the semaphore.
|
// Wait for the semaphore.
|
||||||
inline void wait ()
|
inline void wait ()
|
||||||
{
|
{
|
||||||
int rc = pthread_mutex_lock (&mutex);
|
int rc = pthread_mutex_lock (&mutex);
|
||||||
errno_assert (rc == 0);
|
posix_assert (rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post the semaphore.
|
// Post the semaphore.
|
||||||
inline void post ()
|
inline void post ()
|
||||||
{
|
{
|
||||||
int rc = pthread_mutex_unlock (&mutex);
|
int rc = pthread_mutex_unlock (&mutex);
|
||||||
errno_assert (rc == 0);
|
posix_assert (rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user