]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - htl/pt-internal.h
Use __nonnull for the epoll_wait(2) family of syscalls
[thirdparty/glibc.git] / htl / pt-internal.h
index 22afc1fcce63e9b6488b02057760510da21c3411..5179428ce709d642eb9ad24b7a9ca3235747c5d4 100644 (file)
@@ -1,20 +1,20 @@
-/* Internal defenitions for pthreads library.
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
+/* Internal definitions for pthreads library.
+   Copyright (C) 2000-2023 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If
-   not, see <http://www.gnu.org/licenses/>.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library;  if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #ifndef _PT_INTERNAL_H
 #define _PT_INTERNAL_H 1
@@ -37,6 +37,8 @@
 # include <ldsodefs.h>
 #endif
 
+#include <tls.h>
+
 /* Thread state.  */
 enum pthread_state
 {
@@ -46,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
@@ -58,16 +58,6 @@ enum pthread_state
 # define PTHREAD_SYSDEP_MEMBERS
 #endif
 
-#if !(IS_IN (libpthread))
-/* Type of the TCB.  */
-typedef struct
-{
-  void *tcb;                   /* Points to this structure.  */
-  void *dtv;                   /* Vector of pointers to TLS data.  */
-  thread_t self;               /* This thread's control port.  */
-} tcbhead_t;
-#endif /* ! IS_IN (libpthread) */
-
 /* This structure describes a POSIX thread.  */
 struct __pthread
 {
@@ -89,7 +79,6 @@ struct __pthread
   int cancel_state;
   int cancel_type;
   int cancel_pending;
-  struct __pthread_cancelation_handler *cancelation_handlers;
 
   /* Thread stack.  */
   void *stackaddr;
@@ -104,10 +93,18 @@ 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;
 
+  /* Indicates whether is a C11 thread created by thrd_creat.  */
+  bool c11;
+
+  /* Initial sigset for the thread.  */
+  sigset_t init_sigset;
+
   /* Thread context.  */
   struct pthread_mcontext mcontext;
 
@@ -168,38 +165,35 @@ __pthread_dequeue (struct __pthread *thread)
 
 /* The total number of threads currently active.  */
 extern unsigned int __pthread_total;
-
-/* The total number of thread IDs currently in use, or on the list of
-   available thread IDs.  */
-extern int __pthread_num_threads;
+libc_hidden_proto (__pthread_total)
 
 /* Concurrency hint.  */
 extern int __pthread_concurrency;
 
-/* Array of __pthread structures and its lock.  Indexed by the pthread
-   id minus one.  (Why not just use the pthread id?  Because some
-   brain-dead users of the pthread interface incorrectly assume that 0
-   is an invalid pthread id.)  */
-extern struct __pthread **__pthread_threads;
-extern pthread_rwlock_t __pthread_threads_lock;
+/* The size of the thread ID lookup table.  */
+extern int __pthread_max_threads;
 
 #define __pthread_getid(thread) \
-  ({ struct __pthread *__t;                                                  \
-     __pthread_rwlock_rdlock (&__pthread_threads_lock);                      \
-     __t = __pthread_threads[thread - 1];                                    \
-     __pthread_rwlock_unlock (&__pthread_threads_lock);                      \
+  ({ struct __pthread *__t = NULL;                                           \
+     __libc_rwlock_rdlock (GL (dl_pthread_threads_lock));                    \
+     if (thread <= __pthread_max_threads)                                    \
+       __t = GL (dl_pthread_threads)[thread - 1];                            \
+     __libc_rwlock_unlock (GL (dl_pthread_threads_lock));                    \
      __t; })
 
 #define __pthread_setid(thread, pthread) \
-  __pthread_rwlock_wrlock (&__pthread_threads_lock);                         \
-  __pthread_threads[thread - 1] = pthread;                                   \
-  __pthread_rwlock_unlock (&__pthread_threads_lock);
+  __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));                       \
+  GL (dl_pthread_threads)[thread - 1] = pthread;                             \
+  __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
 
 /* Similar to pthread_self, but returns the thread descriptor instead
    of the thread ID.  */
 #ifndef _pthread_self
 extern struct __pthread *_pthread_self (void);
 #endif
+
+/* Stores the stack of cleanup handlers for the thread.  */
+extern __thread struct __pthread_cancelation_handler *__pthread_cleanup_stack;
 \f
 
 /* Initialize the pthreads library.  */
@@ -216,12 +210,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.  */
@@ -273,6 +273,14 @@ extern error_t __pthread_timedblock (struct __pthread *__restrict thread,
                                     const struct timespec *__restrict abstime,
                                     clockid_t clock_id);
 
+/* Block THREAD with interrupts.  */
+extern error_t __pthread_block_intr (struct __pthread *thread);
+
+/* Block THREAD until *ABSTIME is reached, with interrupts.  */
+extern error_t __pthread_timedblock_intr (struct __pthread *__restrict thread,
+                                         const struct timespec *__restrict abstime,
+                                         clockid_t clock_id);
+
 /* Wakeup THREAD.  */
 extern void __pthread_wakeup (struct __pthread *thread);
 
@@ -304,21 +312,54 @@ extern error_t __pthread_sigstate (struct __pthread *__restrict thread, int how,
                                   const sigset_t *__restrict set,
                                   sigset_t *__restrict oset,
                                   int clear_pending);
+
+/* If supported, check that MUTEX is locked by the caller.  */
+extern int __pthread_mutex_checklocked (pthread_mutex_t *mtx);
 \f
 
 /* Default thread attributes.  */
-extern const struct __pthread_attr __pthread_default_attr;
+extern struct __pthread_attr __pthread_default_attr;
 
 /* Default barrier attributes.  */
 extern const struct __pthread_barrierattr __pthread_default_barrierattr;
 
-/* Default mutex attributes.  */
-extern const struct __pthread_mutexattr __pthread_default_mutexattr;
-
 /* Default rdlock attributes.  */
 extern const struct __pthread_rwlockattr __pthread_default_rwlockattr;
 
 /* Default condition attributes.  */
 extern const struct __pthread_condattr __pthread_default_condattr;
 
+/* Semaphore encoding.
+   See nptl implementation for the details.  */
+struct new_sem
+{
+#if __HAVE_64B_ATOMICS
+  /* The data field holds both value (in the least-significant 32 bits) and
+     nwaiters.  */
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define SEM_VALUE_OFFSET 0
+# elif __BYTE_ORDER == __BIG_ENDIAN
+#  define SEM_VALUE_OFFSET 1
+# else
+#  error Unsupported byte order.
+# endif
+# define SEM_NWAITERS_SHIFT 32
+# define SEM_VALUE_MASK (~(unsigned int)0)
+  uint64_t data;
+  int pshared;
+#define __SEMAPHORE_INITIALIZER(value, pshared) \
+  { (value), (pshared) }
+#else
+# define SEM_VALUE_SHIFT 1
+# define SEM_NWAITERS_MASK ((unsigned int)1)
+  unsigned int value;
+  unsigned int nwaiters;
+  int pshared;
+#define __SEMAPHORE_INITIALIZER(value, pshared) \
+  { (value) << SEM_VALUE_SHIFT, 0, (pshared) }
+#endif
+};
+
+extern int __sem_waitfast (struct new_sem *isem, int definitive_result);
+
 #endif /* pt-internal.h */