pthread_internals.h [plain text]
#ifndef _POSIX_PTHREAD_INTERNALS_H
#define _POSIX_PTHREAD_INTERNALS_H
#define _PTHREAD_ATTR_T
struct _pthread_attr_t;
typedef struct _pthread_attr_t pthread_attr_t;
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#ifndef __POSIX_LIB__
#define __POSIX_LIB__
#endif
#include "posix_sched.h"
#include <sys/queue.h>
#include "pthread_machdep.h"
#include "pthread_spinlock.h"
LIST_HEAD(__pthread_list, _pthread);
extern struct __pthread_list __pthread_head;
extern pthread_lock_t _pthread_list_lock;
#undef _POSIX_THREAD_KEYS_MAX
#define _POSIX_THREAD_KEYS_MAX 128
#define _PTHREAD_T
typedef struct _pthread
{
long sig;
struct __darwin_pthread_handler_rec *__cleanup_stack;
pthread_lock_t lock;
u_int32_t detached:8,
inherit:8,
policy:8,
pad:8;
size_t guardsize;
#if !defined(__LP64__)
int pad0;
#endif
struct sched_param param;
struct _pthread_mutex *mutexes;
struct _pthread *joiner;
#if !defined(__LP64__)
int pad1;
#endif
void *exit_value;
semaphore_t death;
mach_port_t kernel_thread;
void *(*fun)(void*);
void *arg;
int cancel_state;
int err_no;
void *tsd[_POSIX_THREAD_KEYS_MAX];
void *stackaddr;
size_t stacksize;
mach_port_t reply_port;
#if defined(__LP64__)
int pad2;
#endif
void *cthread_self;
boolean_t freeStackOnExit;
#if defined(__LP64__)
int pad3;
#endif
LIST_ENTRY(_pthread) plist;
} *pthread_t;
typedef char _need_to_change_PTHREAD_TSD_OFFSET[(_PTHREAD_TSD_OFFSET == offsetof(struct _pthread, tsd[0])) ? 0 : -1] ;
struct _pthread_attr_t
{
long sig;
pthread_lock_t lock;
u_int32_t detached:8,
inherit:8,
policy:8,
reserved1:8;
size_t guardsize;
int reserved2;
struct sched_param param;
void *stackaddr;
size_t stacksize;
boolean_t freeStackOnExit;
};
#define _PTHREAD_MUTEXATTR_T
typedef struct
{
long sig;
int prioceiling;
u_int32_t protocol:2,
type:2,
rfu:28;
} pthread_mutexattr_t;
#define _PTHREAD_MUTEX_T
typedef struct _pthread_mutex
{
long sig;
pthread_lock_t lock;
u_int32_t waiters;
pthread_t owner;
semaphore_t sem;
u_int32_t protocol:2,
type:2,
rfu:12,
lock_count:16;
struct _pthread_mutex *next, *prev;
struct _pthread_cond *busy;
int16_t prioceiling;
int16_t priority;
semaphore_t order;
} pthread_mutex_t;
#define _PTHREAD_CONDATTR_T
typedef struct
{
long sig;
int unsupported;
} pthread_condattr_t;
#define _PTHREAD_COND_T
typedef struct _pthread_cond
{
long sig;
pthread_lock_t lock;
semaphore_t sem;
struct _pthread_cond *next, *prev;
struct _pthread_mutex *busy;
u_int32_t waiters:16,
sigspending:16;
} pthread_cond_t;
#define _PTHREAD_ONCE_T
typedef struct
{
long sig;
pthread_lock_t lock;
} pthread_once_t;
#define _PTHREAD_RWLOCKATTR_T
typedef struct {
long sig;
int pshared;
int rfu[2];
} pthread_rwlockattr_t;
#define _PTHREAD_RWLOCK_T
typedef struct {
long sig;
pthread_mutex_t lock;
int state;
pthread_cond_t read_signal;
pthread_cond_t write_signal;
int blocked_writers;
int pshared;
int rfu[3];
} pthread_rwlock_t;
#include "pthread.h"
#if defined(__i386__) || defined(__ppc64__) || defined(__x86_64__)
inline static pthread_t __attribute__((__pure__))
_pthread_self_direct(void)
{
pthread_t ret;
#if defined(__i386__) || defined(__x86_64__)
asm("mov %%gs:%P1, %0" : "=r" (ret) : "i" (offsetof(struct _pthread, tsd[0])));
#elif defined(__ppc64__)
register const pthread_t __pthread_self asm ("r13");
ret = __pthread_self;
#endif
return ret;
}
#define pthread_self() _pthread_self_direct()
#endif
#define _PTHREAD_DEFAULT_INHERITSCHED PTHREAD_INHERIT_SCHED
#define _PTHREAD_DEFAULT_PROTOCOL PTHREAD_PRIO_NONE
#define _PTHREAD_DEFAULT_PRIOCEILING 0
#define _PTHREAD_DEFAULT_POLICY SCHED_OTHER
#define _PTHREAD_DEFAULT_STACKSIZE 0x80000
#define _PTHREAD_NO_SIG 0x00000000
#define _PTHREAD_MUTEX_ATTR_SIG 0x4D545841
#define _PTHREAD_MUTEX_SIG 0x4D555458
#define _PTHREAD_MUTEX_SIG_init 0x32AAABA7
#define _PTHREAD_COND_ATTR_SIG 0x434E4441
#define _PTHREAD_COND_SIG 0x434F4E44
#define _PTHREAD_COND_SIG_init 0x3CB0B1BB
#define _PTHREAD_ATTR_SIG 0x54484441
#define _PTHREAD_ONCE_SIG 0x4F4E4345
#define _PTHREAD_ONCE_SIG_init 0x30B1BCBA
#define _PTHREAD_SIG 0x54485244
#define _PTHREAD_RWLOCK_ATTR_SIG 0x52574C41
#define _PTHREAD_RWLOCK_SIG 0x52574C4B
#define _PTHREAD_RWLOCK_SIG_init 0x2DA8B3B4
#define _PTHREAD_CREATE_PARENT 4
#define _PTHREAD_EXITED 8
#if defined(DEBUG)
#define _PTHREAD_MUTEX_OWNER_SELF pthread_self()
#else
#define _PTHREAD_MUTEX_OWNER_SELF (pthread_t)0x12141968
#endif
#define _PTHREAD_MUTEX_OWNER_SWITCHING (pthread_t)(~0)
#define _PTHREAD_CANCEL_STATE_MASK 0x01
#define _PTHREAD_CANCEL_TYPE_MASK 0x02
#define _PTHREAD_CANCEL_PENDING 0x10
extern boolean_t swtch_pri(int);
#ifndef ESUCCESS
#define ESUCCESS 0
#endif
#ifndef PTHREAD_MACH_CALL
#define PTHREAD_MACH_CALL(expr, ret) (ret) = (expr)
#endif
extern vm_address_t _sp(void);
extern vm_address_t _adjust_sp(vm_address_t sp);
extern void _pthread_setup(pthread_t th, void (*f)(pthread_t), void *sp, int suspended, int needresume);
extern void _pthread_tsd_cleanup(pthread_t self);
__private_extern__ semaphore_t new_sem_from_pool(void);
__private_extern__ void restore_sem_to_pool(semaphore_t);
__private_extern__ void _pthread_atfork_queue_init(void);
#endif