src/thread/pthread/SDL_syssem.c
changeset 1627 aee7ea396f59
parent 1487 dc6b59e925a2
child 1630 eba962f9d603
     1.1 --- a/src/thread/pthread/SDL_syssem.c	Thu Apr 13 13:38:40 2006 +0000
     1.2 +++ b/src/thread/pthread/SDL_syssem.c	Thu Apr 13 14:04:13 2006 +0000
     1.3 @@ -30,15 +30,12 @@
     1.4  /* Wrapper around POSIX 1003.1b semaphores */
     1.5  
     1.6  #ifdef __MACOSX__
     1.7 -#define USE_NAMED_SEMAPHORES 1
     1.8 -#include <unistd.h>
     1.9 -#endif
    1.10 +/* Mac OS X doesn't support sem_getvalue() as of version 10.4 */
    1.11 +#include "../generic/SDL_syssem.c"
    1.12 +#else
    1.13  
    1.14  struct SDL_semaphore {
    1.15  	sem_t *sem;
    1.16 -#if !USE_NAMED_SEMAPHORES
    1.17 -	sem_t sem_data;
    1.18 -#endif
    1.19  };
    1.20  
    1.21  /* Create a semaphore, initialized with value */
    1.22 @@ -46,20 +43,6 @@
    1.23  {
    1.24  	SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
    1.25  	if ( sem ) {
    1.26 -#if USE_NAMED_SEMAPHORES
    1.27 -		static int semnum = 0;
    1.28 -		char name[32];
    1.29 -
    1.30 -		SDL_snprintf(name, SDL_arraysize(name), "/SDL_sem-%d-%4.4d", getpid(), semnum++);
    1.31 -		sem->sem = sem_open(name, O_CREAT, 0600, initial_value);
    1.32 -		if ( sem->sem == (sem_t *)SEM_FAILED ) {
    1.33 -			SDL_SetError("sem_open(%s) failed", name);
    1.34 -			SDL_free(sem);
    1.35 -			sem = NULL;
    1.36 -		} else {
    1.37 -			sem_unlink(name);
    1.38 -		}
    1.39 -#else
    1.40  		if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) {
    1.41  			SDL_SetError("sem_init() failed");
    1.42  			SDL_free(sem);
    1.43 @@ -67,7 +50,6 @@
    1.44  		} else {
    1.45  			sem->sem = &sem->sem_data;
    1.46  		}
    1.47 -#endif /* USE_NAMED_SEMAPHORES */
    1.48  	} else {
    1.49  		SDL_OutOfMemory();
    1.50  	}
    1.51 @@ -77,11 +59,7 @@
    1.52  void SDL_DestroySemaphore(SDL_sem *sem)
    1.53  {
    1.54  	if ( sem ) {
    1.55 -#if USE_NAMED_SEMAPHORES
    1.56 -		sem_close(sem->sem);
    1.57 -#else
    1.58  		sem_destroy(sem->sem);
    1.59 -#endif
    1.60  		SDL_free(sem);
    1.61  	}
    1.62  }
    1.63 @@ -135,6 +113,7 @@
    1.64  	}
    1.65  
    1.66  	/* Ack!  We have to busy wait... */
    1.67 +	/* FIXME: Use sem_timedwait()? */
    1.68  	timeout += SDL_GetTicks();
    1.69  	do {
    1.70  		retval = SDL_SemTryWait(sem);
    1.71 @@ -174,3 +153,5 @@
    1.72  	}
    1.73  	return retval;
    1.74  }
    1.75 +
    1.76 +#endif /* __MACOSX__ */