SDL_x11sym.h: add symbols for _XGetRequest
[sdl_omap.git] / src / thread / pth / SDL_sysmutex.c
CommitLineData
e14743d1 1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/*
25 * GNU pth mutexes
26 *
27 * Patrice Mandin
28 */
29
30#include <pth.h>
31
32#include "SDL_mutex.h"
33#include "SDL_sysmutex_c.h"
34
35/* Create a mutex */
36SDL_mutex *SDL_CreateMutex(void)
37{
38 SDL_mutex *mutex;
39
40 /* Allocate mutex memory */
41 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
42 if ( mutex ) {
43 /* Create the mutex, with initial value signaled */
44 if (!pth_mutex_init(&(mutex->mutexpth_p))) {
45 SDL_SetError("Couldn't create mutex");
46 SDL_free(mutex);
47 mutex = NULL;
48 }
49 } else {
50 SDL_OutOfMemory();
51 }
52 return(mutex);
53}
54
55/* Free the mutex */
56void SDL_DestroyMutex(SDL_mutex *mutex)
57{
58 if ( mutex ) {
59 SDL_free(mutex);
60 }
61}
62
63/* Lock the mutex */
64int SDL_mutexP(SDL_mutex *mutex)
65{
66 if ( mutex == NULL ) {
67 SDL_SetError("Passed a NULL mutex");
68 return -1;
69 }
70
71 pth_mutex_acquire(&(mutex->mutexpth_p), FALSE, NULL);
72
73 return(0);
74}
75
76/* Unlock the mutex */
77int SDL_mutexV(SDL_mutex *mutex)
78{
79 if ( mutex == NULL ) {
80 SDL_SetError("Passed a NULL mutex");
81 return -1;
82 }
83
84 pth_mutex_release(&(mutex->mutexpth_p));
85
86 return(0);
87}