src/thread/pthread/SDL_syssem.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1630 eba962f9d603
child 1668 4da1ee79c9af
--- a/src/thread/pthread/SDL_syssem.c	Sun May 21 17:27:13 2006 +0000
+++ b/src/thread/pthread/SDL_syssem.c	Sun May 28 13:04:16 2006 +0000
@@ -34,122 +34,132 @@
 #include "../generic/SDL_syssem.c"
 #else
 
-struct SDL_semaphore {
-	sem_t sem;
+struct SDL_semaphore
+{
+    sem_t sem;
 };
 
 /* Create a semaphore, initialized with value */
-SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
+SDL_sem *
+SDL_CreateSemaphore (Uint32 initial_value)
 {
-	SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
-	if ( sem ) {
-		if ( sem_init(&sem->sem, 0, initial_value) < 0 ) {
-			SDL_SetError("sem_init() failed");
-			SDL_free(sem);
-			sem = NULL;
-		}
-	} else {
-		SDL_OutOfMemory();
-	}
-	return sem;
+    SDL_sem *sem = (SDL_sem *) SDL_malloc (sizeof (SDL_sem));
+    if (sem) {
+        if (sem_init (&sem->sem, 0, initial_value) < 0) {
+            SDL_SetError ("sem_init() failed");
+            SDL_free (sem);
+            sem = NULL;
+        }
+    } else {
+        SDL_OutOfMemory ();
+    }
+    return sem;
 }
 
-void SDL_DestroySemaphore(SDL_sem *sem)
+void
+SDL_DestroySemaphore (SDL_sem * sem)
 {
-	if ( sem ) {
-		sem_destroy(&sem->sem);
-		SDL_free(sem);
-	}
+    if (sem) {
+        sem_destroy (&sem->sem);
+        SDL_free (sem);
+    }
 }
 
-int SDL_SemTryWait(SDL_sem *sem)
+int
+SDL_SemTryWait (SDL_sem * sem)
 {
-	int retval;
+    int retval;
 
-	if ( ! sem ) {
-		SDL_SetError("Passed a NULL semaphore");
-		return -1;
-	}
-	retval = SDL_MUTEX_TIMEDOUT;
-	if ( sem_trywait(&sem->sem) == 0 ) {
-		retval = 0;
-	}
-	return retval;
+    if (!sem) {
+        SDL_SetError ("Passed a NULL semaphore");
+        return -1;
+    }
+    retval = SDL_MUTEX_TIMEDOUT;
+    if (sem_trywait (&sem->sem) == 0) {
+        retval = 0;
+    }
+    return retval;
 }
 
-int SDL_SemWait(SDL_sem *sem)
+int
+SDL_SemWait (SDL_sem * sem)
 {
-	int retval;
+    int retval;
 
-	if ( ! sem ) {
-		SDL_SetError("Passed a NULL semaphore");
-		return -1;
-	}
+    if (!sem) {
+        SDL_SetError ("Passed a NULL semaphore");
+        return -1;
+    }
 
-	retval = sem_wait(&sem->sem);
-	if ( retval < 0 ) {
-		SDL_SetError("sem_wait() failed");
-	}
-	return retval;
+    retval = sem_wait (&sem->sem);
+    if (retval < 0) {
+        SDL_SetError ("sem_wait() failed");
+    }
+    return retval;
 }
 
-int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
+int
+SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout)
 {
-	int retval;
+    int retval;
 
-	if ( ! sem ) {
-		SDL_SetError("Passed a NULL semaphore");
-		return -1;
-	}
+    if (!sem) {
+        SDL_SetError ("Passed a NULL semaphore");
+        return -1;
+    }
 
-	/* Try the easy cases first */
-	if ( timeout == 0 ) {
-		return SDL_SemTryWait(sem);
-	}
-	if ( timeout == SDL_MUTEX_MAXWAIT ) {
-		return SDL_SemWait(sem);
-	}
+    /* Try the easy cases first */
+    if (timeout == 0) {
+        return SDL_SemTryWait (sem);
+    }
+    if (timeout == SDL_MUTEX_MAXWAIT) {
+        return SDL_SemWait (sem);
+    }
 
-	/* Ack!  We have to busy wait... */
-	/* FIXME: Use sem_timedwait()? */
-	timeout += SDL_GetTicks();
-	do {
-		retval = SDL_SemTryWait(sem);
-		if ( retval == 0 ) {
-			break;
-		}
-		SDL_Delay(1);
-	} while ( SDL_GetTicks() < timeout );
+    /* Ack!  We have to busy wait... */
+    /* FIXME: Use sem_timedwait()? */
+    timeout += SDL_GetTicks ();
+    do {
+        retval = SDL_SemTryWait (sem);
+        if (retval == 0) {
+            break;
+        }
+        SDL_Delay (1);
+    }
+    while (SDL_GetTicks () < timeout);
 
-	return retval;
+    return retval;
 }
 
-Uint32 SDL_SemValue(SDL_sem *sem)
+Uint32
+SDL_SemValue (SDL_sem * sem)
 {
-	int ret = 0;
-	if ( sem ) {
-		sem_getvalue(&sem->sem, &ret);
-		if ( ret < 0 ) {
-			ret = 0;
-		}
-	}
-	return (Uint32)ret;
+    int ret = 0;
+    if (sem) {
+        sem_getvalue (&sem->sem, &ret);
+        if (ret < 0) {
+            ret = 0;
+        }
+    }
+    return (Uint32) ret;
 }
 
-int SDL_SemPost(SDL_sem *sem)
+int
+SDL_SemPost (SDL_sem * sem)
 {
-	int retval;
+    int retval;
 
-	if ( ! sem ) {
-		SDL_SetError("Passed a NULL semaphore");
-		return -1;
-	}
+    if (!sem) {
+        SDL_SetError ("Passed a NULL semaphore");
+        return -1;
+    }
 
-	retval = sem_post(&sem->sem);
-	if ( retval < 0 ) {
-		SDL_SetError("sem_post() failed");
-	}
-	return retval;
+    retval = sem_post (&sem->sem);
+    if (retval < 0) {
+        SDL_SetError ("sem_post() failed");
+    }
+    return retval;
 }
 
 #endif /* __MACOSX__ */
+/* vi: set ts=4 sw=4 expandtab: */