snprintf(name, sizeof(name), "%02u", i);
dupname = strdup(name);
RUNTIME_CHECK(dupname != NULL);
- if (i != 0 && i % 3 == 0)
- RUNTIME_CHECK(isc_thread_create(run1, dupname,
- &workers[i]) ==
- ISC_R_SUCCESS);
- else
- RUNTIME_CHECK(isc_thread_create(run2, dupname,
- &workers[i]) ==
- ISC_R_SUCCESS);
+ if (i != 0 && i % 3 == 0) {
+ isc_thread_create(run1, dupname, &workers[i]);
+ } else {
+ isc_thread_create(run2, dupname, &workers[i]);
+ }
}
for (i = 0; i < nworkers; i++)
nthreads = ISC_MIN(isc_os_ncpus(), 32);
nthreads = ISC_MAX(nthreads, 1);
for (i = 0; i < nthreads; i++) {
- result = isc_thread_create(fromwire_thread, NULL, &threads[i]);
- assert_int_equal(result, ISC_R_SUCCESS);
+ isc_thread_create(fromwire_thread, NULL, &threads[i]);
}
for (i = 0; i < nthreads; i++) {
nthreads = ISC_MIN(isc_os_ncpus(), 32);
nthreads = ISC_MAX(nthreads, 1);
for (i = 0; i < nthreads; i++) {
- result = isc_thread_create(find_thread, mytree, &threads[i]);
- assert_int_equal(result, ISC_R_SUCCESS);
+ isc_thread_create(find_thread, mytree, &threads[i]);
}
for (i = 0; i < nthreads; i++) {
typedef isc_threadresult_t (*isc_threadfunc_t)(isc_threadarg_t);
typedef pthread_key_t isc_thread_key_t;
-isc_result_t
+void
isc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
void
#define THREAD_MINSTACKSIZE (1024U * 1024)
#endif
-isc_result_t
+#define _FATAL(r, f) \
+ { \
+ char strbuf[ISC_STRERRORSIZE]; \
+ strerror_r(r, strbuf, sizeof(strbuf)); \
+ isc_error_fatal(__FILE__, __LINE__, \
+ f # " failed: %s", \
+ strbuf); \
+ }
+
+void
isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg,
isc_thread_t *thread)
{
#if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \
defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
ret = pthread_attr_getstacksize(&attr, &stacksize);
- if (ret != 0)
- return (ISC_R_UNEXPECTED);
+ if (ret != 0) {
+ _FATAL(ret, "pthread_attr_getstacksize");
+ }
if (stacksize < THREAD_MINSTACKSIZE) {
ret = pthread_attr_setstacksize(&attr, THREAD_MINSTACKSIZE);
- if (ret != 0)
- return (ISC_R_UNEXPECTED);
+ if (ret != 0) {
+ _FATAL(ret, pthread_attr_setstacksize);
+ }
}
#endif
ret = pthread_create(thread, &attr, func, arg);
- if (ret != 0)
- return (ISC_R_UNEXPECTED);
+ if (ret != 0) {
+ _FATAL(ret,"pthread_create");
+ }
pthread_attr_destroy(&attr);
- return (ISC_R_SUCCESS);
+ return;
}
#ifdef __NetBSD__
manager->queues[i].manager = manager;
manager->queues[i].threadid = i;
- RUNTIME_CHECK(isc_thread_create(run, &manager->queues[i],
- &manager->queues[i].thread)
- == ISC_R_SUCCESS);
+ isc_thread_create(run, &manager->queues[i],
+ &manager->queues[i].thread);
char name[21];
snprintf(name, sizeof(name), "isc-worker%04u", i);
isc_thread_setname(manager->queues[i].thread, name);
assert_int_equal(result, ISC_R_SUCCESS);
for (int i = 0; i < nthreads; i++) {
- result = isc_thread_create(mem_thread, &size, &threads[i]);
- assert_int_equal(result, ISC_R_SUCCESS);
+ isc_thread_create(mem_thread, &size, &threads[i]);
size = size / 2;
}
for (int i = 0; i < nthreads; i++) {
assert_int_equal(result, ISC_R_SUCCESS);
for (int i = 0; i < nthreads; i++) {
- result = isc_thread_create(mempool_thread, mp, &threads[i]);
- assert_int_equal(result, ISC_R_SUCCESS);
+ isc_thread_create(mempool_thread, mp, &threads[i]);
size = size / 2;
}
for (int i = 0; i < nthreads; i++) {
isc_mutex_init(&manager->lock);
isc_mem_attach(mctx, &manager->mctx);
isc_condition_init(&manager->wakeup);
- if (isc_thread_create(run, manager, &manager->thread) !=
- ISC_R_SUCCESS) {
- isc_mem_detach(&manager->mctx);
- (void)isc_condition_destroy(&manager->wakeup);
- isc_mutex_destroy(&manager->lock);
- isc_heap_destroy(&manager->heap);
- isc_mem_put(mctx, manager, sizeof(*manager));
- UNEXPECTED_ERROR(__FILE__, __LINE__, "%s",
- "isc_thread_create() failed");
- return (ISC_R_UNEXPECTED);
- }
+ isc_thread_create(run, manager, &manager->thread);
isc_thread_setname(manager->thread, "isc-timer");
*managerp = (isc_timermgr_t *)manager;
manager->threads[i].manager = manager;
manager->threads[i].threadid = i;
setup_thread(&manager->threads[i]);
- RUNTIME_CHECK(isc_thread_create(netthread,
- &manager->threads[i],
- &manager->threads[i].thread)
- == ISC_R_SUCCESS);
+ isc_thread_create(netthread,
+ &manager->threads[i],
+ &manager->threads[i].thread);
char tname[1024];
sprintf(tname, "isc-socket-%d", i);
isc_thread_setname(manager->threads[i].thread, tname);
ISC_LANG_BEGINDECLS
-isc_result_t
+void
isc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
isc_result_t
#include <process.h>
+#include <isc/strerr.h>
#include <isc/thread.h>
#include <isc/util.h>
-isc_result_t
+void
isc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg,
isc_thread_t *threadp)
{
thread = (isc_thread_t)_beginthreadex(NULL, 0, start, arg, 0, &id);
if (thread == NULL) {
- /* XXX */
- return (ISC_R_UNEXPECTED);
+ char strbuf[ISC_STRERRORSIZE];
+ /* FIXME */
+ strerror_r(GetLastError(), strbuf, sizeof(strbuf));
+ isc_error_fatal(__FILE__, __LINE__, "_beginthreadex failed: %s",
+ strbuf);
}
*threadp = thread;
- return (ISC_R_SUCCESS);
+ return;
}
isc_result_t