1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
1ca2cf024391992fe14b2df7d3ae0f575d074452Evan Hunt * Copyright (C) 1998-2001, 2004, 2005, 2007, 2016, 2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley#include <config.h>
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
e904ee6c5289d59c3a8d84a354d97026a6688f19David Lawrence#include <process.h>
e904ee6c5289d59c3a8d84a354d97026a6688f19David Lawrence
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley#include <isc/thread.h>
6cb83898777f525b53ff73f744b4d3d7ff16ae78Evan Hunt#include <isc/util.h>
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halleyisc_result_t
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrenceisc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg,
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson isc_thread_t *threadp)
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson{
1eda5e1a7ce97ea997f2cfbaaf6bee1da5ea0e7eBob Halley isc_thread_t thread;
1eda5e1a7ce97ea997f2cfbaaf6bee1da5ea0e7eBob Halley unsigned int id;
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
1eda5e1a7ce97ea997f2cfbaaf6bee1da5ea0e7eBob Halley thread = (isc_thread_t)_beginthreadex(NULL, 0, start, arg, 0, &id);
1eda5e1a7ce97ea997f2cfbaaf6bee1da5ea0e7eBob Halley if (thread == NULL) {
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley /* XXX */
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley return (ISC_R_UNEXPECTED);
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley }
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
1eda5e1a7ce97ea997f2cfbaaf6bee1da5ea0e7eBob Halley *threadp = thread;
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley return (ISC_R_SUCCESS);
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley}
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halleyisc_result_t
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halleyisc_thread_join(isc_thread_t thread, isc_threadresult_t *rp) {
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley DWORD result;
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley result = WaitForSingleObject(thread, INFINITE);
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley if (result != WAIT_OBJECT_0) {
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley /* XXX */
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley return (ISC_R_UNEXPECTED);
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley }
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley if (rp != NULL && !GetExitCodeThread(thread, rp)) {
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley /* XXX */
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley return (ISC_R_UNEXPECTED);
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley }
1eda5e1a7ce97ea997f2cfbaaf6bee1da5ea0e7eBob Halley (void)CloseHandle(thread);
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley return (ISC_R_SUCCESS);
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley}
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayervoid
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayerisc_thread_setconcurrency(unsigned int level) {
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson /*
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson * This is unnecessary on Win32 systems, but is here so that the
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson * call exists
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson */
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer}
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews
8b9c4592ed718c4187971f1104381faf538bf4f7Evan Huntvoid
8b9c4592ed718c4187971f1104381faf538bf4f7Evan Huntisc_thread_setname(isc_thread_t thread, const char *name) {
8b9c4592ed718c4187971f1104381faf538bf4f7Evan Hunt UNUSED(thread);
8b9c4592ed718c4187971f1104381faf538bf4f7Evan Hunt UNUSED(name);
8b9c4592ed718c4187971f1104381faf538bf4f7Evan Hunt}
8b9c4592ed718c4187971f1104381faf538bf4f7Evan Hunt
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrewsvoid *
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrewsisc_thread_key_getspecific(isc_thread_key_t key) {
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews return(TlsGetValue(key));
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews}
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrewsint
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrewsisc_thread_key_setspecific(isc_thread_key_t key, void *value) {
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews return (TlsSetValue(key, value) ? 0 : GetLastError());
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews}
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrewsint
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrewsisc_thread_key_create(isc_thread_key_t *key, void (*func)(void *)) {
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews *key = TlsAlloc();
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews return ((*key != -1) ? 0 : GetLastError());
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews}
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrewsint
3a8be17fbfc66da458ebad9c5fbae16abaf09ee4Mark Andrewsisc_thread_key_delete(isc_thread_key_t key) {
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews return (TlsFree(key) ? 0 : GetLastError());
ed6ca94ad75353d5344e2a456e7a8beb480a351fMark Andrews}