about summary refs log tree commit diff
path: root/htl/pt-internal.h
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2022-01-22 00:12:05 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-01-22 02:17:19 +0100
commit8c86ba446367fd676457e51eb44d7af2e5d9a392 (patch)
tree110b0549f3a5708a1b27714d752fa1551e465f70 /htl/pt-internal.h
parente22a4557eb39d7cba9a74d70f4582c13f1a7a83a (diff)
downloadglibc-8c86ba446367fd676457e51eb44d7af2e5d9a392.tar.gz
glibc-8c86ba446367fd676457e51eb44d7af2e5d9a392.tar.xz
glibc-8c86ba446367fd676457e51eb44d7af2e5d9a392.zip
htl: Fix cleaning the reply port
If any RPC fails, the reply port will already be deallocated.
__pthread_thread_terminate thus has to defer taking its name until the very last
__thread_terminate_release which doesn't reply a message.  But then we
have to read from the pthread structure.

This introduces __pthread_dealloc_finish() which does the recording of
the thread termination, so the slot can be reused really only just before
the __thread_terminate_release call. Only the real thread can set it, so
let's decouple this from the pthread_state by just removing the
PTHREAD_TERMINATED state and add a terminated field.
Diffstat (limited to 'htl/pt-internal.h')
-rw-r--r--htl/pt-internal.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/htl/pt-internal.h b/htl/pt-internal.h
index 738efd5c6f..f01cb7ceb2 100644
--- a/htl/pt-internal.h
+++ b/htl/pt-internal.h
@@ -48,8 +48,6 @@ enum pthread_state
   PTHREAD_DETACHED,
   /* A joinable thread exited and its return code is available.  */
   PTHREAD_EXITED,
-  /* The thread structure is unallocated and available for reuse.  */
-  PTHREAD_TERMINATED
 };
 
 #ifndef PTHREAD_KEY_MEMBERS
@@ -95,6 +93,8 @@ struct __pthread
   enum pthread_state state;
   pthread_mutex_t state_lock;	/* Locks the state.  */
   pthread_cond_t state_cond;	/* Signalled when the state changes.  */
+  bool terminated;		/* Whether the kernel thread is over
+				   and we can reuse this structure.  */
 
   /* Resolver state.  */
   struct __res_state res_state;
@@ -209,12 +209,18 @@ extern int __pthread_create_internal (struct __pthread **__restrict pthread,
    kernel thread or a stack).  THREAD has one reference.  */
 extern int __pthread_alloc (struct __pthread **thread);
 
-/* Deallocate the thread structure.  This is the dual of
+/* Deallocate the content of the thread structure.  This is the dual of
    __pthread_alloc (N.B. it does not call __pthread_stack_dealloc nor
-   __pthread_thread_terminate).  THREAD loses one reference and is
-   released if the reference counter drops to 0.  */
+   __pthread_thread_terminate).  THREAD loses one reference, and if
+   if the reference counter drops to 0 this returns 1, and the caller has
+   to call __pthread_dealloc_finish when it is really finished with using
+   THREAD.  */
 extern void __pthread_dealloc (struct __pthread *thread);
 
+/* Confirm deallocating the thread structure.  Before calling this
+   the structure will not be reused yet.  */
+extern void __pthread_dealloc_finish (struct __pthread *pthread);
+
 
 /* Allocate a stack of size STACKSIZE.  The stack base shall be
    returned in *STACKADDR.  */