(loc_RunThread, empth_init, empth_threadMain, empth_yield)
(empth_select, empth_sleep, empth_wait_for_signal) (empth_sem_wait) [EMPTH_W32]: Add the ability to wait additional event in loc_RunThread() when acquiring the hThread mutex. (empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy) (empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock): New. (empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy) (empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock) [EMPTH_W32]: WIN32 implementation. (empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy) (empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock) (lwp_rwlock, lwp_rwlock_create, lwp_rwlock_destroy) (lwp_rwlock_wrlock, lwp_rwlock_rdlock, lwp_rwlock_unlock) [EMPTH_LWP]: LWP implementation. (empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy) (empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock) [EMPTH_POSIX]: pthread implementation.
This commit is contained in:
parent
8c65fbc2be
commit
71e0f98825
6 changed files with 409 additions and 14 deletions
|
@ -30,7 +30,8 @@
|
|||
* Known contributors to this file:
|
||||
* Sasha Mikheev
|
||||
* Steve McClure, 1998
|
||||
* Markus Armbruster, 2005-2006
|
||||
* Markus Armbruster, 2005-2007
|
||||
* Ron Koenderink, 2007
|
||||
*/
|
||||
|
||||
/* Required for PTHREAD_STACK_MIN on some systems, e.g. Solaris: */
|
||||
|
@ -75,6 +76,11 @@ struct empth_sem_t {
|
|||
pthread_cond_t cnd_sem;
|
||||
};
|
||||
|
||||
struct empth_rwlock_t {
|
||||
char *name;
|
||||
pthread_rwlock_t lock;
|
||||
};
|
||||
|
||||
/* Thread-specific data key */
|
||||
static pthread_key_t ctx_key;
|
||||
|
||||
|
@ -455,3 +461,52 @@ empth_sem_wait(empth_sem_t *sm)
|
|||
} else
|
||||
pthread_mutex_unlock(&sm->mtx_update);
|
||||
}
|
||||
|
||||
empth_rwlock_t *
|
||||
empth_rwlock_create(char *name)
|
||||
{
|
||||
empth_rwlock_t *rwlock;
|
||||
|
||||
rwlock = malloc(sizeof(*rwlock));
|
||||
if (!rwlock)
|
||||
return NULL;
|
||||
|
||||
if (pthread_rwlock_init(&rwlock->lock, NULL) != 0) {
|
||||
free(rwlock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rwlock->name = strdup(name);
|
||||
return rwlock;
|
||||
}
|
||||
|
||||
void
|
||||
empth_rwlock_destroy(empth_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_destroy(&rwlock->lock);
|
||||
free(rwlock);
|
||||
}
|
||||
|
||||
void
|
||||
empth_rwlock_wrlock(empth_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_mutex_unlock(&mtx_ctxsw);
|
||||
pthread_rwlock_wrlock(&rwlock->lock);
|
||||
pthread_mutex_lock(&mtx_ctxsw);
|
||||
empth_restorectx();
|
||||
}
|
||||
|
||||
void
|
||||
empth_rwlock_rdlock(empth_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_mutex_unlock(&mtx_ctxsw);
|
||||
pthread_rwlock_rdlock(&rwlock->lock);
|
||||
pthread_mutex_lock(&mtx_ctxsw);
|
||||
empth_restorectx();
|
||||
}
|
||||
|
||||
void
|
||||
empth_rwlock_unlock(empth_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_unlock(&rwlock->lock);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue