summaryrefslogtreecommitdiff
path: root/sem_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'sem_init.c')
-rw-r--r--sem_init.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/sem_init.c b/sem_init.c
index af0e285..fb596ae 100644
--- a/sem_init.c
+++ b/sem_init.c
@@ -128,17 +128,27 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
#else /* NEED_SEM */
s->value = value;
- s->sem = CreateSemaphore (NULL, /* Always NULL */
- (long) 0, /* Force threads to wait */
- (long) _POSIX_SEM_VALUE_MAX, /* Maximum value */
- NULL); /* Name */
-
- if (0 == s->sem)
+ if (pthread_mutex_init(&s->lock, NULL) == 0)
+ {
+ if ((s->sem = CreateSemaphore (NULL, /* Always NULL */
+ (long) 0, /* Force threads to wait */
+ (long) _POSIX_SEM_VALUE_MAX, /* Maximum value */
+ NULL)) == 0) /* Name */
+ {
+ (void) pthread_mutex_destroy(&s->lock);
+ result = ENOSPC;
+ }
+ }
+ else
{
- free (s);
result = ENOSPC;
}
+ if (result != 0)
+ {
+ free(s);
+ }
+
#endif /* NEED_SEM */
}