}
}
- 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);
}
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);
}
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);
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);
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
#include <sys/procset.h>
#endif
+#include <isc/strerr.h>
#include <isc/thread.h>
#include <isc/util.h>
char strbuf[ISC_STRERRORSIZE]; \
strerror_r(r, strbuf, sizeof(strbuf)); \
isc_error_fatal(__FILE__, __LINE__, \
- f # " failed: %s", \
+ f " failed: %s", \
strbuf); \
}
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);
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
/*
* 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);
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);
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);
/*
* 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.
* 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]);
}
/*
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
* 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.
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);
}
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);