Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
93 lines (76 loc) · 2.04 KB

SDL_sysmutex.c

File metadata and controls

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