include/SDL_mutex.h
author Ryan C. Gordon <icculus@icculus.org>
Tue, 15 Dec 2009 18:00:16 +0000
changeset 3567 fb9ea4b549c3
parent 3407 d3baf5ac4e37
child 3697 f7b03b6838cb
permissions -rw-r--r--
Added a warning comment to SDL_putenv().

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