src/thread/win32/SDL_sysmutex.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1433 bb6839704ed6
child 1668 4da1ee79c9af
     1.1 --- a/src/thread/win32/SDL_sysmutex.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/thread/win32/SDL_sysmutex.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -29,67 +29,74 @@
     1.4  #include "SDL_mutex.h"
     1.5  
     1.6  
     1.7 -struct SDL_mutex {
     1.8 -	HANDLE id;
     1.9 +struct SDL_mutex
    1.10 +{
    1.11 +    HANDLE id;
    1.12  };
    1.13  
    1.14  /* Create a mutex */
    1.15 -SDL_mutex *SDL_CreateMutex(void)
    1.16 +SDL_mutex *
    1.17 +SDL_CreateMutex (void)
    1.18  {
    1.19 -	SDL_mutex *mutex;
    1.20 +    SDL_mutex *mutex;
    1.21  
    1.22 -	/* Allocate mutex memory */
    1.23 -	mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
    1.24 -	if ( mutex ) {
    1.25 -		/* Create the mutex, with initial value signaled */
    1.26 -		mutex->id = CreateMutex(NULL, FALSE, NULL);
    1.27 -		if ( ! mutex->id ) {
    1.28 -			SDL_SetError("Couldn't create mutex");
    1.29 -			SDL_free(mutex);
    1.30 -			mutex = NULL;
    1.31 -		}
    1.32 -	} else {
    1.33 -		SDL_OutOfMemory();
    1.34 -	}
    1.35 -	return(mutex);
    1.36 +    /* Allocate mutex memory */
    1.37 +    mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex));
    1.38 +    if (mutex) {
    1.39 +        /* Create the mutex, with initial value signaled */
    1.40 +        mutex->id = CreateMutex (NULL, FALSE, NULL);
    1.41 +        if (!mutex->id) {
    1.42 +            SDL_SetError ("Couldn't create mutex");
    1.43 +            SDL_free (mutex);
    1.44 +            mutex = NULL;
    1.45 +        }
    1.46 +    } else {
    1.47 +        SDL_OutOfMemory ();
    1.48 +    }
    1.49 +    return (mutex);
    1.50  }
    1.51  
    1.52  /* Free the mutex */
    1.53 -void SDL_DestroyMutex(SDL_mutex *mutex)
    1.54 +void
    1.55 +SDL_DestroyMutex (SDL_mutex * mutex)
    1.56  {
    1.57 -	if ( mutex ) {
    1.58 -		if ( mutex->id ) {
    1.59 -			CloseHandle(mutex->id);
    1.60 -			mutex->id = 0;
    1.61 -		}
    1.62 -		SDL_free(mutex);
    1.63 -	}
    1.64 +    if (mutex) {
    1.65 +        if (mutex->id) {
    1.66 +            CloseHandle (mutex->id);
    1.67 +            mutex->id = 0;
    1.68 +        }
    1.69 +        SDL_free (mutex);
    1.70 +    }
    1.71  }
    1.72  
    1.73  /* Lock the mutex */
    1.74 -int SDL_mutexP(SDL_mutex *mutex)
    1.75 +int
    1.76 +SDL_mutexP (SDL_mutex * mutex)
    1.77  {
    1.78 -	if ( mutex == NULL ) {
    1.79 -		SDL_SetError("Passed a NULL mutex");
    1.80 -		return -1;
    1.81 -	}
    1.82 -	if ( WaitForSingleObject(mutex->id, INFINITE) == WAIT_FAILED ) {
    1.83 -		SDL_SetError("Couldn't wait on mutex");
    1.84 -		return -1;
    1.85 -	}
    1.86 -	return(0);
    1.87 +    if (mutex == NULL) {
    1.88 +        SDL_SetError ("Passed a NULL mutex");
    1.89 +        return -1;
    1.90 +    }
    1.91 +    if (WaitForSingleObject (mutex->id, INFINITE) == WAIT_FAILED) {
    1.92 +        SDL_SetError ("Couldn't wait on mutex");
    1.93 +        return -1;
    1.94 +    }
    1.95 +    return (0);
    1.96  }
    1.97  
    1.98  /* Unlock the mutex */
    1.99 -int SDL_mutexV(SDL_mutex *mutex)
   1.100 +int
   1.101 +SDL_mutexV (SDL_mutex * mutex)
   1.102  {
   1.103 -	if ( mutex == NULL ) {
   1.104 -		SDL_SetError("Passed a NULL mutex");
   1.105 -		return -1;
   1.106 -	}
   1.107 -	if ( ReleaseMutex(mutex->id) == FALSE ) {
   1.108 -		SDL_SetError("Couldn't release mutex");
   1.109 -		return -1;
   1.110 -	}
   1.111 -	return(0);
   1.112 +    if (mutex == NULL) {
   1.113 +        SDL_SetError ("Passed a NULL mutex");
   1.114 +        return -1;
   1.115 +    }
   1.116 +    if (ReleaseMutex (mutex->id) == FALSE) {
   1.117 +        SDL_SetError ("Couldn't release mutex");
   1.118 +        return -1;
   1.119 +    }
   1.120 +    return (0);
   1.121  }
   1.122 +
   1.123 +/* vi: set ts=4 sw=4 expandtab: */