pthread_internals.h [plain text]
#ifndef _POSIX_PTHREAD_INTERNALS_H
#define _POSIX_PTHREAD_INTERNALS_H
#include <assert.h>
#include <mach/port.h>
#include <mach/mach_error.h>
#include <mach/message.h>
#include <mach/machine/vm_types.h>
#include <mach/std_types.h>
#include <mach/policy.h>
#include <mach/sync.h>
#include <mach/sync_policy.h>
#include <mach/mach_traps.h>
#include <mach/thread_switch.h>
#include <mach/mach_host.h>
#include <mach/mach.h>
#ifndef __POSIX_LIB__
#define __POSIX_LIB__
#endif
#include "posix_sched.h"
#include "pthread_machdep.h"
extern kern_return_t syscall_thread_switch(mach_port_name_t, int, mach_msg_timeout_t);
#undef _POSIX_THREAD_KEYS_MAX
#define _POSIX_THREAD_KEYS_MAX 128
typedef struct _pthread
{
long sig;
struct _pthread_handler_rec *cleanup_stack;
pthread_lock_t lock;
int detached;
int inherit;
int policy;
struct sched_param param;
struct _pthread_mutex *mutexes;
mach_port_t joiners;
int num_joiners;
void *exit_value;
mach_port_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;
void *cthread_self;
boolean_t freeStackOnExit;
} *pthread_t;
typedef struct
{
long sig;
pthread_lock_t lock;
int detached;
int inherit;
int policy;
struct sched_param param;
void *stackaddr;
size_t stacksize;
boolean_t freeStackOnExit;
} pthread_attr_t;
typedef struct
{
long sig;
int prioceiling;
int protocol;
} pthread_mutexattr_t;
typedef struct _pthread_mutex
{
long sig;
pthread_lock_t lock;
int prioceiling;
int priority;
int protocol;
pthread_t owner;
struct _pthread_mutex *next, *prev;
struct _pthread_cond *busy;
int waiters:31,
cond_lock:1;
mach_port_t sem;
} pthread_mutex_t;
typedef struct
{
long sig;
int unsupported;
} pthread_condattr_t;
typedef struct _pthread_cond
{
long sig;
pthread_lock_t lock;
mach_port_t sem;
struct _pthread_cond *next, *prev;
struct _pthread_mutex *busy;
int waiters:16,
sigspending:16;
} pthread_cond_t;
typedef struct
{
long sig;
pthread_lock_t lock;
} pthread_once_t;
#include "pthread.h"
#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_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_EXITED 3
#define _PTHREAD_CREATE_PARENT 4
#define _PTHREAD_CANCEL_STATE_MASK 0xFE
#define _PTHREAD_CANCEL_TYPE_MASK 0xFD
#define _PTHREAD_CANCEL_PENDING 0x10
extern boolean_t swtch_pri(int);
#define SPIN_TRIES 10
extern int _spin_tries;
extern int __is_threaded;
extern int _cpu_has_altivec;
#define TRY_LOCK(v) (!__is_threaded || _spin_lock_try((pthread_lock_t *)&v))
#if 0
#define LOCK(v) if (__is_threaded) _spin_lock((pthread_lock_t)&v)
#else
#define LOCK(v) \
if (__is_threaded) { \
while (!_spin_lock_try((pthread_lock_t *)&v)) { \
syscall_thread_switch(THREAD_NULL, SWITCH_OPTION_WAIT, 1); \
} \
}
#endif
#define UNLOCK(v) if (__is_threaded) _spin_unlock((pthread_lock_t *)&v)
#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 _spin_lock(pthread_lock_t *lockp);
extern int _spin_lock_try(pthread_lock_t *lockp);
extern void _spin_unlock(pthread_lock_t *lockp);
extern void _pthread_setup(pthread_t th, void (*f)(pthread_t), vm_address_t sp);
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);
#endif