mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Make isc_thread_join() assert internally on failure
Previously isc_thread_join() would return ISC_R_UNEXPECTED on a failure to create new thread. All such occurences were caught and wrapped into assert function at higher level. The function was simplified to assert directly in the isc_thread_join() function and all caller level assertions were removed.
This commit is contained in:
parent
d6a60f2905
commit
46919579bb
12 changed files with 38 additions and 43 deletions
|
|
@ -116,8 +116,9 @@ main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < nworkers; i++)
|
||||
(void)isc_thread_join(workers[i], NULL);
|
||||
for (i = 0; i < nworkers; i++) {
|
||||
isc_thread_join(workers[i], NULL);
|
||||
}
|
||||
|
||||
isc_rwlock_destroy(&lock);
|
||||
|
||||
|
|
|
|||
|
|
@ -747,8 +747,7 @@ benchmark_test(void **state) {
|
|||
}
|
||||
|
||||
for (i = 0; i < nthreads; i++) {
|
||||
result = isc_thread_join(threads[i], NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_thread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
result = isc_time_now(&ts2);
|
||||
|
|
|
|||
|
|
@ -1299,8 +1299,7 @@ benchmark(void **state) {
|
|||
}
|
||||
|
||||
for (i = 0; i < nthreads; i++) {
|
||||
result = isc_thread_join(threads[i], NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_thread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
result = isc_time_now(&ts2);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ typedef pthread_key_t isc_thread_key_t;
|
|||
void
|
||||
isc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
|
||||
|
||||
void
|
||||
isc_thread_join(isc_thread_t thread, isc_threadresult_t *result);
|
||||
|
||||
void
|
||||
isc_thread_setconcurrency(unsigned int level);
|
||||
|
||||
|
|
@ -47,12 +50,6 @@ isc_thread_setname(isc_thread_t thread, const char *name);
|
|||
isc_result_t
|
||||
isc_thread_setaffinity(int cpu);
|
||||
|
||||
/* XXX We could do fancier error handling... */
|
||||
|
||||
#define isc_thread_join(t, rp) \
|
||||
((pthread_join((t), (rp)) == 0) ? \
|
||||
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
|
||||
|
||||
#define isc_thread_self \
|
||||
(unsigned long)pthread_self
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <sys/procset.h>
|
||||
#endif
|
||||
|
||||
#include <isc/strerr.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
|
|
@ -39,7 +40,7 @@
|
|||
char strbuf[ISC_STRERRORSIZE]; \
|
||||
strerror_r(r, strbuf, sizeof(strbuf)); \
|
||||
isc_error_fatal(__FILE__, __LINE__, \
|
||||
f # " failed: %s", \
|
||||
f " failed: %s", \
|
||||
strbuf); \
|
||||
}
|
||||
|
||||
|
|
@ -60,20 +61,20 @@ isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg,
|
|||
defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
|
||||
ret = pthread_attr_getstacksize(&attr, &stacksize);
|
||||
if (ret != 0) {
|
||||
_FATAL(ret, "pthread_attr_getstacksize");
|
||||
_FATAL(ret, "pthread_attr_getstacksize()");
|
||||
}
|
||||
|
||||
if (stacksize < THREAD_MINSTACKSIZE) {
|
||||
ret = pthread_attr_setstacksize(&attr, THREAD_MINSTACKSIZE);
|
||||
if (ret != 0) {
|
||||
_FATAL(ret, pthread_attr_setstacksize);
|
||||
_FATAL(ret, "pthread_attr_setstacksize()");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = pthread_create(thread, &attr, func, arg);
|
||||
if (ret != 0) {
|
||||
_FATAL(ret,"pthread_create");
|
||||
_FATAL(ret, "pthread_create()");
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
|
|
@ -81,6 +82,15 @@ isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg,
|
|||
return;
|
||||
}
|
||||
|
||||
void
|
||||
isc_thread_join(isc_thread_t thread, isc_threadresult_t *result)
|
||||
{
|
||||
int ret = pthread_join(thread, result);
|
||||
if (ret != 0) {
|
||||
_FATAL(ret, "pthread_join()");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#define pthread_setconcurrency(a) (void) a/* nothing */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1483,8 +1483,9 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
|
|||
/*
|
||||
* Wait for all the worker threads to exit.
|
||||
*/
|
||||
for (i = 0; i < manager->workers; i++)
|
||||
(void)isc_thread_join(manager->queues[i].thread, NULL);
|
||||
for (i = 0; i < manager->workers; i++) {
|
||||
isc_thread_join(manager->queues[i].thread, NULL);
|
||||
}
|
||||
|
||||
manager_free(manager);
|
||||
|
||||
|
|
|
|||
|
|
@ -467,8 +467,7 @@ isc_mem_benchmark(void **state) {
|
|||
size = size / 2;
|
||||
}
|
||||
for (int i = 0; i < nthreads; i++) {
|
||||
result = isc_thread_join(threads[i], NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_thread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
result = isc_time_now(&ts2);
|
||||
|
|
@ -530,8 +529,7 @@ isc_mempool_benchmark(void **state) {
|
|||
size = size / 2;
|
||||
}
|
||||
for (int i = 0; i < nthreads; i++) {
|
||||
result = isc_thread_join(threads[i], NULL);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_thread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
result = isc_time_now(&ts2);
|
||||
|
|
|
|||
|
|
@ -739,9 +739,7 @@ isc_timermgr_destroy(isc_timermgr_t **managerp) {
|
|||
/*
|
||||
* Wait for thread to exit.
|
||||
*/
|
||||
if (isc_thread_join(manager->thread, NULL) != ISC_R_SUCCESS)
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__, "%s",
|
||||
"isc_thread_join() failed");
|
||||
isc_thread_join(manager->thread, NULL);
|
||||
|
||||
/*
|
||||
* Clean up.
|
||||
|
|
|
|||
|
|
@ -3884,12 +3884,7 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
|
|||
* Wait for thread to exit.
|
||||
*/
|
||||
for (int i = 0; i < manager->nthreads; i++) {
|
||||
isc_result_t result;
|
||||
result = isc_thread_join(manager->threads[i].thread, NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_thread_join() failed");
|
||||
}
|
||||
isc_thread_join(manager->threads[i].thread, NULL);
|
||||
cleanup_thread(manager->mctx, &manager->threads[i]);
|
||||
}
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ ISC_LANG_BEGINDECLS
|
|||
void
|
||||
isc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_thread_join(isc_thread_t, isc_threadresult_t *);
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -2569,10 +2569,7 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
|
|||
* Wait for threads to exit.
|
||||
*/
|
||||
for (int i = 0; i < manager->maxIOCPThreads; i++) {
|
||||
if (isc_thread_join((isc_thread_t) manager->hIOCPThreads[i],
|
||||
NULL) != ISC_R_SUCCESS)
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_thread_join() for Completion Port failed");
|
||||
isc_thread_join((isc_thread_t) manager->hIOCPThreads[i], NULL);
|
||||
}
|
||||
/*
|
||||
* Clean up.
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ isc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg,
|
|||
thread = (isc_thread_t)_beginthreadex(NULL, 0, start, arg, 0, &id);
|
||||
if (thread == NULL) {
|
||||
char strbuf[ISC_STRERRORSIZE];
|
||||
/* FIXME */
|
||||
strerror_r(GetLastError(), strbuf, sizeof(strbuf));
|
||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||
isc_error_fatal(__FILE__, __LINE__, "_beginthreadex failed: %s",
|
||||
strbuf);
|
||||
}
|
||||
|
|
@ -36,18 +35,19 @@ isc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg,
|
|||
return;
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
void
|
||||
isc_thread_join(isc_thread_t thread, isc_threadresult_t *rp) {
|
||||
DWORD result;
|
||||
|
||||
result = WaitForSingleObject(thread, INFINITE);
|
||||
if (result != WAIT_OBJECT_0) {
|
||||
/* XXX */
|
||||
return (ISC_R_UNEXPECTED);
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"WaitForSingleObject() != WAIT_OBJECT_0");
|
||||
}
|
||||
if (rp != NULL && !GetExitCodeThread(thread, rp)) {
|
||||
/* XXX */
|
||||
return (ISC_R_UNEXPECTED);
|
||||
isc_error_fatal(__FILE__, __LINE__,
|
||||
"GetExitCodeThread() failed: %d", GetLastError());
|
||||
|
||||
}
|
||||
(void)CloseHandle(thread);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue