Changeset 1404
- Timestamp:
- Apr 29, 2004, 6:33:48 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gcc/gcc/gthr-os2.h
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1403 r1404 30 30 #define __gthr_os2_h 31 31 32 /* The __MT__ symbol should be defined for multiple threads (-Zmt) */ 33 #ifdef __MT__ 32 #ifdef _LIBOBJC 33 #error "gthr-os2.h doesn't implement the _LIBOBJC mode!" 34 #endif 34 35 35 36 #define __GTHREADS 1 … … 41 42 #include <malloc.h> 42 43 #include <stdlib.h> 44 #include <errno.h> 45 #include <InnoTekLIBC/thread.h> 43 46 44 typedef struct 45 { 46 void *thread_data; 47 void (*thread_dtor) (void *); 48 } __gthread_key_struct_t; 49 50 typedef __gthread_key_struct_t *__gthread_key_t; 47 typedef int __gthread_key_t; 51 48 typedef volatile signed char __gthread_once_t; 52 49 typedef _fmutex __gthread_mutex_t; … … 64 61 __gthread_once (__gthread_once_t *once, void (*func) (void)) 65 62 { 63 if (once == NULL || func == NULL) 64 return EINVAL; 66 65 if (__cxchg (once, 1) == 0) 67 66 func (); … … 93 92 } 94 93 95 #ifdef __cplusplus96 # define EXTERN_C extern "C"97 #else98 # define EXTERN_C extern99 #endif100 101 /** r=bird: We really should make a set of TLS functions for this stuff as102 * the thread local memory is a very limited resource.103 */104 /* rather than including os2.h we'll define the prototype here... */105 EXTERN_C unsigned long _System DosAllocThreadLocalMemory (unsigned long dwords,106 unsigned long **ptr);107 EXTERN_C unsigned long _System DosFreeThreadLocalMemory (unsigned long *ptr);108 109 #undef EXTERN_C110 111 /* @@@BUG: dtor is NEVER called when the thread exits; todo: modify EMX112 libc so that we have separate storage in current thread structure and113 _endthread() calls all the destructors we assign here... */114 94 static inline int 115 95 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *)) 116 96 { 117 if (DosAllocThreadLocalMemory ((sizeof (__gthread_key_struct_t) + 3)/4, 118 (unsigned long **)key)) 119 return -1; 120 121 (*key)->thread_data = NULL; 122 (*key)->thread_dtor = dtor; 123 return 0; 97 int iTLS = __libc_TLSAlloc(); 98 if (iTLS < 0) 99 return errno; 100 __libc_TLSDestructor(iTLS, (void (*)(void *, int, unsigned))dtor, 0); 101 *key = iTLS; 102 return 0; 124 103 } 125 104 … … 127 106 __gthread_key_dtor (__gthread_key_t key, void *ptr) 128 107 { 129 key->thread_dtor (ptr); 130 key->thread_dtor = NULL; 131 return 0; 108 void (*pfnDestructor)(void *pvValue, int iTLSIndex, unsigned fFlags) = __libc_TLSGetDestructor(key, NULL); 109 if (pfnDestructor) 110 { 111 pfnDestructor(ptr, key, 0); 112 __libc_TLSSet(key, NULL); 113 } 114 return 0; 132 115 } 133 116 … … 135 118 __gthread_key_delete (__gthread_key_t key) 136 119 { 137 return DosFreeThreadLocalMemory ((unsigned long *)key); 120 if (__libc_TLSFree(key)) 121 return errno; 122 return 0; 138 123 } 139 124 … … 141 126 __gthread_getspecific (__gthread_key_t key) 142 127 { 143 return key->thread_data;128 return __libc_TLSGet(key); 144 129 } 145 130 … … 147 132 __gthread_setspecific (__gthread_key_t key, const void *ptr) 148 133 { 149 key->thread_data = (void *)ptr; 150 return 0; 134 if (__libc_TLSSet(key, (void *)ptr)) 135 return errno; 136 return 0; 151 137 } 152 138 153 #else /* __MT__ */154 155 #include "gthr-single.h"156 157 #endif /* __MT__ */158 159 139 #endif /* not __gthr_os2_h */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.