summaryrefslogtreecommitdiff
path: root/tsd.c
diff options
context:
space:
mode:
authorrpj <rpj>1998-12-06 04:42:29 +0000
committerrpj <rpj>1998-12-06 04:42:29 +0000
commita7d47499d89932fa74932fef5af9b046227788de (patch)
tree986bad2b5ee7b52cabff02d0620980315ed6c8b1 /tsd.c
parente17bb90f17f0530bc74a3e463b8ea9eedfaae01f (diff)
Sun Dec 6 21:54:35 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* buildlib.bat: Fix args to CL when building the .DLL * cleanup.c (_pthread_destructor_run_all): Fix TSD key management. This is a tidy-up before TSD and Thread management is completely replaced by John Bossom's much more elegant code. * tsd.c (pthread_key_create): Fix TSD key management. * global.c (_pthread_key_virgin_next): Initialise. * build.bat: New DOS script to compile and link a pthreads app using Microsoft's CL compiler linker. * buildlib.bat: New DOS script to compile all the object files and create pthread.lib and pthread.dll using Microsoft's CL compiler linker.
Diffstat (limited to 'tsd.c')
-rw-r--r--tsd.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/tsd.c b/tsd.c
index 9d489d9..cc0b98e 100644
--- a/tsd.c
+++ b/tsd.c
@@ -62,14 +62,26 @@ pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
/* CRITICAL SECTION */
pthread_mutex_lock(&_pthread_tsd_mutex);
- if (_pthread_key_virgin_next >= PTHREAD_KEYS_MAX)
- ret = EAGAIN;
+ if (_pthread_key_reuse_top >= 0)
+ {
+ k = _pthread_key_reuse[_pthread_key_reuse_top--];
+ }
+ else
+ {
+ if (_pthread_key_virgin_next < PTHREAD_KEYS_MAX)
+ {
+ k = _pthread_key_virgins[_pthread_key_virgin_next++];
+ }
+ else
+ {
+ return EAGAIN;
+ }
+ }
/* FIXME: This needs to be implemented as a list plus a re-use stack as for
thread IDs. _pthread_destructor_run_all() then needs to be changed
to push keys onto the re-use stack.
*/
- k = _pthread_key_virgin_next++;
_pthread_tsd_key_table[k].in_use = 0;
_pthread_tsd_key_table[k].status = _PTHREAD_TSD_KEY_INUSE;