summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpj <rpj>1998-10-14 19:51:06 +0000
committerrpj <rpj>1998-10-14 19:51:06 +0000
commit424ca52423ca124e4618e0e7a0dba22ea989ef09 (patch)
treeb63bdf933f381923fe99a09177c4acd07496f5bb
parent8c4d7f6bc1d365906724c92e4143fa021bf8a757 (diff)
Thu Oct 15 11:53:21 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* global.c (_pthread_tsd_key_table): Fix declaration. * implement.h(_pthread_TSD_keys_TlsIndex): Add missing extern. (_pthread_tsd_mutex): Ditto. * create.c (_pthread_start_call): Fix "keys" array declaration. Add comment. * tsd.c (pthread_setspecific): Fix type declaration and cast. (pthread_getspecific): Ditto. * cleanup.c (_pthread_destructor_run_all): Declare missing loop counter.
-rw-r--r--ChangeLog16
-rw-r--r--cleanup.c19
-rw-r--r--create.c7
-rw-r--r--global.c14
-rw-r--r--implement.h11
-rw-r--r--pthread.h2
-rw-r--r--tsd.c8
7 files changed, 56 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 6219728..db0d9ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Thu Oct 15 11:53:21 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
+
+ * global.c (_pthread_tsd_key_table): Fix declaration.
+
+ * implement.h(_pthread_TSD_keys_TlsIndex): Add missing extern.
+ (_pthread_tsd_mutex): Ditto.
+
+ * create.c (_pthread_start_call): Fix "keys" array declaration.
+ Add comment.
+
+ * tsd.c (pthread_setspecific): Fix type declaration and cast.
+ (pthread_getspecific): Ditto.
+
+ * cleanup.c (_pthread_destructor_run_all): Declare missing loop
+ counter.
+
Wed Oct 14 21:09:24 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* private.c (_pthread_new_thread): Increment _pthread_threads_count.
diff --git a/cleanup.c b/cleanup.c
index c956ce7..936e6e1 100644
--- a/cleanup.c
+++ b/cleanup.c
@@ -125,31 +125,34 @@ _pthread_handler_pop_all(int stack, int execute)
void
_pthread_destructor_run_all()
{
- _pthread_tsd_key_t * k;
+ _pthread_tsd_key_t * key;
void * arg;
int count;
- k = _pthread_tsd_key_table;
+ /* This threads private keys */
+ key = _pthread_tsd_key_table;
/* Stop destructor execution at a finite time. POSIX allows us
to ignore this if we like, even at the risk of an infinite loop.
*/
for (count = 0; count < PTHREAD_DESTRUCTOR_ITERATIONS; count++)
{
+ int k;
+
/* Loop through all keys. */
- for (key = 0; key < _POSIX_THREAD_KEYS_MAX; key++)
+ for (k = 0; k < _POSIX_THREAD_KEYS_MAX; k++)
{
- if (k->in_use != 1)
+ if (key->in_use != _PTHREAD_TSD_KEY_INUSE)
continue;
- arg = pthread_getspecific(key);
+ arg = pthread_getspecific((pthread_key_t) k);
- if (arg != NULL && k->destructor != NULL)
+ if (arg != NULL && key->destructor != NULL)
{
- (void) (k->destructor)(arg);
+ (void) (key->destructor)(arg);
}
- k++;
+ key++;
}
}
}
diff --git a/create.c b/create.c
index a0b8d02..6119198 100644
--- a/create.c
+++ b/create.c
@@ -22,7 +22,12 @@ STDCALL _pthread_start_call(void * us_arg)
this thread's private stack so we're safe to leave data in them
until we leave. */
pthread_t us;
- void * keys[PTHREAD_KEYS_MAX];
+
+ /* FIXME: Needs to be a malloc(PTHREAD_KEYS_MAX) otherwise changing
+ _PTHREAD_MAX_KEYS in a later version of the DLL will break older apps.
+ */
+ void * keys[_PTHREAD_MAX_KEYS];
+
unsigned (*func)(void *);
void * arg;
unsigned ret;
diff --git a/global.c b/global.c
index ee6de82..3bd3b4e 100644
--- a/global.c
+++ b/global.c
@@ -11,13 +11,17 @@
#include "pthread.h"
#include "implement.h"
-/* Making these constants will mean that applications remain binary
- compatible between versions of the DLL. */
+/* POSIX run-time invariant values. (Currently POSIX minimum values)
+
+ Making these constants will mean that applications remain binary
+ compatible between versions of the DLL.
+
+ FIXME: There are still places in the package that break this.
+*/
-/* POSIX run-time invariant values. (Currently POSIX minimum values) */
const int _POSIX_THREAD_THREADS_MAX = _PTHREAD_MAX_THREADS;
const int _POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4;
-const int _POSIX_THREAD_KEYS_MAX = 128;
+const int _POSIX_THREAD_KEYS_MAX = _PTHREAD_MAX_KEYS;
const int _pthread_create_joinable = 0;
@@ -58,7 +62,7 @@ pthread_t _pthread_win32handle_map[_PTHREAD_MAX_THREADS];
pthread_mutex_t _pthread_threads_mutex_table[_PTHREAD_MAX_THREADS];
/* Global TSD key array. */
-_pthread_tsd_key_t _pthread_tsd_key_table[_POSIX_THREAD_KEYS_MAX];
+_pthread_tsd_key_t _pthread_tsd_key_table[_PTHREAD_MAX_KEYS];
/* Mutex lock for TSD operations */
pthread_mutex_t _pthread_tsd_mutex = PTHREAD_MUTEX_INITIALIZER;
diff --git a/implement.h b/implement.h
index a87edb2..135fc18 100644
--- a/implement.h
+++ b/implement.h
@@ -9,6 +9,7 @@
/* Use internally to initialise const ints and thread admin array sizes. */
#define _PTHREAD_MAX_THREADS 128
+#define _PTHREAD_MAX_KEYS 128
#define _PTHREAD_HASH_INDEX(x) (((ULONG) x) % PTHREAD_THREADS_MAX)
@@ -142,6 +143,8 @@ void _pthread_exit(pthread_t thread, void * value, int return_code);
extern DWORD _pthread_threadID_TlsIndex;
+extern DWORD _pthread_TSD_keys_TlsIndex;
+
/* Global data declared in global.c */
@@ -171,8 +174,10 @@ extern pthread_mutex_t _pthread_threads_mutex_table[];
/* Global TSD key array. */
extern _pthread_tsd_key_t _pthread_tsd_key_table[];
-#endif /* _IMPLEMENT_H */
-
-
+/* Mutex lock for TSD operations */
+extern pthread_mutex_t _pthread_tsd_mutex;
+/* Index to the next available TSD key. */
+extern int _pthread_tsd_key_next;
+#endif /* _IMPLEMENT_H */
diff --git a/pthread.h b/pthread.h
index b678c68..ef22d80 100644
--- a/pthread.h
+++ b/pthread.h
@@ -82,6 +82,8 @@ typedef struct {
int valid;
CRITICAL_SECTION cs;
} pthread_mutex_t;
+
+
typedef DWORD pthread_key_t;
diff --git a/tsd.c b/tsd.c
index 7b801db..87a2268 100644
--- a/tsd.c
+++ b/tsd.c
@@ -81,7 +81,7 @@ pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
int
pthread_setspecific(pthread_key_t key, void *value)
{
- void ** keys;
+ LPVOID keys;
int inuse;
/* CRITICAL SECTION */
@@ -95,7 +95,7 @@ pthread_setspecific(pthread_key_t key, void *value)
if (! inuse)
return EINVAL;
- keys = (void **) TlsGetValue(_pthread_TSD_keys_TlsIndex);
+ keys = TlsGetValue(_pthread_TSD_keys_TlsIndex);
keys[key] = value;
return 0;
@@ -104,7 +104,7 @@ pthread_setspecific(pthread_key_t key, void *value)
void *
pthread_getspecific(pthread_key_t key)
{
- void ** keys;
+ LPVOID keys;
int inuse;
/* CRITICAL SECTION */
@@ -118,7 +118,7 @@ pthread_getspecific(pthread_key_t key)
if (! inuse)
return EINVAL;
- keys = (void **) TlsGetValue(_pthread_TSD_keys_TlsIndex);
+ keys = TlsGetValue(_pthread_TSD_keys_TlsIndex);
return keys[key];
}