pthread.h revision 11cd02dfb91661c65134cac258cf5924270e9d2
111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Copyright (C) 2008 The Android Open Source Project 311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * All rights reserved. 411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * 511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Redistribution and use in source and binary forms, with or without 611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * modification, are permitted provided that the following conditions 711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * are met: 811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * * Redistributions of source code must retain the above copyright 911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * notice, this list of conditions and the following disclaimer. 1011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * * Redistributions in binary form must reproduce the above copyright 1111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * notice, this list of conditions and the following disclaimer in 1211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * the documentation and/or other materials provided with the 1311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * distribution. 1411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * 1511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * SUCH DAMAGE. 2711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 2811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#ifndef _PTHREAD_H_ 2911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define _PTHREAD_H_ 3011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include <time.h> 3211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include <signal.h> 3311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include <sched.h> 3411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include <limits.h> 3511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include <sys/types.h> 3611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 3811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Types 3911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 4011cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct 4111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 4211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int volatile value; 4311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} pthread_mutex_t; 4411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define __PTHREAD_MUTEX_INIT_VALUE 0 4611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define __PTHREAD_RECURSIVE_MUTEX_INIT_VALUE 0x4000 4711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define __PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE 0x8000 4811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_MUTEX_INITIALIZER {__PTHREAD_MUTEX_INIT_VALUE} 5011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER {__PTHREAD_RECURSIVE_MUTEX_INIT_VALUE} 5111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER {__PTHREAD_ERRORCHECK_MUTEX_INIT_VALUE} 5211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertenum { 5411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert PTHREAD_MUTEX_NORMAL = 0, 5511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert PTHREAD_MUTEX_RECURSIVE = 1, 5611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert PTHREAD_MUTEX_ERRORCHECK = 2, 5711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert PTHREAD_MUTEX_ERRORCHECK_NP = PTHREAD_MUTEX_ERRORCHECK, 5911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert PTHREAD_MUTEX_RECURSIVE_NP = PTHREAD_MUTEX_RECURSIVE, 6011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL 6211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert}; 6311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6611cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct 6711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 6811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int volatile value; 6911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} pthread_cond_t; 7011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 7111cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct 7211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 7311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert uint32_t flags; 7411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert void * stack_base; 7511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert size_t stack_size; 7611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert size_t guard_size; 7711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int32_t sched_policy; 7811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int32_t sched_priority; 7911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} pthread_attr_t; 8011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8111cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef long pthread_mutexattr_t; 8211cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef long pthread_condattr_t; 8311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8411cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef int pthread_key_t; 8511cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef long pthread_t; 8611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8711cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef volatile int pthread_once_t; 8811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 8911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 9011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Defines 9111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 9211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_COND_INITIALIZER {0} 9311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 9411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_STACK_MIN (2 * PAGE_SIZE) 9511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 9611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_CREATE_DETACHED 0x00000001 9711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_CREATE_JOINABLE 0x00000000 9811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 9911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_ONCE_INIT 0 10011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_PROCESS_PRIVATE 0 10211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_PROCESS_SHARED 1 10311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_SCOPE_SYSTEM 0 10511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_SCOPE_PROCESS 1 10611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 10711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* 10811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * Prototypes 10911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 11011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#ifdef __cplusplus 11111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertextern "C" { 11211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif 11311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 11411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_init(pthread_attr_t * attr); 11511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_destroy(pthread_attr_t * attr); 11611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 11711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setdetachstate(pthread_attr_t * attr, int state); 11811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getdetachstate(pthread_attr_t const * attr, int * state); 11911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 12011cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setschedpolicy(pthread_attr_t * attr, int policy); 12111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getschedpolicy(pthread_attr_t const * attr, int * policy); 12211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 12311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setschedparam(pthread_attr_t * attr, struct sched_param const * param); 12411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getschedparam(pthread_attr_t const * attr, struct sched_param * param); 12511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 12611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setstacksize(pthread_attr_t * attr, size_t stack_size); 12711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getstacksize(pthread_attr_t const * attr, size_t * stack_size); 12811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 12911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setstackaddr(pthread_attr_t * attr, void * stackaddr); 13011cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getstackaddr(pthread_attr_t const * attr, void ** stackaddr); 13111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 13211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setstack(pthread_attr_t * attr, void * stackaddr, size_t stack_size); 13311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getstack(pthread_attr_t const * attr, void ** stackaddr, size_t * stack_size); 13411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 13511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setguardsize(pthread_attr_t * attr, size_t guard_size); 13611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getguardsize(pthread_attr_t const * attr, size_t * guard_size); 13711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 13811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_setscope(pthread_attr_t *attr, int scope); 13911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_attr_getscope(pthread_attr_t const *attr); 14011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 14111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_getattr_np(pthread_t thid, pthread_attr_t * attr); 14211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 14311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_create(pthread_t *thread, pthread_attr_t const * attr, 14411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert void *(*start_routine)(void *), void * arg); 14511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 14611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert__noreturn void pthread_exit(void * retval); 14711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 14811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_join(pthread_t thid, void ** ret_val); 14911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_detach(pthread_t thid); 15011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 15111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertpthread_t pthread_self(void); 15211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_equal(pthread_t one, pthread_t two); 15311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 15411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_getschedparam(pthread_t thid, int * policy, 15511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert struct sched_param * param); 15611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_setschedparam(pthread_t thid, int poilcy, 15711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert struct sched_param const * param); 15811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 15911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutexattr_init(pthread_mutexattr_t *attr); 16011cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutexattr_destroy(pthread_mutexattr_t *attr); 16111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type); 16211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); 16311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared); 16411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared); 16511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 16611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutex_init(pthread_mutex_t *mutex, 16711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const pthread_mutexattr_t *attr); 16811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutex_destroy(pthread_mutex_t *mutex); 16911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutex_lock(pthread_mutex_t *mutex); 17011cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutex_unlock(pthread_mutex_t *mutex); 17111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutex_trylock(pthread_mutex_t *mutex); 17211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#if 0 /* MISSING FROM BIONIC */ 17311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutex_timedlock(pthread_mutex_t *mutex, struct timespec* ts); 17411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif /* MISSING */ 17511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 17611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_condattr_init(pthread_condattr_t *attr); 17711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_condattr_getpshared(pthread_condattr_t *attr, int *pshared); 17811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_condattr_setpshared(pthread_condattr_t* attr, int pshared); 17911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_condattr_destroy(pthread_condattr_t *attr); 18011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 18111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_init(pthread_cond_t *cond, 18211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const pthread_condattr_t *attr); 18311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_destroy(pthread_cond_t *cond); 18411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_broadcast(pthread_cond_t *cond); 18511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_signal(pthread_cond_t *cond); 18611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); 18711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_timedwait(pthread_cond_t *cond, 18811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pthread_mutex_t * mutex, 18911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const struct timespec *abstime); 19011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 19111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* BIONIC: same as pthread_cond_timedwait, except the 'abstime' given refers 19211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * to the CLOCK_MONOTONIC clock instead, to avoid any problems when 19311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * the wall-clock time is changed brutally 19411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 19511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_timedwait_monotonic_np(pthread_cond_t *cond, 19611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pthread_mutex_t *mutex, 19711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const struct timespec *abstime); 19811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 19911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* BIONIC: DEPRECATED. same as pthread_cond_timedwait_monotonic_np() 20011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * unfortunately pthread_cond_timedwait_monotonic has shipped already 20111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 20211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_timedwait_monotonic(pthread_cond_t *cond, 20311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pthread_mutex_t *mutex, 20411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const struct timespec *abstime); 20511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 20611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 1 20711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 20811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* BIONIC: same as pthread_cond_timedwait, except the 'reltime' given refers 20911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * is relative to the current time. 21011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 21111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_timedwait_relative_np(pthread_cond_t *cond, 21211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pthread_mutex_t *mutex, 21311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert const struct timespec *reltime); 21411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1 21611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 21911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_cond_timeout_np(pthread_cond_t *cond, 22011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pthread_mutex_t * mutex, 22111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert unsigned msecs); 22211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 22311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* same as pthread_mutex_lock(), but will wait up to 'msecs' milli-seconds 22411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * before returning. same return values than pthread_mutex_trylock though, i.e. 22511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * returns EBUSY if the lock could not be acquired after the timeout 22611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * expired. 22711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 22811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_mutex_lock_timeout_np(pthread_mutex_t *mutex, unsigned msecs); 22911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 23011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* read-write lock support */ 23111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 23211cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef int pthread_rwlockattr_t; 23311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 23411cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct { 23511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pthread_mutex_t lock; 23611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert pthread_cond_t cond; 23711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int numLocks; 23811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int writerThreadId; 23911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int pendingReaders; 24011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int pendingWriters; 24111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert void* reserved[4]; /* for future extensibility */ 24211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} pthread_rwlock_t; 24311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 24411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define PTHREAD_RWLOCK_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0, 0, { NULL, NULL, NULL, NULL } } 24511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 24611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlockattr_init(pthread_rwlockattr_t *attr); 24711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr); 24811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared); 24911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlockattr_getpshared(pthread_rwlockattr_t *attr, int *pshared); 25011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 25111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); 25211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_destroy(pthread_rwlock_t *rwlock); 25311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 25411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); 25511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); 25611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout); 25711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 25811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); 25911cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); 26011cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout); 26111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 26211cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_rwlock_unlock(pthread_rwlock_t *rwlock); 26311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 26411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 26511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_key_create(pthread_key_t *key, void (*destructor_function)(void *)); 26611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_key_delete (pthread_key_t); 26711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_setspecific(pthread_key_t key, const void *value); 26811cd02dfb91661c65134cac258cf5924270e9d2Dan Albertvoid *pthread_getspecific(pthread_key_t key); 26911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27011cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_kill(pthread_t tid, int sig); 27111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_sigmask(int how, const sigset_t *set, sigset_t *oset); 27211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27311cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_getcpuclockid(pthread_t tid, clockid_t *clockid); 27411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_once(pthread_once_t *once_control, void (*init_routine)(void)); 27611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertint pthread_setname_np(pthread_t thid, const char *thname); 27811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 27911cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef void (*__pthread_cleanup_func_t)(void*); 28011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 28111cd02dfb91661c65134cac258cf5924270e9d2Dan Alberttypedef struct __pthread_cleanup_t { 28211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert struct __pthread_cleanup_t* __cleanup_prev; 28311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert __pthread_cleanup_func_t __cleanup_routine; 28411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert void* __cleanup_arg; 28511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} __pthread_cleanup_t; 28611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 28711cd02dfb91661c65134cac258cf5924270e9d2Dan Albertextern void __pthread_cleanup_push(__pthread_cleanup_t* c, 28811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert __pthread_cleanup_func_t routine, 28911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert void* arg); 29011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 29111cd02dfb91661c65134cac258cf5924270e9d2Dan Albertextern void __pthread_cleanup_pop(__pthread_cleanup_t* c, 29211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert int execute); 29311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 29411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert/* Believe or not, the definitions of pthread_cleanup_push and 29511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * pthread_cleanup_pop below are correct. Posix states that these 29611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * can be implemented as macros that might introduce opening and 29711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * closing braces, and that using setjmp/longjmp/return/break/continue 29811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * between them results in undefined behaviour. 29911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * 30011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert * And indeed, GLibc and other C libraries use a similar definition 30111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert */ 30211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define pthread_cleanup_push(routine, arg) \ 30311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert do { \ 30411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert __pthread_cleanup_t __cleanup; \ 30511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert __pthread_cleanup_push( &__cleanup, (routine), (arg) ); \ 30611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 30711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#define pthread_cleanup_pop(execute) \ 30811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert __pthread_cleanup_pop( &__cleanup, (execute)); \ 30911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert } while (0); 31011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 31111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#ifdef __cplusplus 31211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} /* extern "C" */ 31311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif 31411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 31511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#endif /* _PTHREAD_H_ */ 316