1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Mesa 3-D graphics library 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Version: 6.5.2 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"), 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions: 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice shall be included 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * in all copies or substantial portions of the Software. 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Thread support for gl dispatch. 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu) 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and Christoph Poliwoda (poliwoda@volumegraphics.com) 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Revised by Keith Whitwell 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Adapted for new gl dispatcher by Brian Paul 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Modified for use in mapi by Chia-I Wu 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If this file is accidentally included by a non-threaded build, 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * it should not cause the build to fail, or otherwise cause problems. 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * In general, it should only be included when needed however. 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef _U_THREAD_H_ 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define _U_THREAD_H_ 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdio.h> 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdlib.h> 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "u_compiler.h" 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(HAVE_PTHREAD) 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <pthread.h> /* POSIX threads headers */ 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _WIN32 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <windows.h> 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(HAVE_PTHREAD) || defined(_WIN32) 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef THREADS 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define THREADS 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Error messages 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define INIT_TSD_ERROR "_glthread_: failed to allocate key for thread specific data" 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define GET_TSD_ERROR "_glthread_: failed to get thread specific data" 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define SET_TSD_ERROR "_glthread_: thread failed to set thread specific data" 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Magic number to determine if a TSD object has been initialized. 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Kind of a hack but there doesn't appear to be a better cross-platform 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * solution. 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define INIT_MAGIC 0xff8adc98 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __cplusplus 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern "C" { 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * POSIX threads. This should be your choice in the Unix world 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * whenever possible. When building with POSIX threads, be sure 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to enable any compiler flags which will cause the MT-safe 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * libc (if one exists) to be used when linking, as well as any 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * header macros for MT-safe errno, etc. For Solaris, this is the -mt 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * proper compiling for MT-safe libc etc. 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(HAVE_PTHREAD) 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct u_tsd { 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org pthread_key_t key; 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned initMagic; 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef pthread_mutex_t u_mutex; 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_declare_static(name) \ 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static u_mutex name = PTHREAD_MUTEX_INITIALIZER 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_init(name) pthread_mutex_init(&(name), NULL) 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_destroy(name) pthread_mutex_destroy(&(name)) 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_lock(name) (void) pthread_mutex_lock(&(name)) 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_unlock(name) (void) pthread_mutex_unlock(&(name)) 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE unsigned long 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_thread_self(void) 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return (unsigned long) pthread_self(); 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_init(struct u_tsd *tsd) 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) { 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org perror(INIT_TSD_ERROR); 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org exit(-1); 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org tsd->initMagic = INIT_MAGIC; 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void * 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_get(struct u_tsd *tsd) 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (tsd->initMagic != INIT_MAGIC) { 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org u_tsd_init(tsd); 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return pthread_getspecific(tsd->key); 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_set(struct u_tsd *tsd, void *ptr) 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (tsd->initMagic != INIT_MAGIC) { 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org u_tsd_init(tsd); 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (pthread_setspecific(tsd->key, ptr) != 0) { 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org perror(SET_TSD_ERROR); 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org exit(-1); 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* HAVE_PTHREAD */ 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Windows threads. Should work with Windows NT and 95. 153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPORTANT: Link with multithreaded runtime library when THREADS are 154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * used! 155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef WIN32 157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct u_tsd { 159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org DWORD key; 160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned initMagic; 161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef CRITICAL_SECTION u_mutex; 164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* http://locklessinc.com/articles/pthreads_on_windows/ */ 166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_declare_static(name) \ 167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static u_mutex name = {(PCRITICAL_SECTION_DEBUG)-1, -1, 0, 0, 0, 0} 168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_init(name) InitializeCriticalSection(&name) 170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_destroy(name) DeleteCriticalSection(&name) 171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_lock(name) EnterCriticalSection(&name) 172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_unlock(name) LeaveCriticalSection(&name) 173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE unsigned long 175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_thread_self(void) 176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return GetCurrentThreadId(); 178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void 182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_init(struct u_tsd *tsd) 183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org tsd->key = TlsAlloc(); 185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (tsd->key == TLS_OUT_OF_INDEXES) { 186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org perror(INIT_TSD_ERROR); 187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org exit(-1); 188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org tsd->initMagic = INIT_MAGIC; 190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void 194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_destroy(struct u_tsd *tsd) 195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (tsd->initMagic != INIT_MAGIC) { 197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return; 198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org TlsFree(tsd->key); 200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org tsd->initMagic = 0x0; 201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void * 205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_get(struct u_tsd *tsd) 206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (tsd->initMagic != INIT_MAGIC) { 208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org u_tsd_init(tsd); 209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return TlsGetValue(tsd->key); 211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void 215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_set(struct u_tsd *tsd, void *ptr) 216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* the following code assumes that the struct u_tsd has been initialized 218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org to zero at creation */ 219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (tsd->initMagic != INIT_MAGIC) { 220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org u_tsd_init(tsd); 221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (TlsSetValue(tsd->key, ptr) == 0) { 223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org perror(SET_TSD_ERROR); 224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org exit(-1); 225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* WIN32 */ 229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THREADS not defined 233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef THREADS 235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct u_tsd { 237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned initMagic; 238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef unsigned u_mutex; 241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_declare_static(name) static u_mutex name = 0 243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_init(name) (void) name 244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_destroy(name) (void) name 245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_lock(name) (void) name 246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define u_mutex_unlock(name) (void) name 247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * no-op functions 250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE unsigned long 253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_thread_self(void) 254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void 260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_init(struct u_tsd *tsd) 261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) tsd; 263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void * 267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_get(struct u_tsd *tsd) 268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) tsd; 270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return NULL; 271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void 275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgu_tsd_set(struct u_tsd *tsd, void *ptr) 276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) tsd; 278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) ptr; 279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* THREADS */ 281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __cplusplus 284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* _U_THREAD_H_ */ 288