diff src/thread/irix/SDL_syssem.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents ad887c988713
children e27bdcc80744 204be4fc2726
line wrap: on
line diff
--- a/src/thread/irix/SDL_syssem.c	Thu Jul 06 18:01:37 2006 +0000
+++ b/src/thread/irix/SDL_syssem.c	Mon Jul 10 21:04:37 2006 +0000
@@ -36,8 +36,9 @@
 #include "SDL_thread.h"
 
 
-struct SDL_semaphore {
-	int id;
+struct SDL_semaphore
+{
+    int id;
 };
 
 /* Not defined by many operating systems, use configure to detect */
@@ -52,168 +53,178 @@
 */
 
 static struct sembuf op_trywait[2] = {
-	{ 0, -1, (IPC_NOWAIT|SEM_UNDO) } /* Decrement semaphore, no block */
+    {0, -1, (IPC_NOWAIT | SEM_UNDO)}    /* Decrement semaphore, no block */
 };
 static struct sembuf op_wait[2] = {
-	{ 0, -1, SEM_UNDO }		/* Decrement semaphore */
+    {0, -1, SEM_UNDO}           /* Decrement semaphore */
 };
 static struct sembuf op_post[1] = {
-	{ 0, 1, (IPC_NOWAIT|SEM_UNDO) }	/* Increment semaphore */
+    {0, 1, (IPC_NOWAIT | SEM_UNDO)}     /* Increment semaphore */
 };
 
 /* Create a blockable semaphore */
-SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
+SDL_sem *
+SDL_CreateSemaphore(Uint32 initial_value)
 {
-	extern int _creating_thread_lock;	/* SDL_threads.c */
-	SDL_sem *sem;
-	union semun init;
+    extern int _creating_thread_lock;   /* SDL_threads.c */
+    SDL_sem *sem;
+    union semun init;
 
-	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
-	if ( sem == NULL ) {
-		SDL_OutOfMemory();
-		return(NULL);
-	}
-	sem->id = semget(IPC_PRIVATE, 1, (0600|IPC_CREAT));
-	if ( sem->id < 0 ) {
-		SDL_SetError("Couldn't create semaphore");
-		SDL_free(sem);
-		return(NULL);
-	}
-	init.val = initial_value;	/* Initialize semaphore */
-	semctl(sem->id, 0, SETVAL, init);
-	return(sem);
+    sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
+    if (sem == NULL) {
+        SDL_OutOfMemory();
+        return (NULL);
+    }
+    sem->id = semget(IPC_PRIVATE, 1, (0600 | IPC_CREAT));
+    if (sem->id < 0) {
+        SDL_SetError("Couldn't create semaphore");
+        SDL_free(sem);
+        return (NULL);
+    }
+    init.val = initial_value;   /* Initialize semaphore */
+    semctl(sem->id, 0, SETVAL, init);
+    return (sem);
 }
 
-void SDL_DestroySemaphore(SDL_sem *sem)
+void
+SDL_DestroySemaphore(SDL_sem * sem)
 {
-	if ( sem ) {
+    if (sem) {
 #ifdef __IRIX__
-		semctl(sem->id, 0, IPC_RMID);
+        semctl(sem->id, 0, IPC_RMID);
 #else
-		union semun dummy;
-		dummy.val = 0;
-		semctl(sem->id, 0, IPC_RMID, dummy);
+        union semun dummy;
+        dummy.val = 0;
+        semctl(sem->id, 0, IPC_RMID, dummy);
 #endif
-		SDL_free(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;
-	}
+    if (!sem) {
+        SDL_SetError("Passed a NULL semaphore");
+        return -1;
+    }
 
-	retval = 0;
+    retval = 0;
   tryagain:
-	if ( semop(sem->id, op_trywait, 1) < 0 ) {
-		if ( errno == EINTR ) {
-			goto tryagain;
-		}
-		retval = SDL_MUTEX_TIMEDOUT;
-	}
-	return retval;
+    if (semop(sem->id, op_trywait, 1) < 0) {
+        if (errno == EINTR) {
+            goto tryagain;
+        }
+        retval = SDL_MUTEX_TIMEDOUT;
+    }
+    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 = 0;
+    retval = 0;
   tryagain:
-	if ( semop(sem->id, op_wait, 1) < 0 ) {
-		if ( errno == EINTR ) {
-			goto tryagain;
-		}
-		SDL_SetError("Semaphore operation error");
-		retval = -1;
-	}
-	return retval;
+    if (semop(sem->id, op_wait, 1) < 0) {
+        if (errno == EINTR) {
+            goto tryagain;
+        }
+        SDL_SetError("Semaphore operation error");
+        retval = -1;
+    }
+    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... */
-	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... */
+    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 semval;
-	Uint32 value;
-	
-	value = 0;
-	if ( sem ) {
-	  tryagain:
+    int semval;
+    Uint32 value;
+
+    value = 0;
+    if (sem) {
+      tryagain:
 #ifdef __IRIX__
-		semval = semctl(sem->id, 0, GETVAL);
+        semval = semctl(sem->id, 0, GETVAL);
 #else
-		{
-		union semun arg;
-		arg.val = 0;
-		semval = semctl(sem->id, 0, GETVAL, arg);
-		}
+        {
+            union semun arg;
+            arg.val = 0;
+            semval = semctl(sem->id, 0, GETVAL, arg);
+        }
 #endif
-		if ( semval < 0 ) {
-			if ( errno == EINTR ) {
-				goto tryagain;
-			}
-		} else {
-			value = (Uint32)semval;
-		}
-	}
-	return value;
+        if (semval < 0) {
+            if (errno == EINTR) {
+                goto tryagain;
+            }
+        } else {
+            value = (Uint32) semval;
+        }
+    }
+    return value;
 }
 
-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 = 0;
+    retval = 0;
   tryagain:
-	if ( semop(sem->id, op_post, 1) < 0 ) {
-		if ( errno == EINTR ) {
-			goto tryagain;
-		}
-		SDL_SetError("Semaphore operation error");
-		retval = -1;
-	}
-	return retval;
+    if (semop(sem->id, op_post, 1) < 0) {
+        if (errno == EINTR) {
+            goto tryagain;
+        }
+        SDL_SetError("Semaphore operation error");
+        retval = -1;
+    }
+    return retval;
 }
+
+/* vi: set ts=4 sw=4 expandtab: */