"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/isc/win32/thread.c" (7 Sep 2020, 1883 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "thread.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #include <config.h>
   13 
   14 #include <process.h>
   15 
   16 #include <isc/thread.h>
   17 #include <isc/util.h>
   18 
   19 isc_result_t
   20 isc_thread_create(isc_threadfunc_t start, isc_threadarg_t arg,
   21           isc_thread_t *threadp)
   22 {
   23     isc_thread_t thread;
   24     unsigned int id;
   25 
   26     thread = (isc_thread_t)_beginthreadex(NULL, 0, start, arg, 0, &id);
   27     if (thread == NULL) {
   28         /* XXX */
   29         return (ISC_R_UNEXPECTED);
   30     }
   31 
   32     *threadp = thread;
   33 
   34     return (ISC_R_SUCCESS);
   35 }
   36 
   37 isc_result_t
   38 isc_thread_join(isc_thread_t thread, isc_threadresult_t *rp) {
   39     DWORD result;
   40 
   41     result = WaitForSingleObject(thread, INFINITE);
   42     if (result != WAIT_OBJECT_0) {
   43         /* XXX */
   44         return (ISC_R_UNEXPECTED);
   45     }
   46     if (rp != NULL && !GetExitCodeThread(thread, rp)) {
   47         /* XXX */
   48         return (ISC_R_UNEXPECTED);
   49     }
   50     (void)CloseHandle(thread);
   51 
   52     return (ISC_R_SUCCESS);
   53 }
   54 
   55 void
   56 isc_thread_setconcurrency(unsigned int level) {
   57     /*
   58      * This is unnecessary on Win32 systems, but is here so that the
   59      * call exists
   60      */
   61 }
   62 
   63 void
   64 isc_thread_setname(isc_thread_t thread, const char *name) {
   65     UNUSED(thread);
   66     UNUSED(name);
   67 }
   68 
   69 void *
   70 isc_thread_key_getspecific(isc_thread_key_t key) {
   71     return(TlsGetValue(key));
   72 }
   73 
   74 int
   75 isc_thread_key_setspecific(isc_thread_key_t key, void *value) {
   76     return (TlsSetValue(key, value) ? 0 : GetLastError());
   77 }
   78 
   79 int
   80 isc_thread_key_create(isc_thread_key_t *key, void (*func)(void *)) {
   81     *key = TlsAlloc();
   82 
   83     return ((*key != -1) ? 0 : GetLastError());
   84 }
   85 
   86 int
   87 isc_thread_key_delete(isc_thread_key_t key) {
   88     return (TlsFree(key) ? 0 : GetLastError());
   89 }