summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpj <rpj>1998-10-29 20:58:36 +0000
committerrpj <rpj>1998-10-29 20:58:36 +0000
commite0b68aae21da8697ef0f4f3924ea29edb0e89582 (patch)
treef5fe9666d832692241b88d35da3a9e292102c3a5
parente0cb3da9bad150b424848b993bb100766d07ded7 (diff)
Fri Oct 30 15:15:50 1998 Ross Johnson <rpj@swan.canberra.edu.au>
* cleanup.c (_pthread_handler_push): Fixed bug appending new handler to list reported by Peter Slacik <Peter.Slacik@leibinger.freinet.de>. (new_thread): Rename poorly named local variable to "new_handler".
-rw-r--r--ChangeLog13
-rw-r--r--cleanup.c40
-rw-r--r--tests/ChangeLog4
-rw-r--r--tests/tsd1.c35
4 files changed, 69 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 8e006b0..de62025 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,21 @@
+Fri Oct 30 15:15:50 1998 Ross Johnson <rpj@swan.canberra.edu.au>
+
+ * cleanup.c (_pthread_handler_push): Fixed bug appending new
+ handler to list reported by Peter Slacik
+ <Peter.Slacik@leibinger.freinet.de>.
+ (new_thread): Rename poorly named local variable to
+ "new_handler".
+
Thu Oct 22 21:44:44 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* tsd.c: Add description of pthread_key_delete() from the
standard as a comment.
+Fri Oct 16 17:38:47 1998 Ross Johnson <rpj@swan.canberra.edu.au>
+
+ * cleanup.c (_pthread_destructor_run_all): Fix and improve
+ stepping through the key table.
+
Thu Oct 15 14:05:01 1998 Ross Johnson <rpj@swan.canberra.edu.au>
* private.c (_pthread_new_thread): Remove init of destructorstack.
diff --git a/cleanup.c b/cleanup.c
index 936e6e1..1eac9f3 100644
--- a/cleanup.c
+++ b/cleanup.c
@@ -20,48 +20,48 @@ _pthread_handler_push(int stack,
{
/* Place the new handler into the list so that handlers are
popped off in the order given by poporder. */
- _pthread_handler_node_t * new_thread;
+ _pthread_handler_node_t * new_handler;
_pthread_handler_node_t * next;
_pthread_handler_node_t ** stacktop;
stacktop = _PTHREAD_STACK(stack);
- new_thread =
+ new_handler =
(_pthread_handler_node_t *) malloc(sizeof(_pthread_handler_node_t));
- if (new_thread == NULL)
+ if (new_handler == NULL)
{
return 0; /* NOMEM */
}
- new_thread->routine = routine;
- new_thread->arg = arg;
+ new_handler->routine = routine;
+ new_handler->arg = arg;
if (poporder == _PTHREAD_HANDLER_POP_LIFO)
{
/* Add the new node to the start of the list. */
- new_thread->next = *stacktop;
- *stacktop = next;
+ new_handler->next = *stacktop;
+ *stacktop = new_handler;
}
else
{
/* Add the new node to the end of the list. */
- new_thread->next = NULL;
+ new_handler->next = NULL;
if (*stacktop == NULL)
{
- *stacktop = new_thread;
+ *stacktop = new_handler;
}
else
{
next = *stacktop;
- while (next != NULL)
+ while (next->next != NULL)
{
next = next->next;
}
- next = new_thread;
+ next->next = new_handler;
}
}
return 0;
@@ -126,7 +126,6 @@ void
_pthread_destructor_run_all()
{
_pthread_tsd_key_t * key;
- void * arg;
int count;
/* This threads private keys */
@@ -134,6 +133,8 @@ _pthread_destructor_run_all()
/* Stop destructor execution at a finite time. POSIX allows us
to ignore this if we like, even at the risk of an infinite loop.
+
+ FIXME: We don't know when to stop yet.
*/
for (count = 0; count < PTHREAD_DESTRUCTOR_ITERATIONS; count++)
{
@@ -142,14 +143,17 @@ _pthread_destructor_run_all()
/* Loop through all keys. */
for (k = 0; k < _POSIX_THREAD_KEYS_MAX; k++)
{
- if (key->in_use != _PTHREAD_TSD_KEY_INUSE)
- continue;
+ /* If there's no destructor or the key isn't in use, skip it. */
+ if (key->destructor != NULL && key->in_use == _PTHREAD_TSD_KEY_INUSE)
+ {
+ void * arg;
- arg = pthread_getspecific((pthread_key_t) k);
+ arg = pthread_getspecific((pthread_key_t) k);
- if (arg != NULL && key->destructor != NULL)
- {
- (void) (key->destructor)(arg);
+ if (arg != NULL)
+ {
+ (void) (key->destructor)(arg);
+ }
}
key++;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 6217b28..a634f87 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+Fri Oct 16 17:59:49 1998 Ross Johnson <rpj@swan.canberra.edu.au>
+
+ * tsd1.c (destroy_key): Add function. Change diagnostics.
+
Thu Oct 15 17:42:37 1998 Ross Johnson <rpj@swan.canberra.edu.au>
* tsd1.c (mythread): Fix some casts and add some message
diff --git a/tests/tsd1.c b/tests/tsd1.c
index 06ffab5..aa2d3da 100644
--- a/tests/tsd1.c
+++ b/tests/tsd1.c
@@ -5,9 +5,21 @@ pthread_key_t key;
pthread_once_t key_once = PTHREAD_ONCE_INIT;
void
+destroy_key(void * arg)
+{
+ /* arg is not NULL if we get to here. */
+ printf("SUCCESS: %s: destroying key.\n", (char *) arg);
+
+ free((char *) arg);
+
+ /* Is it our responsibility to do this? */
+ arg = NULL;
+}
+
+void
make_key(void)
{
- if (pthread_key_create(&key, free) != 0)
+ if (pthread_key_create(&key, destroy_key) != 0)
{
printf("Key create failed\n");
exit(1);
@@ -31,18 +43,31 @@ mythread(void * arg)
else
{
ptr = (void *) malloc(80);
- sprintf((char *) ptr, "Thread %d Key 0x%x succeeded\n",
+ sprintf((char *) ptr, "Thread %d Key 0x%x",
(int) arg,
(int) key);
(void) pthread_setspecific(key, ptr);
}
- if ((ptr = pthread_getspecific(key)) != NULL)
- printf((char *) ptr);
+ if ((ptr = pthread_getspecific(key)) == NULL)
+ {
+ printf("FAILED: Thread %d Key 0x%x: key value set or get failed.\n",
+ (int) arg,
+ (int) key);
+ exit(1);
+ }
else
- printf("Failed %d\n", (int) arg);
+ {
+ printf("SUCCESS: Thread %d Key 0x%x: key value set and get succeeded.\n",
+ (int) arg,
+ (int) key);
+
+ printf("SUCCESS: %s: exiting thread.\n", (char *) ptr);
+ }
return 0;
+
+ /* Exiting the thread will call the key destructor. */
}
int