include/SDL_mutex.h
changeset 0 74212992fb08
child 251 b8688cfdc232
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_mutex.h	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,163 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +#ifndef _SDL_mutex_h
    1.32 +#define _SDL_mutex_h
    1.33 +
    1.34 +/* Functions to provide thread synchronization primitives
    1.35 +
    1.36 +	These are independent of the other SDL routines.
    1.37 +*/
    1.38 +
    1.39 +#include "SDL_main.h"
    1.40 +#include "SDL_types.h"
    1.41 +
    1.42 +#include "begin_code.h"
    1.43 +/* Set up for C function definitions, even when using C++ */
    1.44 +#ifdef __cplusplus
    1.45 +extern "C" {
    1.46 +#endif
    1.47 +
    1.48 +/* Synchronization functions which can time out return this value
    1.49 +   if they time out.
    1.50 +*/
    1.51 +#define SDL_MUTEX_TIMEDOUT	1
    1.52 +
    1.53 +/* This is the timeout value which corresponds to never time out */
    1.54 +#define SDL_MUTEX_MAXWAIT	(~(Uint32)0)
    1.55 +
    1.56 +
    1.57 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    1.58 +/* Mutex functions                                               */
    1.59 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    1.60 +
    1.61 +/* The SDL mutex structure, defined in SDL_mutex.c */
    1.62 +struct SDL_mutex;
    1.63 +typedef struct SDL_mutex SDL_mutex;
    1.64 +
    1.65 +/* Create a mutex, initialized unlocked */
    1.66 +extern DECLSPEC SDL_mutex * SDL_CreateMutex(void);
    1.67 +
    1.68 +/* Lock the mutex  (Returns 0, or -1 on error) */
    1.69 +#define SDL_LockMutex(m)	SDL_mutexP(m)
    1.70 +extern DECLSPEC int SDL_mutexP(SDL_mutex *mutex);
    1.71 +
    1.72 +/* Unlock the mutex  (Returns 0, or -1 on error) */
    1.73 +#define SDL_UnlockMutex(m)	SDL_mutexV(m)
    1.74 +extern DECLSPEC int SDL_mutexV(SDL_mutex *mutex);
    1.75 +
    1.76 +/* Destroy a mutex */
    1.77 +extern DECLSPEC void SDL_DestroyMutex(SDL_mutex *mutex);
    1.78 +
    1.79 +
    1.80 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    1.81 +/* Semaphore functions                                           */
    1.82 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    1.83 +
    1.84 +/* The SDL semaphore structure, defined in SDL_sem.c */
    1.85 +struct SDL_semaphore;
    1.86 +typedef struct SDL_semaphore SDL_sem;
    1.87 +
    1.88 +/* Create a semaphore, initialized with value, returns NULL on failure. */
    1.89 +extern DECLSPEC SDL_sem * SDL_CreateSemaphore(Uint32 initial_value);
    1.90 +
    1.91 +/* Destroy a semaphore */
    1.92 +extern DECLSPEC void SDL_DestroySemaphore(SDL_sem *sem);
    1.93 +
    1.94 +/* This function suspends the calling thread until the semaphore pointed 
    1.95 + * to by sem has a positive count. It then atomically decreases the semaphore
    1.96 + * count.
    1.97 + */
    1.98 +extern DECLSPEC int SDL_SemWait(SDL_sem *sem);
    1.99 +
   1.100 +/* Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds,
   1.101 +   SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error.
   1.102 +*/
   1.103 +extern DECLSPEC int SDL_SemTryWait(SDL_sem *sem);
   1.104 +
   1.105 +/* Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if
   1.106 +   the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in
   1.107 +   the allotted time, and -1 on error.
   1.108 +   On some platforms this function is implemented by looping with a delay
   1.109 +   of 1 ms, and so should be avoided if possible.
   1.110 +*/
   1.111 +extern DECLSPEC int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms);
   1.112 +
   1.113 +/* Atomically increases the semaphore's count (not blocking), returns 0,
   1.114 +   or -1 on error.
   1.115 + */
   1.116 +extern DECLSPEC int SDL_SemPost(SDL_sem *sem);
   1.117 +
   1.118 +/* Returns the current count of the semaphore */
   1.119 +extern DECLSPEC Uint32 SDL_SemValue(SDL_sem *sem);
   1.120 +
   1.121 +
   1.122 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   1.123 +/* Condition variable functions                                  */
   1.124 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   1.125 +
   1.126 +/* The SDL condition variable structure, defined in SDL_cond.c */
   1.127 +struct SDL_cond;
   1.128 +typedef struct SDL_cond SDL_cond;
   1.129 +
   1.130 +/* Create a condition variable */
   1.131 +extern DECLSPEC SDL_cond * SDL_CreateCond(void);
   1.132 +
   1.133 +/* Destroy a condition variable */
   1.134 +extern DECLSPEC void SDL_DestroyCond(SDL_cond *cond);
   1.135 +
   1.136 +/* Restart one of the threads that are waiting on the condition variable,
   1.137 +   returns 0 or -1 on error.
   1.138 + */
   1.139 +extern DECLSPEC int SDL_CondSignal(SDL_cond *cond);
   1.140 +
   1.141 +/* Restart all threads that are waiting on the condition variable,
   1.142 +   returns 0 or -1 on error.
   1.143 + */
   1.144 +extern DECLSPEC int SDL_CondBroadcast(SDL_cond *cond);
   1.145 +
   1.146 +/* Wait on the condition variable, unlocking the provided mutex.
   1.147 +   The mutex must be locked before entering this function!
   1.148 +   Returns 0 when it is signaled, or -1 on error.
   1.149 + */
   1.150 +extern DECLSPEC int SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);
   1.151 +
   1.152 +/* Waits for at most 'ms' milliseconds, and returns 0 if the condition
   1.153 +   variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
   1.154 +   signaled in the allotted time, and -1 on error.
   1.155 +   On some platforms this function is implemented by looping with a delay
   1.156 +   of 1 ms, and so should be avoided if possible.
   1.157 +*/
   1.158 +extern DECLSPEC int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms);
   1.159 +
   1.160 +/* Ends C function definitions when using C++ */
   1.161 +#ifdef __cplusplus
   1.162 +}
   1.163 +#endif
   1.164 +#include "close_code.h"
   1.165 +
   1.166 +#endif /* _SDL_mutex_h */