From 73a8999d1cc003f0b27ea5d967ff7df78cf177fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 15 Nov 2018 17:20:36 +0100 Subject: [PATCH] isc_condition_init returns 'void' --- lib/isc/pthreads/include/isc/condition.h | 22 +++++++++++------- lib/isc/rwlock.c | 29 ++---------------------- lib/isc/task.c | 8 +++---- lib/isc/tests/task_test.c | 21 ++++++----------- lib/isc/tests/timer_test.c | 6 ++--- lib/isc/timer.c | 12 +--------- lib/isc/unix/app.c | 6 +---- lib/isc/unix/socket.c | 3 +-- lib/isc/win32/condition.c | 15 ++++++------ lib/isc/win32/include/isc/condition.h | 2 +- lib/isc/win32/socket.c | 10 +------- 11 files changed, 41 insertions(+), 93 deletions(-) diff --git a/lib/isc/pthreads/include/isc/condition.h b/lib/isc/pthreads/include/isc/condition.h index 92d33ad324..0ad9a0f0b2 100644 --- a/lib/isc/pthreads/include/isc/condition.h +++ b/lib/isc/pthreads/include/isc/condition.h @@ -9,22 +9,30 @@ * information regarding copyright ownership. */ - -#ifndef ISC_CONDITION_H -#define ISC_CONDITION_H 1 +#pragma once /*! \file */ +#include + +#include #include #include #include +#include #include typedef pthread_cond_t isc_condition_t; -#define isc_condition_init(cp) \ - (RUNTIME_CHECK(pthread_cond_init((cp), NULL) == 0), \ - ISC_R_SUCCESS) +#define isc_condition_init(cond) \ + if (pthread_cond_init(cond, NULL) != 0) { \ + char isc_condition_strbuf[ISC_STRERRORSIZE]; \ + strerror_r(errno, isc_condition_strbuf, \ + sizeof(isc_condition_strbuf)); \ + isc_error_fatal(__FILE__, __LINE__, \ + "pthread_cond_init failed: %s", \ + isc_condition_strbuf); \ + } #if ISC_MUTEX_PROFILE #define isc_condition_wait(cp, mp) \ @@ -54,5 +62,3 @@ isc_result_t isc_condition_waituntil(isc_condition_t *, isc_mutex_t *, isc_time_t *); ISC_LANG_ENDDECLS - -#endif /* ISC_CONDITION_H */ diff --git a/lib/isc/rwlock.c b/lib/isc/rwlock.c index 8e4a94108b..d95950658e 100644 --- a/lib/isc/rwlock.c +++ b/lib/isc/rwlock.c @@ -122,37 +122,12 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota, if (result != ISC_R_SUCCESS) return (result); - result = isc_condition_init(&rwl->readable); - if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_condition_init(readable) %s: %s", - isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, - ISC_MSG_FAILED, "failed"), - isc_result_totext(result)); - result = ISC_R_UNEXPECTED; - goto destroy_lock; - } - result = isc_condition_init(&rwl->writeable); - if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_condition_init(writeable) %s: %s", - isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, - ISC_MSG_FAILED, "failed"), - isc_result_totext(result)); - result = ISC_R_UNEXPECTED; - goto destroy_rcond; - } + isc_condition_init(&rwl->readable); + isc_condition_init(&rwl->writeable); rwl->magic = RWLOCK_MAGIC; return (ISC_R_SUCCESS); - - destroy_rcond: - (void)isc_condition_destroy(&rwl->readable); - destroy_lock: - DESTROYLOCK(&rwl->lock); - - return (result); } void diff --git a/lib/isc/task.c b/lib/isc/task.c index c2d00feffd..93cdac3bdd 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -1340,7 +1340,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers, RUNTIME_CHECK(isc_mutex_init(&manager->excl_lock) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_mutex_init(&manager->halt_lock) == ISC_R_SUCCESS); - RUNTIME_CHECK(isc_condition_init(&manager->halt_cond) == ISC_R_SUCCESS); + isc_condition_init(&manager->halt_cond); manager->workers = workers; @@ -1372,9 +1372,8 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers, INIT_LIST(manager->queues[i].ready_priority_tasks); RUNTIME_CHECK(isc_mutex_init(&manager->queues[i].lock) == ISC_R_SUCCESS); - RUNTIME_CHECK(isc_condition_init( - &manager->queues[i].work_available) - == ISC_R_SUCCESS); + isc_condition_init(&manager->queues[i].work_available); + manager->queues[i].manager = manager; manager->queues[i].threadid = i; RUNTIME_CHECK(isc_thread_create(run, &manager->queues[i], @@ -1875,4 +1874,3 @@ isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, return (result); } - diff --git a/lib/isc/tests/task_test.c b/lib/isc/tests/task_test.c index 8276c3a85a..c9c1d51277 100644 --- a/lib/isc/tests/task_test.c +++ b/lib/isc/tests/task_test.c @@ -59,8 +59,7 @@ _setup(void **state) { result = isc_mutex_init(&lock); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); result = isc_test_begin(NULL, true, 0); assert_int_equal(result, ISC_R_SUCCESS); @@ -77,8 +76,7 @@ _setup2(void **state) { result = isc_mutex_init(&lock); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); /* Two worker threads */ result = isc_test_begin(NULL, true, 2); @@ -96,8 +94,7 @@ _setup4(void **state) { result = isc_mutex_init(&lock); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); /* Four worker threads */ result = isc_test_begin(NULL, true, 4); @@ -712,8 +709,7 @@ manytasks(void **state) { (unsigned long)ntasks); } - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); isc_mem_debugging = ISC_MEM_DEBUGRECORD; result = isc_mem_create(0, 0, &mctx); @@ -914,8 +910,7 @@ post_shutdown(void **state) { done = false; event_type = 4; - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); LOCK(&lock); @@ -1056,8 +1051,7 @@ test_purge(int sender, int type, int tag, int exp_purged) { done = false; eventcnt = 0; - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); result = isc_task_create(taskmgr, 0, &task); assert_int_equal(result, ISC_R_SUCCESS); @@ -1356,8 +1350,7 @@ try_purgeevent(bool purgeable) { done = false; eventcnt = 0; - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); result = isc_task_create(taskmgr, 0, &task); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/isc/tests/timer_test.c b/lib/isc/tests/timer_test.c index d964c7c8cc..1ef15779e1 100644 --- a/lib/isc/tests/timer_test.c +++ b/lib/isc/tests/timer_test.c @@ -108,8 +108,7 @@ setup_test(isc_timertype_t timertype, isc_time_t *expires, result = isc_mutex_init(&mx); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); LOCK(&mx); @@ -506,8 +505,7 @@ purge(void **state) { result = isc_mutex_init(&mx); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_condition_init(&cv); - assert_int_equal(result, ISC_R_SUCCESS); + isc_condition_init(&cv); result = isc_task_create(taskmgr, 0, &task1); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/lib/isc/timer.c b/lib/isc/timer.c index f75ea18643..96b3d4293a 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -750,17 +750,7 @@ isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) { return (result); } isc_mem_attach(mctx, &manager->mctx); - if (isc_condition_init(&manager->wakeup) != ISC_R_SUCCESS) { - isc_mem_detach(&manager->mctx); - DESTROYLOCK(&manager->lock); - isc_heap_destroy(&manager->heap); - isc_mem_put(mctx, manager, sizeof(*manager)); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_condition_init() %s", - isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, - ISC_MSG_FAILED, "failed")); - return (ISC_R_UNEXPECTED); - } + isc_condition_init(&manager->wakeup); if (isc_thread_create(run, manager, &manager->thread) != ISC_R_SUCCESS) { isc_mem_detach(&manager->mctx); diff --git a/lib/isc/unix/app.c b/lib/isc/unix/app.c index 5705a44efb..8027f592bf 100644 --- a/lib/isc/unix/app.c +++ b/lib/isc/unix/app.c @@ -142,9 +142,7 @@ isc_app_ctxstart(isc_appctx_t *ctx0) { if (result != ISC_R_SUCCESS) return (result); - result = isc_condition_init(&ctx->ready); - if (result != ISC_R_SUCCESS) - goto cleanup_rlock; + isc_condition_init(&ctx->ready); result = isc_mutex_init(&ctx->lock); if (result != ISC_R_SUCCESS) @@ -236,8 +234,6 @@ isc_app_ctxstart(isc_appctx_t *ctx0) { cleanup: (void)isc_condition_destroy(&ctx->ready); - - cleanup_rlock: (void)isc_mutex_destroy(&ctx->readylock); return (result); } diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 2fb6d4fd66..9b29cde324 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -3934,8 +3934,7 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, ISC_LIST_INIT(manager->socklist); RUNTIME_CHECK(isc_mutex_init(&manager->lock) == ISC_R_SUCCESS); - RUNTIME_CHECK(isc_condition_init(&manager->shutdown_ok) - == ISC_R_SUCCESS); + isc_condition_init(&manager->shutdown_ok); /* * Start up the select/poll thread. diff --git a/lib/isc/win32/condition.c b/lib/isc/win32/condition.c index 78875081cb..814fc8ef5e 100644 --- a/lib/isc/win32/condition.c +++ b/lib/isc/win32/condition.c @@ -9,7 +9,6 @@ * information regarding copyright ownership. */ - #include #include @@ -17,14 +16,16 @@ #include #include +#include #include +#include #include #include #define LSIGNAL 0 #define LBROADCAST 1 -isc_result_t +void isc_condition_init(isc_condition_t *cond) { HANDLE h; @@ -36,8 +37,11 @@ isc_condition_init(isc_condition_t *cond) { */ h = CreateEvent(NULL, FALSE, FALSE, NULL); if (h == NULL) { - /* XXX */ - return (ISC_R_UNEXPECTED); + char strbuf[ISC_STRERRORSIZE]; + DWORD err = GetLastError(); + strerror_r(err, strbuf, sizeof(strbuf)); + isc_error_fatal(__FILE__, __LINE, + "CreateEvent failed: %s", strbuf); } cond->events[LSIGNAL] = h; @@ -46,8 +50,6 @@ isc_condition_init(isc_condition_t *cond) { * for the wait condition */ ISC_LIST_INIT(cond->threadlist); - - return (ISC_R_SUCCESS); } /* @@ -131,7 +133,6 @@ isc_condition_signal(isc_condition_t *cond) { /* XXX */ return (ISC_R_UNEXPECTED); } - return (ISC_R_SUCCESS); } diff --git a/lib/isc/win32/include/isc/condition.h b/lib/isc/win32/include/isc/condition.h index 1f5b2d6042..e69425b208 100644 --- a/lib/isc/win32/include/isc/condition.h +++ b/lib/isc/win32/include/isc/condition.h @@ -37,7 +37,7 @@ typedef struct isc_condition { ISC_LANG_BEGINDECLS -isc_result_t +void isc_condition_init(isc_condition_t *); isc_result_t diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 28d96b0df5..4bd9b87b67 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -2561,15 +2561,7 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, isc_mem_put(mctx, manager, sizeof(*manager)); return (result); } - if (isc_condition_init(&manager->shutdown_ok) != ISC_R_SUCCESS) { - DESTROYLOCK(&manager->lock); - isc_mem_put(mctx, manager, sizeof(*manager)); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_condition_init() %s", - isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, - ISC_MSG_FAILED, "failed")); - return (ISC_R_UNEXPECTED); - } + isc_condition_init(&manager->shutdown_ok); isc_mem_attach(mctx, &manager->mctx); if (nthreads == 0) {