Blame sysdeps/nptl/threads.h

Packit Service 82fcde
/* ISO C11 Standard: 7.26 - Thread support library  <threads.h>.
Packit Service 82fcde
   Copyright (C) 2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef _THREADS_H
Packit Service 82fcde
#define _THREADS_H	1
Packit Service 82fcde
Packit Service 82fcde
#include <features.h>
Packit Service 82fcde
#include <time.h>
Packit Service 82fcde
Packit Service 82fcde
__BEGIN_DECLS
Packit Service 82fcde
Packit Service 82fcde
#include <bits/pthreadtypes-arch.h>
Packit Service 82fcde
#include <bits/types/struct_timespec.h>
Packit Service 82fcde
Packit Service 82fcde
#ifndef __cplusplus
Packit Service 82fcde
# define thread_local _Thread_local
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
#define TSS_DTOR_ITERATIONS 4
Packit Service 82fcde
typedef unsigned int tss_t;
Packit Service 82fcde
typedef void (*tss_dtor_t) (void*);
Packit Service 82fcde
Packit Service 82fcde
typedef unsigned long int thrd_t;
Packit Service 82fcde
typedef int (*thrd_start_t) (void*);
Packit Service 82fcde
Packit Service 82fcde
/* Exit and error codes.  */
Packit Service 82fcde
enum
Packit Service 82fcde
{
Packit Service 82fcde
  thrd_success  = 0,
Packit Service 82fcde
  thrd_busy     = 1,
Packit Service 82fcde
  thrd_error    = 2,
Packit Service 82fcde
  thrd_nomem    = 3,
Packit Service 82fcde
  thrd_timedout = 4
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
/* Mutex types.  */
Packit Service 82fcde
enum
Packit Service 82fcde
{
Packit Service 82fcde
  mtx_plain     = 0,
Packit Service 82fcde
  mtx_recursive = 1,
Packit Service 82fcde
  mtx_timed     = 2
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
typedef struct
Packit Service 82fcde
{
Packit Service 82fcde
  int __data __ONCE_ALIGNMENT;
Packit Service 82fcde
} once_flag;
Packit Service 82fcde
#define ONCE_FLAG_INIT { 0 }
Packit Service 82fcde
Packit Service 82fcde
typedef union
Packit Service 82fcde
{
Packit Service 82fcde
  char __size[__SIZEOF_PTHREAD_MUTEX_T];
Packit Service 82fcde
  long int __align __LOCK_ALIGNMENT;
Packit Service 82fcde
} mtx_t;
Packit Service 82fcde
Packit Service 82fcde
typedef union
Packit Service 82fcde
{
Packit Service 82fcde
  char __size[__SIZEOF_PTHREAD_COND_T];
Packit Service 82fcde
  __extension__ long long int __align __LOCK_ALIGNMENT;
Packit Service 82fcde
} cnd_t;
Packit Service 82fcde
Packit Service 82fcde
/* Threads functions.  */
Packit Service 82fcde
Packit Service 82fcde
/* Create a new thread executing the function __FUNC.  Arguments for __FUNC
Packit Service 82fcde
   are passed through __ARG.  If succesful, __THR is set to new thread
Packit Service 82fcde
   identifier.  */
Packit Service 82fcde
extern int thrd_create (thrd_t *__thr, thrd_start_t __func, void *__arg);
Packit Service 82fcde
Packit Service 82fcde
/* Check if __LHS and __RHS point to the same thread.  */
Packit Service 82fcde
extern int thrd_equal (thrd_t __lhs, thrd_t __rhs);
Packit Service 82fcde
Packit Service 82fcde
/* Return current thread identifier.  */
Packit Service 82fcde
extern thrd_t thrd_current (void);
Packit Service 82fcde
Packit Service 82fcde
/* Block current thread execution for at least the time pointed by
Packit Service 82fcde
   __TIME_POINT.  The current thread may resume if receives a signal.  In
Packit Service 82fcde
   that case, if __REMAINING is not NULL, the remaining time is stored in
Packit Service 82fcde
   the object pointed by it.  */
Packit Service 82fcde
extern int thrd_sleep (const struct timespec *__time_point,
Packit Service 82fcde
		       struct timespec *__remaining);
Packit Service 82fcde
Packit Service 82fcde
/* Terminate current thread execution, cleaning up any thread local
Packit Service 82fcde
   storage and freeing resources.  Returns the value specified in __RES.  */
Packit Service 82fcde
extern void thrd_exit (int __res) __attribute__ ((__noreturn__));
Packit Service 82fcde
Packit Service 82fcde
/* Detach the thread identified by __THR from the current environment
Packit Service 82fcde
   (it does not allow join or wait for it).  */
Packit Service 82fcde
extern int thrd_detach (thrd_t __thr);
Packit Service 82fcde
Packit Service 82fcde
/* Block current thread until execution of __THR is complete.  In case that
Packit Service 82fcde
   __RES is not NULL, will store the return value of __THR when exiting.  */
Packit Service 82fcde
extern int thrd_join (thrd_t __thr, int *__res);
Packit Service 82fcde
Packit Service 82fcde
/* Stop current thread execution and call the scheduler to decide which
Packit Service 82fcde
   thread should execute next.  The current thread may be selected by the
Packit Service 82fcde
   scheduler to keep running.  */
Packit Service 82fcde
extern void thrd_yield (void);
Packit Service 82fcde
Packit Service 82fcde
#ifdef __USE_EXTERN_INLINES
Packit Service 82fcde
/* Optimizations.  */
Packit Service 82fcde
__extern_inline int
Packit Service 82fcde
thrd_equal (thrd_t __thread1, thrd_t __thread2)
Packit Service 82fcde
{
Packit Service 82fcde
  return __thread1 == __thread2;
Packit Service 82fcde
}
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Mutex functions.  */
Packit Service 82fcde
Packit Service 82fcde
/* Creates a new mutex object with type __TYPE.  If successful the new
Packit Service 82fcde
   object is pointed by __MUTEX.  */
Packit Service 82fcde
extern int mtx_init (mtx_t *__mutex, int __type);
Packit Service 82fcde
Packit Service 82fcde
/* Block the current thread until the mutex pointed to by __MUTEX is
Packit Service 82fcde
   unlocked.  In that case current thread will not be blocked.  */
Packit Service 82fcde
extern int mtx_lock (mtx_t *__mutex);
Packit Service 82fcde
Packit Service 82fcde
/* Block the current thread until the mutex pointed by __MUTEX is unlocked
Packit Service 82fcde
   or time pointed by __TIME_POINT is reached.  In case the mutex is unlock,
Packit Service 82fcde
   the current thread will not be blocked.  */
Packit Service 82fcde
extern int mtx_timedlock (mtx_t *__restrict __mutex,
Packit Service 82fcde
			  const struct timespec *__restrict __time_point);
Packit Service 82fcde
Packit Service 82fcde
/* Try to lock the mutex pointed by __MUTEX without blocking.  If the mutex
Packit Service 82fcde
   is free the current threads takes control of it, otherwise it returns
Packit Service 82fcde
   immediately.  */
Packit Service 82fcde
extern int mtx_trylock (mtx_t *__mutex);
Packit Service 82fcde
Packit Service 82fcde
/* Unlock the mutex pointed by __MUTEX.  It may potentially awake other
Packit Service 82fcde
   threads waiting on this mutex.  */
Packit Service 82fcde
extern int mtx_unlock (mtx_t *__mutex);
Packit Service 82fcde
Packit Service 82fcde
/* Destroy the mutex object pointed by __MUTEX.  */
Packit Service 82fcde
extern void mtx_destroy (mtx_t *__mutex);
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Call function __FUNC exactly once, even if invoked from several threads.
Packit Service 82fcde
   All calls must be made with the same __FLAGS object.  */
Packit Service 82fcde
extern void call_once (once_flag *__flag, void (*__func)(void));
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Condition variable functions.  */
Packit Service 82fcde
Packit Service 82fcde
/* Initialize new condition variable pointed by __COND.  */
Packit Service 82fcde
extern int cnd_init (cnd_t *__cond);
Packit Service 82fcde
Packit Service 82fcde
/* Unblock one thread that currently waits on condition variable pointed
Packit Service 82fcde
   by __COND.  */
Packit Service 82fcde
extern int cnd_signal (cnd_t *__cond);
Packit Service 82fcde
Packit Service 82fcde
/* Unblock all threads currently waiting on condition variable pointed by
Packit Service 82fcde
   __COND.  */
Packit Service 82fcde
extern int cnd_broadcast (cnd_t *__cond);
Packit Service 82fcde
Packit Service 82fcde
/* Block current thread on the condition variable pointed by __COND.  */
Packit Service 82fcde
extern int cnd_wait (cnd_t *__cond, mtx_t *__mutex);
Packit Service 82fcde
Packit Service 82fcde
/* Block current thread on the condition variable until condition variable
Packit Service 82fcde
   pointed by __COND is signaled or time pointed by __TIME_POINT is
Packit Service 82fcde
   reached.  */
Packit Service 82fcde
extern int cnd_timedwait (cnd_t *__restrict __cond,
Packit Service 82fcde
			  mtx_t *__restrict __mutex,
Packit Service 82fcde
			  const struct timespec *__restrict __time_point);
Packit Service 82fcde
Packit Service 82fcde
/* Destroy condition variable pointed by __cond and free all of its
Packit Service 82fcde
   resources.  */
Packit Service 82fcde
extern void cnd_destroy (cnd_t *__COND);
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Thread specific storage functions.  */
Packit Service 82fcde
Packit Service 82fcde
/* Create new thread-specific storage key and stores it in the object pointed
Packit Service 82fcde
   by __TSS_ID.  If __DESTRUCTOR is not NULL, the function will be called when
Packit Service 82fcde
   the thread terminates.  */
Packit Service 82fcde
extern int tss_create (tss_t *__tss_id, tss_dtor_t __destructor);
Packit Service 82fcde
Packit Service 82fcde
/* Return the value held in thread-specific storage for the current thread
Packit Service 82fcde
   identified by __TSS_ID.  */
Packit Service 82fcde
extern void *tss_get (tss_t __tss_id);
Packit Service 82fcde
Packit Service 82fcde
/* Sets the value of the thread-specific storage identified by __TSS_ID for
Packit Service 82fcde
   the current thread to __VAL.  */
Packit Service 82fcde
extern int tss_set (tss_t __tss_id, void *__val);
Packit Service 82fcde
Packit Service 82fcde
/* Destroys the thread-specific storage identified by __TSS_ID.  The
Packit Service 82fcde
   destructor is not called until thrd_exit is called.  */
Packit Service 82fcde
extern void tss_delete (tss_t __tss_id);
Packit Service 82fcde
Packit Service 82fcde
__END_DECLS
Packit Service 82fcde
Packit Service 82fcde
#endif /* _THREADS_H */