source: trunk/src/opengl/mesa/mthreads.h@ 3582

Last change on this file since 3582 was 2970, checked in by sandervl, 25 years ago

Reapplied TLS fixes

File size: 4.7 KB
Line 
1/* $Id: mthreads.h,v 1.2 2000-03-02 13:27:30 sandervl Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
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
30/*
31 * mthreads.h -- platform dependent thread support for Mesa
32 *
33 * Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu)
34 * and Christoph Poliwoda (poliwoda@volumegraphics.com)
35 *
36 * Revised by Keith Whitwell
37 */
38
39
40
41/*
42 * If this file is accidentally included by a non-threaded build,
43 * it should not cause the build to fail, or otherwise cause problems.
44 * In general, it should only be included when needed however.
45 */
46#ifdef THREADS
47/*
48 * It is an error not to select a specific threads API when compiling.
49 */
50#if !defined PTHREADS && !defined SOLARIS_THREADS && !defined WIN32 && !defined(__WIN32OS2__)
51#error One of PTHREADS, SOLARIS_THREADS, WIN32 or __WIN32OS2__ must be defined.
52#endif
53
54
55/*
56 * Error messages which should be printed when our Mesa thread APIs fail
57 * for one reason or another.
58 */
59#define MESA_INIT_TSD_ERROR "Mesa: thread failed to allocate key for thread specific data"
60#define MESA_GET_TSD_ERROR "Mesa: thread failed to get thread specific data"
61#define MESA_SET_TSD_ERROR "Mesa: thread failed to set thread specific data"
62
63
64/*
65 * magic number for win32 and solaris threads equivalents of pthread_once
66 * This could probably be done better, but we haven't figured out how yet.
67 */
68#define INITFUNC_CALLED_MAGIC 0xff8adc98
69
70
71
72
73/*
74 * POSIX threads. This should be your choice in the Unix world
75 * whenever possible. When building with POSIX threads, be sure
76 * to any able any compiler flags which will cause the MT-safe
77 * libc (if one exists) to be used when linking, as well as any
78 * header macros for MT-safe errno, etc. For Solaris, this is the -mt
79 * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable
80 * proper compiling for MT-safe libc etc.
81 */
82#ifdef PTHREADS
83#include <pthread.h> /* POSIX threads headers */
84
85typedef struct {
86 pthread_key_t key;
87 pthread_once_t once;
88} MesaTSD;
89
90typedef pthread_mutex_t MesaMutex;
91typedef pthread_t MesaThread;
92
93#endif /* PTHREADS */
94
95
96
97
98/*
99 * Solaris threads. Use only up to Solaris 2.4.
100 * Solaris 2.5 and higher provide POSIX threads.
101 * Be sure to compile with -mt on the Solaris compilers, or
102 * use -D_REENTRANT if using gcc.
103 */
104#ifdef SOLARIS_THREADS
105#include <thread.h>
106
107typedef struct {
108 thread_key_t key;
109 mutex_t keylock;
110 int initfuncCalled;
111} MesaTSD;
112
113typedef mutex_t MesaMutex;
114typedef thread_t MesaThread;
115
116#endif /* SOLARIS_THREADS */
117
118
119
120
121/*
122 * Windows threads. Should work with Windows NT and 95.
123 * IMPORTANT: Link with multithreaded runtime library when THREADS are
124 * used!
125 */
126
127#if defined(WIN32) || defined(__WIN32OS2__)
128
129#include <windows.h>
130
131typedef struct {
132 DWORD key;
133 int initfuncCalled;
134} MesaTSD;
135
136typedef CRITICAL_SECTION MesaMutex;
137typedef HANDLE MesaThread;
138
139#endif /* WIN32 */
140
141
142
143
144/*
145 * Platform independent thread specific data API.
146 */
147void MesaInitTSD(MesaTSD *);
148
149#ifdef __WIN32OS2__
150void *MesaGetTSD (MesaTSD * tsd, void (*initfunc)(void)) ;
151#else
152void* MesaGetTSD (MesaTSD *);
153#endif
154void MesaSetTSD (MesaTSD *, void *, void (*initfunc)(void));
155
156
157/*
158 * The following APIs are preliminary. They may be needed in
159 * future versions of Mesa.
160 */
161#if 0
162
163/*
164 * Platform independent mutual exclusion lock API.
165 */
166void MesaInitMutex (MesaMutex *);
167void MesaDestroyMutex (MesaMutex *);
168void MesaLockMutex (MesaMutex *);
169void MesaUnlockMutex (MesaMutex *);
170
171/*
172 * Platform independent thread management API.
173 */
174MesaThread MesaCreateThread ((void*)(*)(void*), void*);
175void MesaJoinThread (MesaThread);
176
177#endif
178
179#endif /* THREADS */
Note: See TracBrowser for help on using the repository browser.