1998-12-12 15:48:14 -05:00
|
|
|
/*
|
2018-02-23 03:53:12 -05:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-07-31 21:33:37 -04:00
|
|
|
*
|
2016-06-27 00:56:38 -04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 19:50:58 -04:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 03:53:12 -05:00
|
|
|
*
|
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
|
* information regarding copyright ownership.
|
1998-12-12 15:48:14 -05:00
|
|
|
*/
|
1998-10-23 02:02:07 -04:00
|
|
|
|
1999-09-23 14:26:12 -04:00
|
|
|
#include <process.h>
|
|
|
|
|
|
2021-02-16 09:57:39 -05:00
|
|
|
#include <isc/mutex.h>
|
|
|
|
|
#include <isc/once.h>
|
2019-07-18 11:24:05 -04:00
|
|
|
#include <isc/strerr.h>
|
1998-10-23 02:02:07 -04:00
|
|
|
#include <isc/thread.h>
|
2017-05-01 16:28:24 -04:00
|
|
|
#include <isc/util.h>
|
1998-10-23 02:02:07 -04:00
|
|
|
|
2021-02-16 09:57:39 -05:00
|
|
|
#include "trampoline_p.h"
|
|
|
|
|
|
2019-07-18 11:24:05 -04:00
|
|
|
void
|
2000-07-31 21:33:37 -04:00
|
|
|
isc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg,
|
2020-02-14 00:35:17 -05:00
|
|
|
isc_thread_t *threadp) {
|
1998-10-23 14:24:18 -04:00
|
|
|
isc_thread_t thread;
|
|
|
|
|
unsigned int id;
|
2021-02-16 09:57:39 -05:00
|
|
|
isc__trampoline_t *trampoline_arg;
|
|
|
|
|
|
|
|
|
|
trampoline_arg = isc__trampoline_get(start, arg);
|
1998-10-23 02:02:07 -04:00
|
|
|
|
2021-02-16 09:57:39 -05:00
|
|
|
thread = (isc_thread_t)_beginthreadex(NULL, 0, isc__trampoline_run,
|
|
|
|
|
trampoline_arg, 0, &id);
|
1998-10-23 14:24:18 -04:00
|
|
|
if (thread == NULL) {
|
2019-07-18 11:24:05 -04:00
|
|
|
char strbuf[ISC_STRERRORSIZE];
|
2019-07-18 11:47:40 -04:00
|
|
|
strerror_r(errno, strbuf, sizeof(strbuf));
|
2019-07-18 11:24:05 -04:00
|
|
|
isc_error_fatal(__FILE__, __LINE__, "_beginthreadex failed: %s",
|
|
|
|
|
strbuf);
|
1998-10-23 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
1998-10-23 14:24:18 -04:00
|
|
|
*threadp = thread;
|
1998-10-23 02:02:07 -04:00
|
|
|
|
2019-07-18 11:24:05 -04:00
|
|
|
return;
|
1998-10-23 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-18 11:47:40 -04:00
|
|
|
void
|
2020-02-14 00:35:17 -05:00
|
|
|
isc_thread_join(isc_thread_t thread, isc_threadresult_t *rp) {
|
1998-10-23 02:02:07 -04:00
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
|
|
result = WaitForSingleObject(thread, INFINITE);
|
|
|
|
|
if (result != WAIT_OBJECT_0) {
|
2019-07-18 11:47:40 -04:00
|
|
|
isc_error_fatal(__FILE__, __LINE__,
|
|
|
|
|
"WaitForSingleObject() != WAIT_OBJECT_0");
|
1998-10-23 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
if (rp != NULL && !GetExitCodeThread(thread, rp)) {
|
2019-07-18 11:47:40 -04:00
|
|
|
isc_error_fatal(__FILE__, __LINE__,
|
2020-02-12 09:33:32 -05:00
|
|
|
"GetExitCodeThread() failed: %d",
|
|
|
|
|
GetLastError());
|
1998-10-23 02:02:07 -04:00
|
|
|
}
|
1998-10-23 14:24:18 -04:00
|
|
|
(void)CloseHandle(thread);
|
1998-10-23 02:02:07 -04:00
|
|
|
}
|
2001-07-06 01:08:39 -04:00
|
|
|
|
|
|
|
|
void
|
2020-02-14 00:35:17 -05:00
|
|
|
isc_thread_setconcurrency(unsigned int level) {
|
2001-07-09 17:06:30 -04:00
|
|
|
/*
|
|
|
|
|
* This is unnecessary on Win32 systems, but is here so that the
|
|
|
|
|
* call exists
|
|
|
|
|
*/
|
2001-07-06 01:08:39 -04:00
|
|
|
}
|
2005-09-18 03:16:24 -04:00
|
|
|
|
2017-04-21 16:58:22 -04:00
|
|
|
void
|
2020-02-14 00:35:17 -05:00
|
|
|
isc_thread_setname(isc_thread_t thread, const char *name) {
|
2017-04-21 16:58:22 -04:00
|
|
|
UNUSED(thread);
|
|
|
|
|
UNUSED(name);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-03 17:20:22 -04:00
|
|
|
isc_result_t
|
2020-02-14 00:35:17 -05:00
|
|
|
isc_thread_setaffinity(int cpu) {
|
2018-10-03 17:20:22 -04:00
|
|
|
/* no-op on Windows for now */
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
}
|