Commit 73a8999d authored by Ondřej Surý's avatar Ondřej Surý Committed by Witold Krecicki
Browse files

isc_condition_init returns 'void'

parent 0bed9bfc
......@@ -9,22 +9,30 @@
* information regarding copyright ownership.
*/
#ifndef ISC_CONDITION_H
#define ISC_CONDITION_H 1
#pragma once
/*! \file */
#include <errno.h>
#include <isc/error.h>
#include <isc/lang.h>
#include <isc/mutex.h>
#include <isc/result.h>
#include <isc/strerr.h>
#include <isc/types.h>
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 */
......@@ -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
......
......@@ -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);
}
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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.
......
......@@ -9,7 +9,6 @@
* information regarding copyright ownership.
*/
#include <config.h>
#include <inttypes.h>
......@@ -17,14 +16,16 @@
#include <isc/condition.h>
#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/util.h>
#include <isc/strerr.h>
#include <isc/thread.h>
#include <isc/time.h>
#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);
}
......
......@@ -37,7 +37,7 @@ typedef struct isc_condition {
ISC_LANG_BEGINDECLS
isc_result_t
void
isc_condition_init(isc_condition_t *);
isc_result_t
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment