Blame sysdeps/nptl/threads.h

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