diff options
author | marha <marha@users.sourceforge.net> | 2011-07-18 10:33:05 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-07-18 10:33:05 +0200 |
commit | 88101146f2ec7d53ffb793e365f05097ffd35fd3 (patch) | |
tree | db77eef572a00c62c8d9485c4786f682e20a2fd0 /pthreads/pthread_mutex_init.c | |
parent | 772373ccc8da2b2019555228f4972cc0c5a885a4 (diff) | |
download | vcxsrv-88101146f2ec7d53ffb793e365f05097ffd35fd3.tar.gz vcxsrv-88101146f2ec7d53ffb793e365f05097ffd35fd3.tar.bz2 vcxsrv-88101146f2ec7d53ffb793e365f05097ffd35fd3.zip |
cvs version of pthreads
Diffstat (limited to 'pthreads/pthread_mutex_init.c')
-rw-r--r-- | pthreads/pthread_mutex_init.c | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/pthreads/pthread_mutex_init.c b/pthreads/pthread_mutex_init.c index cff8e5054..daf805e5b 100644 --- a/pthreads/pthread_mutex_init.c +++ b/pthreads/pthread_mutex_init.c @@ -49,27 +49,28 @@ pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr) return EINVAL; } - if (attr != NULL - && *attr != NULL && (*attr)->pshared == PTHREAD_PROCESS_SHARED) + if (attr != NULL && *attr != NULL) { - /* - * Creating mutex that can be shared between - * processes. - */ + if ((*attr)->pshared == PTHREAD_PROCESS_SHARED) + { + /* + * Creating mutex that can be shared between + * processes. + */ #if _POSIX_THREAD_PROCESS_SHARED >= 0 - /* - * Not implemented yet. - */ + /* + * Not implemented yet. + */ #error ERROR [__FILE__, line __LINE__]: Process shared mutexes are not supported yet. #else - return ENOSYS; + return ENOSYS; #endif /* _POSIX_THREAD_PROCESS_SHARED */ - + } } mx = (pthread_mutex_t) calloc (1, sizeof (*mx)); @@ -82,8 +83,33 @@ pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr) { mx->lock_idx = 0; mx->recursive_count = 0; - mx->kind = (attr == NULL || *attr == NULL - ? PTHREAD_MUTEX_DEFAULT : (*attr)->kind); + mx->robustNode = NULL; + if (attr == NULL || *attr == NULL) + { + mx->kind = PTHREAD_MUTEX_DEFAULT; + } + else + { + mx->kind = (*attr)->kind; + if ((*attr)->robustness == PTHREAD_MUTEX_ROBUST) + { + /* + * Use the negative range to represent robust types. + * Replaces a memory fetch with a register negate and incr + * in pthread_mutex_lock etc. + * + * Map 0,1,..,n to -1,-2,..,(-n)-1 + */ + mx->kind = -mx->kind - 1; + + mx->robustNode = (ptw32_robust_node_t*) malloc(sizeof(ptw32_robust_node_t)); + mx->robustNode->stateInconsistent = PTW32_ROBUST_CONSISTENT; + mx->robustNode->mx = mx; + mx->robustNode->next = NULL; + mx->robustNode->prev = NULL; + } + } + mx->ownerThread.p = NULL; mx->event = CreateEvent (NULL, PTW32_FALSE, /* manual reset = No */ |