diff src/thread/generic/SDL_syssem.c @ 1627:aee7ea396f59

Fixed bug #179 SDL_SemValue() always returns 0. That's because the underlying POSIX sem_getvalue() is implemented as a noop in Mac OS X. Apart from that, semaphores do work properly (at least according to test/testsem), so I'm not sure if this is worth fixing at all.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 13 Apr 2006 14:04:13 +0000
parents d910939febfa
children 782fd950bd46 c121d94672cb a1b03ba2fcd0
line wrap: on
line diff
--- a/src/thread/generic/SDL_syssem.c	Thu Apr 13 13:38:40 2006 +0000
+++ b/src/thread/generic/SDL_syssem.c	Thu Apr 13 14:04:13 2006 +0000
@@ -87,7 +87,7 @@
 	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
 	if ( ! sem ) {
 		SDL_OutOfMemory();
-		return(0);
+		return NULL;
 	}
 	sem->count = initial_value;
 	sem->waiters_count = 0;
@@ -96,10 +96,10 @@
 	sem->count_nonzero = SDL_CreateCond();
 	if ( ! sem->count_lock || ! sem->count_nonzero ) {
 		SDL_DestroySemaphore(sem);
-		return(0);
+		return NULL;
 	}
 
-	return(sem);
+	return sem;
 }
 
 /* WARNING:
@@ -114,9 +114,11 @@
 			SDL_Delay(10);
 		}
 		SDL_DestroyCond(sem->count_nonzero);
-		SDL_mutexP(sem->count_lock);
-		SDL_mutexV(sem->count_lock);
-		SDL_DestroyMutex(sem->count_lock);
+		if ( sem->count_lock ) {
+			SDL_mutexP(sem->count_lock);
+			SDL_mutexV(sem->count_lock);
+			SDL_DestroyMutex(sem->count_lock);
+		}
 		SDL_free(sem);
 	}
 }