From: Jeffrey Altman Date: Mon, 7 Feb 2011 21:44:09 +0000 (-0500) Subject: Windows: correct pthread_xxx_init semantics X-Git-Tag: openafs-devel-1_7_1~960 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=ae11ef7898ecffe8eb2a38151602572c24e32a76 Windows: correct pthread_xxx_init semantics pthread lock and conditional initialization semantics do not require that the lock structure be zeroed before pthread_xxxx_init() functions are called. Since the Windows CriticalSection initialization does require that the memory be zeroed, the pthread_xxxx_init() functions must zero the memory just in case before performing the CriticalSection initialization. Change-Id: I61e78ca7cbc10f7d4144b8efcbb38f67bb8fd695 Reviewed-on: http://gerrit.openafs.org/3904 Reviewed-by: Derrick Brashear Tested-by: BuildBot Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- diff --git a/src/WINNT/pthread/pthread.c b/src/WINNT/pthread/pthread.c index 739c7b9..6bde4f2 100644 --- a/src/WINNT/pthread/pthread.c +++ b/src/WINNT/pthread/pthread.c @@ -77,6 +77,7 @@ int pthread_mutex_init(pthread_mutex_t *mp, const pthread_mutexattr_t *attr) { int rc = 0; if ((mp != NULL) && (attr == NULL)) { + memset(mp, 0, sizeof(*mp)); InitializeCriticalSection(&mp->cs); mp->isLocked = 0; mp->tid = 0; @@ -922,6 +923,7 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { * attr parameter. */ if ((attr == NULL) && (cond != NULL)) { + memset(cond, 0, sizeof(*cond)); InitializeCriticalSection(&cond->cs); queue_Init(&cond->waiting_threads); } else { @@ -945,6 +947,10 @@ static int waiter_cache_init; static pthread_once_t waiter_cache_once = PTHREAD_ONCE_INIT; static void init_waiter_cache(void) { + if (waiter_cache_init) + return; + + memset(&waiter_cache_cs, 0, sizeof(waiter_cache_cs)); InitializeCriticalSection(&waiter_cache_cs); queue_Init(&waiter_cache); waiter_cache_init = 1;