Changeset 2346
- Timestamp:
- Mar 27, 2019, 11:42:32 PM (6 years ago)
- Location:
- pthread/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified pthread/trunk/src/my_os2key.c ¶
r1234 r2346 24 24 #include <os2emx.h> 25 25 26 #include <stdlib.h> 27 26 28 #include "pthread.h" 27 29 #include "tls.h" 28 30 31 struct pthread_key_pair_t_ 32 { 33 pthread_key_t key; 34 void (*destructor)(void*); 35 struct pthread_key_pair_t_ *next; 36 }; 37 38 typedef struct pthread_key_pair_t_ * pthread_key_pair_t; 39 40 static pthread_key_pair_t pair_start = NULL; 41 29 42 int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)) 30 43 { 44 pthread_key_pair_t new_pair; 45 46 new_pair = calloc(1, sizeof(*new_pair)); 47 if (new_pair == NULL) { 48 errno = ENOMEM; 49 return -1; 50 } 31 51 32 52 if ((*(ULONG *)key = TlsAlloc()) != -1) 53 { 54 new_pair->key = *key; 55 new_pair->destructor = destructor; 56 new_pair->next = pair_start; 57 58 pair_start = new_pair; 59 33 60 return 0; 61 } 62 63 free(new_pair); 64 34 65 errno = EAGAIN; 35 66 return -1; … … 38 69 int pthread_key_delete(pthread_key_t key) 39 70 { 71 pthread_key_pair_t prev = NULL; 72 pthread_key_pair_t pair; 73 74 for (pair = pair_start; pair != NULL; pair = pair->next) { 75 if (pair->key == key) { 76 if (pair == pair_start) 77 pair_start = pair->next; 78 else 79 prev->next = pair->next; 80 81 free(pair); 82 break; 83 } 84 85 prev = pair; 86 } 87 40 88 if (TlsFree((ULONG)key)) 41 89 return 0; … … 57 105 } 58 106 107 void pthread_key_destructor(void) 108 { 109 pthread_key_pair_t pair; 110 111 for (pair = pair_start; pair != NULL; pair = pair->next) { 112 void *value = pthread_getspecific(pair->key); 113 114 if (value != NULL && pair->destructor != NULL) { 115 pthread_setspecific(pair->key, NULL); 116 pair->destructor(value); 117 } 118 } 119 } -
TabularUnified pthread/trunk/src/my_os2thread.c ¶
r2345 r2346 189 189 pthread_setspecific(THR_self, NULL); 190 190 } 191 192 // call all available destructors associated with all keys 193 pthread_key_destructor(); 191 194 192 195 // thread is joinable, pthread_join is supposed to be called from main thread -
TabularUnified pthread/trunk/src/pthread_private.h ¶
r2332 r2346 87 87 }; 88 88 89 void pthread_key_destructor(void); 90 89 91 #ifdef __cplusplus 90 92 } // extern "C"
Note:
See TracChangeset
for help on using the changeset viewer.