blob: c1b9f9df355d2900ceef0779d510089f5473a1aa [file] [log] [blame]
Brian Paulc11371a1999-12-16 17:31:06 +00001/* $Id: glthread.h,v 1.1 1999/12/16 17:31:06 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28/*
29 * Thread support for gl dispatch.
30 *
31 * Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu)
32 * and Christoph Poliwoda (poliwoda@volumegraphics.com)
33 * Revised by Keith Whitwell
34 * Adapted for new gl dispatcher by Brian Paul
35 */
36
37
38
39/*
40 * If this file is accidentally included by a non-threaded build,
41 * it should not cause the build to fail, or otherwise cause problems.
42 * In general, it should only be included when needed however.
43 */
44#ifdef THREADS
45/*
46 * It is an error not to select a specific threads API when compiling.
47 */
48#if !defined(PTHREADS) && !defined(SOLARIS_THREADS) && !defined(WIN32)
49#error One of PTHREADS, SOLARIS_THREADS or WIN32 must be defined.
50#endif
51
52
53
54/*
55 * POSIX threads. This should be your choice in the Unix world
56 * whenever possible. When building with POSIX threads, be sure
57 * to enable any compiler flags which will cause the MT-safe
58 * libc (if one exists) to be used when linking, as well as any
59 * header macros for MT-safe errno, etc. For Solaris, this is the -mt
60 * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable
61 * proper compiling for MT-safe libc etc.
62 */
63#ifdef PTHREADS
64#include <pthread.h> /* POSIX threads headers */
65
66typedef struct {
67 pthread_key_t key;
68 pthread_once_t once;
69} _glthread_TSD;
70
71typedef pthread_mutex_t _glthread_Mutex;
72typedef pthread_t _glthread_Thread;
73
74#endif /* PTHREADS */
75
76
77
78
79/*
80 * Solaris threads. Use only up to Solaris 2.4.
81 * Solaris 2.5 and higher provide POSIX threads.
82 * Be sure to compile with -mt on the Solaris compilers, or
83 * use -D_REENTRANT if using gcc.
84 */
85#ifdef SOLARIS_THREADS
86#include <thread.h>
87
88typedef struct {
89 thread_key_t key;
90 mutex_t keylock;
91 int initfuncCalled;
92} _glthread_TSD;
93
94typedef mutex_t _glthread_Mutex;
95typedef thread_t _glthread_Thread;
96
97#endif /* SOLARIS_THREADS */
98
99
100
101
102/*
103 * Windows threads. Should work with Windows NT and 95.
104 * IMPORTANT: Link with multithreaded runtime library when THREADS are
105 * used!
106 */
107
108#ifdef WIN32
109#include <windows.h>
110
111typedef struct {
112 DWORD key;
113 int initfuncCalled;
114} _glthread_TSD;
115
116typedef CRITICAL_SECTION _glthread_Mutex;
117typedef HANDLE _glthread_Thread;
118
119#endif /* WIN32 */
120
121
122
123
124/*
125 * Platform independent thread specific data API.
126 */
127
128extern unsigned long
129_glthread_GetID(void);
130
131
132extern void
133_glthread_InitTSD(_glthread_TSD *);
134
135
136extern void *
137_glthread_GetTSD(_glthread_TSD *);
138
139
140extern void
141_glthread_SetTSD(_glthread_TSD *, void *, void (*initfunc)(void));
142
143
144
145#endif