summaryrefslogtreecommitdiff
path: root/pthread_once.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-04-14 08:29:10 +0000
committerrpj <rpj>2005-04-14 08:29:10 +0000
commitef371a69a71cecc05ba9e29dcbc7303f918a4ea0 (patch)
tree21386700eec3d880c7dd45cd32f2f525414ef52a /pthread_once.c
parent8002ee8953f8601a4d2f82bc0c37dbb0229fc07b (diff)
''
Diffstat (limited to 'pthread_once.c')
-rw-r--r--pthread_once.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/pthread_once.c b/pthread_once.c
index 8da10d8..28d4fee 100644
--- a/pthread_once.c
+++ b/pthread_once.c
@@ -119,7 +119,7 @@ ptw32_once_init_routine_cleanup(void * arg)
{
/*
* There are waiters, wake some up
- * We're deliberately not using PulseEvent. It's iffy, and deprecated.
+ * We're deliberately not using PulseEvent. It's deprecated.
*/
SetEvent(once_control->event);
}
@@ -173,10 +173,8 @@ pthread_once (pthread_once_t * once_control, void (*init_routine) (void))
if (once_control == NULL || init_routine == NULL)
{
-
result = EINVAL;
goto FAIL0;
-
}
else
{
@@ -277,7 +275,8 @@ pthread_once (pthread_once_t * once_control, void (*init_routine) (void))
* while waiting, create an event to wait on
*/
- InterlockedIncrement((LPLONG) &once_control->eventUsers);
+ EnterCriticalSection(&ptw32_once_event_lock);
+ once_control->eventUsers++;
/*
* RE CANCELLATION:
@@ -299,7 +298,6 @@ pthread_once (pthread_once_t * once_control, void (*init_routine) (void))
* forever.
*/
- EnterCriticalSection(&ptw32_once_event_lock);
if (!once_control->event)
{
once_control->event = CreateEvent(NULL, PTW32_TRUE, PTW32_FALSE, NULL);
@@ -320,14 +318,14 @@ pthread_once (pthread_once_t * once_control, void (*init_routine) (void))
}
/* last one out shut off the lights */
- if (0 == InterlockedDecrement((LPLONG)&once_control->eventUsers))
+ EnterCriticalSection(&ptw32_once_event_lock);
+ if (0 == --once_control->eventUsers)
{
/* we were last */
- EnterCriticalSection(&ptw32_once_event_lock);
CloseHandle(once_control->event);
once_control->event = 0;
- LeaveCriticalSection(&ptw32_once_event_lock);
}
+ LeaveCriticalSection(&ptw32_once_event_lock);
}
}