#endif /* ISC_TRACK_PTHREADS_OBJECTS */
-#define isc__condition_init(cond) \
- { \
- int _ret = pthread_cond_init(cond, NULL); \
- ERRNO_CHECK(pthread_cond_init, _ret); \
+#define isc__condition_init(cond) \
+ { \
+ int _ret = pthread_cond_init(cond, NULL); \
+ PTHREADS_RUNTIME_CHECK(pthread_cond_init, _ret); \
}
-#define isc__condition_wait(cp, mp) \
- { \
- int _ret = pthread_cond_wait(cp, mp); \
- ERRNO_CHECK(pthread_cond_wait, _ret); \
+#define isc__condition_wait(cp, mp) \
+ { \
+ int _ret = pthread_cond_wait(cp, mp); \
+ PTHREADS_RUNTIME_CHECK(pthread_cond_wait, _ret); \
}
-#define isc__condition_signal(cp) \
- { \
- int _ret = pthread_cond_signal(cp); \
- ERRNO_CHECK(pthread_cond_signal, _ret); \
+#define isc__condition_signal(cp) \
+ { \
+ int _ret = pthread_cond_signal(cp); \
+ PTHREADS_RUNTIME_CHECK(pthread_cond_signal, _ret); \
}
-#define isc__condition_broadcast(cp) \
- { \
- int _ret = pthread_cond_broadcast(cp); \
- ERRNO_CHECK(pthread_cond_broadcast, _ret); \
+#define isc__condition_broadcast(cp) \
+ { \
+ int _ret = pthread_cond_broadcast(cp); \
+ PTHREADS_RUNTIME_CHECK(pthread_cond_broadcast, _ret); \
}
-#define isc__condition_destroy(cp) \
- { \
- int _ret = pthread_cond_destroy(cp); \
- ERRNO_CHECK(pthread_cond_destroy, _ret); \
+#define isc__condition_destroy(cp) \
+ { \
+ int _ret = pthread_cond_destroy(cp); \
+ PTHREADS_RUNTIME_CHECK(pthread_cond_destroy, _ret); \
}
isc_result_t
#define isc__mutex_init(mp) \
{ \
int _ret = pthread_mutex_init(mp, &isc__mutex_init_attr); \
- ERRNO_CHECK(pthread_mutex_init, _ret); \
+ PTHREADS_RUNTIME_CHECK(pthread_mutex_init, _ret); \
}
-#define isc__mutex_lock(mp) \
- { \
- int _ret = pthread_mutex_lock(mp); \
- ERRNO_CHECK(pthread_mutex_lock, _ret); \
+#define isc__mutex_lock(mp) \
+ { \
+ int _ret = pthread_mutex_lock(mp); \
+ PTHREADS_RUNTIME_CHECK(pthread_mutex_lock, _ret); \
}
-#define isc__mutex_unlock(mp) \
- { \
- int _ret = pthread_mutex_unlock(mp); \
- ERRNO_CHECK(pthread_mutex_unlock, _ret); \
+#define isc__mutex_unlock(mp) \
+ { \
+ int _ret = pthread_mutex_unlock(mp); \
+ PTHREADS_RUNTIME_CHECK(pthread_mutex_unlock, _ret); \
}
#define isc__mutex_trylock(mp) \
((pthread_mutex_trylock(mp) == 0) ? ISC_R_SUCCESS : ISC_R_LOCKBUSY)
-#define isc__mutex_destroy(mp) \
- { \
- int _ret = pthread_mutex_destroy(mp); \
- ERRNO_CHECK(pthread_mutex_destroy, _ret); \
+#define isc__mutex_destroy(mp) \
+ { \
+ int _ret = pthread_mutex_destroy(mp); \
+ PTHREADS_RUNTIME_CHECK(pthread_mutex_destroy, _ret); \
}
ISC_LANG_ENDDECLS
#endif /* USE_PTHREAD_RWLOCK */
-#define isc__rwlock_init(rwl, rq, wq) \
- { \
- int _ret = isc___rwlock_init(rwl, rq, wq); \
- ERRNO_CHECK(isc___rwlock_init, _ret); \
+#define isc__rwlock_init(rwl, rq, wq) \
+ { \
+ int _ret = isc___rwlock_init(rwl, rq, wq); \
+ PTHREADS_RUNTIME_CHECK(isc___rwlock_init, _ret); \
}
-#define isc__rwlock_lock(rwl, type) \
- { \
- int _ret = isc___rwlock_lock(rwl, type); \
- ERRNO_CHECK(isc___rwlock_lock, _ret); \
+#define isc__rwlock_lock(rwl, type) \
+ { \
+ int _ret = isc___rwlock_lock(rwl, type); \
+ PTHREADS_RUNTIME_CHECK(isc___rwlock_lock, _ret); \
}
-#define isc__rwlock_unlock(rwl, type) \
- { \
- int _ret = isc___rwlock_unlock(rwl, type); \
- ERRNO_CHECK(isc___rwlock_unlock, _ret); \
+#define isc__rwlock_unlock(rwl, type) \
+ { \
+ int _ret = isc___rwlock_unlock(rwl, type); \
+ PTHREADS_RUNTIME_CHECK(isc___rwlock_unlock, _ret); \
}
-#define isc__rwlock_downgrade(rwl) \
- { \
- int _ret = isc___rwlock_downgrade(rwl); \
- ERRNO_CHECK(isc___rwlock_downgrade, _ret); \
+#define isc__rwlock_downgrade(rwl) \
+ { \
+ int _ret = isc___rwlock_downgrade(rwl); \
+ PTHREADS_RUNTIME_CHECK(isc___rwlock_downgrade, _ret); \
}
-#define isc__rwlock_destroy(rwl) \
- { \
- int _ret = isc___rwlock_destroy(rwl); \
- ERRNO_CHECK(isc___rwlock_destroy, _ret); \
+#define isc__rwlock_destroy(rwl) \
+ { \
+ int _ret = isc___rwlock_destroy(rwl); \
+ PTHREADS_RUNTIME_CHECK(isc___rwlock_destroy, _ret); \
}
int
#endif /* UNIT_TESTING */
-/*% Runtime check which logs the error string corresponding to errno */
-#define ERRNO_CHECK(func, ret) \
- if ((ret) != 0) { \
- char _strerrorbuf[ISC_STRERRORSIZE]; \
- strerror_r(errno, _strerrorbuf, sizeof(_strerrorbuf)); \
- isc_error_fatal(__FILE__, __LINE__, "%s() failed in %s(): %s", \
- #func, __func__, _strerrorbuf); \
+/*%
+ * Runtime check which logs the error value returned by a POSIX Threads
+ * function and the error string that corresponds to it
+ */
+#define PTHREADS_RUNTIME_CHECK(func, ret) \
+ if ((ret) != 0) { \
+ char _strerrorbuf[ISC_STRERRORSIZE]; \
+ strerror_r(ret, _strerrorbuf, sizeof(_strerrorbuf)); \
+ isc_error_fatal(__FILE__, __LINE__, \
+ "%s(): %s() failed with error %d (%s)", \
+ __func__, #func, ret, _strerrorbuf); \
}
/*%
#if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \
defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
ret = pthread_attr_getstacksize(&attr, &stacksize);
- ERRNO_CHECK(pthread_attr_getstacksize, ret);
+ PTHREADS_RUNTIME_CHECK(pthread_attr_getstacksize, ret);
if (stacksize < THREAD_MINSTACKSIZE) {
ret = pthread_attr_setstacksize(&attr, THREAD_MINSTACKSIZE);
- ERRNO_CHECK(pthread_attr_setstacksize, ret);
+ PTHREADS_RUNTIME_CHECK(pthread_attr_setstacksize, ret);
}
#endif /* if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \
* defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) */
ret = pthread_create(thread, &attr, isc__trampoline_run,
trampoline_arg);
- ERRNO_CHECK(pthread_create, ret);
+ PTHREADS_RUNTIME_CHECK(pthread_create, ret);
pthread_attr_destroy(&attr);
isc_thread_join(isc_thread_t thread, isc_threadresult_t *result) {
int ret = pthread_join(thread, result);
- ERRNO_CHECK(pthread_join, ret);
+ PTHREADS_RUNTIME_CHECK(pthread_join, ret);
}
void