20 for( i = 0; i < MAXTHREAD && !pthread_equal(
thread_table[i].tid,tid); i++ )
37 if( pthread_setprio(
thread_table[tid].tid, prio ) == -1 )
49 static void thr_cleanup(
struct thr_arg *
arg )
56 static void thr_startup(
struct thr_arg *
arg )
58 printf(
"thr_startup:tid=%d\n", arg->tid );
60 pthread_cleanup_push( thr_cleanup, arg );
62 pthread_setcancel( CANCEL_ON );
63 pthread_setasynccancel( CANCEL_ON );
65 (arg->func)( arg->args );
67 pthread_cleanup_pop( 1 );
70 int thr_create(
void *base,
size_t size,
void (*
func)(),
void *args,
long flags,
int *tid )
78 for( i = 0; i < MAXTHREAD &&
thread_table[i].using; i++ )
83 if( (arg = (
struct thr_arg *)malloc(
sizeof(
struct thr_arg) )) ==
NULL )
89 stat = pthread_create( &
thread_table[i].tid, pthread_attr_default, (pthread_startroutine_t)thr_startup, (pthread_addr_t)arg );
115 pthread_mutex_init(&(rwlp->
lock), pthread_mutexattr_default);
116 pthread_cond_init(&(rwlp->
r_cond), pthread_condattr_default);
117 pthread_cond_init(&(rwlp->
w_cond), pthread_condattr_default);
126 pthread_mutex_destroy( &(rwlp->
lock) );
127 pthread_cond_destroy( &(rwlp->
r_cond) );
128 pthread_cond_destroy( &(rwlp->
w_cond) );
135 pthread_mutex_lock( &(rwlp->
lock) );
137 pthread_cond_wait( &(rwlp->
r_cond), &(rwlp->
lock) );
139 pthread_mutex_unlock( &(rwlp->
lock) );
146 pthread_mutex_lock( &(rwlp->
lock) );
148 pthread_cond_wait( &(rwlp->
w_cond), &(rwlp->
lock) );
150 pthread_mutex_unlock( &(rwlp->
lock) );
157 pthread_mutex_lock( &(rwlp->
lock) );
162 pthread_cond_broadcast( &(rwlp->
w_cond) );
163 pthread_cond_broadcast( &(rwlp->
r_cond) );
164 pthread_mutex_unlock( &(rwlp->
lock) );
175 pthread_mutex_init(&(sem->
lock), pthread_mutexattr_default );
176 pthread_cond_init(&(sem->
cond), pthread_condattr_default );
184 pthread_mutex_destroy(&(sem->
lock));
185 pthread_cond_destroy(&(sem->
cond));
192 pthread_mutex_lock(&(sem->
lock));
193 while (sem->
count == 0){
194 pthread_cond_wait(&(sem->
cond), &(sem->
lock));}
196 pthread_mutex_unlock(&(sem->
lock));
204 pthread_mutex_lock(&(sem->
lock));
211 pthread_mutex_unlock(&(sem->
lock));
217 pthread_mutex_lock(&(sem->
lock));
219 pthread_cond_broadcast(&(sem->
cond));
220 pthread_mutex_unlock(&(sem->
lock));
231 for( i = 0; i < MAXTHREAD; i++ )
237 pthread_mutex_init(&
p_mark_lock, pthread_mutexattr_default );
238 pthread_mutex_init(&
alloc_lock, pthread_mutexattr_default );
240 pthread_mutex_init(&
qthread_lock, pthread_mutexattr_default );
241 pthread_mutex_init(&
qsort_lock, pthread_mutexattr_default );
int rwlock_destroy(rwlock_t *)
int thr_setprio(int, int)
int sema_init(sema_t *, unsigned int, int, void *)
int rwlock_init(rwlock_t *, int, void *)
int rw_wrlock(rwlock_t *)
struct @10 thread_table[]
int sema_destroy(sema_t *)
int thr_create(void *, size_t, void(*)(), void *, long, int *)
int rw_rdlock(rwlock_t *)
int sema_trywait(sema_t *)
int rw_unlock(rwlock_t *)
int thr_getprio(int tid, int *prio)
int sema_post(sema_t *sem)