misc/winutils/include/SDL_mutex.h
author bovi
Sat, 14 Jan 2012 05:03:21 +0100
changeset 6560 ca07e6be08d0
child 7809 7d4fb2f35f4f
permissions -rw-r--r--
GCI task: cmd.exe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6560
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     1
/*
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     3
    Copyright (C) 1997-2009 Sam Lantinga
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     4
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
     9
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    13
    Lesser General Public License for more details.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    14
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    18
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    19
    Sam Lantinga
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    20
    slouken@libsdl.org
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    21
*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    22
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    23
#ifndef _SDL_mutex_h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    24
#define _SDL_mutex_h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    25
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    26
/** @file SDL_mutex.h
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    27
 *  Functions to provide thread synchronization primitives
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    28
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    29
 *  @note These are independent of the other SDL routines.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    30
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    31
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    32
#include "SDL_stdinc.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    33
#include "SDL_error.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    34
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    35
#include "begin_code.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    36
/* Set up for C function definitions, even when using C++ */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    37
#ifdef __cplusplus
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    38
extern "C" {
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    39
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    40
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    41
/** Synchronization functions which can time out return this value
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    42
 *  if they time out.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    43
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    44
#define SDL_MUTEX_TIMEDOUT	1
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    45
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    46
/** This is the timeout value which corresponds to never time out */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    47
#define SDL_MUTEX_MAXWAIT	(~(Uint32)0)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    48
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    49
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    50
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    51
/** @name Mutex functions                                        */ /*@{*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    52
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    53
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    54
/** The SDL mutex structure, defined in SDL_mutex.c */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    55
struct SDL_mutex;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    56
typedef struct SDL_mutex SDL_mutex;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    57
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    58
/** Create a mutex, initialized unlocked */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    59
extern DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    60
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    61
#define SDL_LockMutex(m)	SDL_mutexP(m)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    62
/** Lock the mutex
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    63
 *  @return 0, or -1 on error
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    64
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    65
extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    66
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    67
#define SDL_UnlockMutex(m)	SDL_mutexV(m)
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    68
/** Unlock the mutex
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    69
 *  @return 0, or -1 on error
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    70
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    71
 *  It is an error to unlock a mutex that has not been locked by
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    72
 *  the current thread, and doing so results in undefined behavior.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    73
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    74
extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    75
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    76
/** Destroy a mutex */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    77
extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    78
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    79
/*@}*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    80
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    81
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    82
/** @name Semaphore functions                                    */ /*@{*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    83
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    84
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    85
/** The SDL semaphore structure, defined in SDL_sem.c */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    86
struct SDL_semaphore;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    87
typedef struct SDL_semaphore SDL_sem;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    88
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    89
/** Create a semaphore, initialized with value, returns NULL on failure. */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    90
extern DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    91
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    92
/** Destroy a semaphore */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    93
extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    94
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    95
/**
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    96
 * This function suspends the calling thread until the semaphore pointed 
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    97
 * to by sem has a positive count. It then atomically decreases the semaphore
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    98
 * count.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
    99
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   100
extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   101
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   102
/** Non-blocking variant of SDL_SemWait().
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   103
 *  @return 0 if the wait succeeds,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   104
 *  SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   105
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   106
extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   107
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   108
/** Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   109
 *  the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   110
 *  the allotted time, and -1 on error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   111
 *
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   112
 *  On some platforms this function is implemented by looping with a delay
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   113
 *  of 1 ms, and so should be avoided if possible.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   114
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   115
extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 ms);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   116
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   117
/** Atomically increases the semaphore's count (not blocking).
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   118
 *  @return 0, or -1 on error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   119
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   120
extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   121
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   122
/** Returns the current count of the semaphore */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   123
extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   124
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   125
/*@}*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   126
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   127
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   128
/** @name Condition_variable_functions                           */ /*@{*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   129
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   130
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   131
/*@{*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   132
/** The SDL condition variable structure, defined in SDL_cond.c */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   133
struct SDL_cond;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   134
typedef struct SDL_cond SDL_cond;
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   135
/*@}*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   136
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   137
/** Create a condition variable */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   138
extern DECLSPEC SDL_cond * SDLCALL SDL_CreateCond(void);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   139
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   140
/** Destroy a condition variable */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   141
extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   142
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   143
/** Restart one of the threads that are waiting on the condition variable,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   144
 *  @return 0 or -1 on error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   145
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   146
extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   147
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   148
/** Restart all threads that are waiting on the condition variable,
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   149
 *  @return 0 or -1 on error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   150
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   151
extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   152
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   153
/** Wait on the condition variable, unlocking the provided mutex.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   154
 *  The mutex must be locked before entering this function!
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   155
 *  The mutex is re-locked once the condition variable is signaled.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   156
 *  @return 0 when it is signaled, or -1 on error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   157
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   158
extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mut);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   159
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   160
/** Waits for at most 'ms' milliseconds, and returns 0 if the condition
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   161
 *  variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   162
 *  signaled in the allotted time, and -1 on error.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   163
 *  On some platforms this function is implemented by looping with a delay
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   164
 *  of 1 ms, and so should be avoided if possible.
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   165
 */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   166
extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms);
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   167
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   168
/*@}*/
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   169
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   170
/* Ends C function definitions when using C++ */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   171
#ifdef __cplusplus
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   172
}
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   173
#endif
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   174
#include "close_code.h"
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   175
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   176
#endif /* _SDL_mutex_h */
ca07e6be08d0 GCI task: cmd.exe
bovi
parents:
diff changeset
   177