1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* $OpenBSD: rthread.h,v 1.8 2005/12/19 06:47:40 tedu Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Private data structures that back up the typedefs in pthread.h.
* Since only the thread library cares about their size or arrangement,
* it should be possible to switch libraries without relinking.
*/
struct stack {
void *sp;
void *base;
size_t len;
};
typedef struct semaphore {
volatile int waitcount;
volatile int value;
_spinlock_lock_t lock;
} *sem_t;
struct pthread_mutex {
struct semaphore sem;
int type;
pthread_t owner;
int count;
};
struct pthread_mutex_attr {
int type;
};
struct pthread_cond {
struct semaphore sem;
};
struct pthread_cond_attr {
int shared;
};
struct pthread_rwlock {
_spinlock_lock_t lock;
int readers;
int writer;
struct semaphore sem;
};
struct pthread_rwlockattr {
int dummy;
};
struct pthread_attr {
void *stack_addr;
size_t stack_size;
int detach_state;
int contention_scope;
int sched_policy;
struct sched_param sched_param;
int sched_inherit;
};
struct rthread_key {
int used;
void (*destructor)(void *);
};
struct rthread_storage {
int keyid;
struct rthread_storage *next;
void *data;
};
struct rthread_cleanup_fn {
void (*fn)(void *);
void *arg;
struct rthread_cleanup_fn *next;
};
struct pthread {
pid_t tid;
struct semaphore donesem;
unsigned int flags;
void *retval;
void *(*fn)(void *);
void *arg;
char name[32];
struct stack *stack;
pthread_t next;
int sched_policy;
struct sched_param sched_param;
struct rthread_storage *local_storage;
int sigpend;
struct rthread_cleanup_fn *cleanup_fns;
};
#define THREAD_DONE 0x001
#define THREAD_DETACHED 0x002
#define THREAD_CANCELLED 0x004
#define THREAD_CANCEL_ENABLE 0x008
#define THREAD_CANCEL_DEFERRED 0x010
void _spinlock(_spinlock_lock_t *);
void _spinunlock(_spinlock_lock_t *);
int _sem_wait(sem_t, int, int);
int _sem_waitl(sem_t, int, int);
int _sem_post(sem_t);
int _sem_wakeup(sem_t);
int _sem_wakeall(sem_t);
void rthread_tls_destructors(pthread_t);
int _atomic_lock(register volatile _spinlock_lock_t *);
|