diff src/thread/irix/SDL_syssem.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents ad887c988713
children 4da1ee79c9af
line wrap: on
line diff
--- a/src/thread/irix/SDL_syssem.c	Sun May 21 17:27:13 2006 +0000
+++ b/src/thread/irix/SDL_syssem.c	Sun May 28 13:04:16 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: */