Mercurial > sdl-ios-xcode
annotate src/thread/os2/SDL_sysmutex.c @ 4204:976bc19f8f6b SDL-1.2
1.2 Quartz video: Ripped out QuickDraw and QuickTime.
Now we use the software path for YUV, and CoreGraphics for 2D stuff.
There are several other 10.6 fixes in here, too...now we can build a 64-bit
SDL for Snow Leopard!
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 21 Sep 2009 06:08:23 +0000 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
1190 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
1190 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
1190 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
1190 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
13 Lesser General Public License for more details. |
1190 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1190 | 18 |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
22 #include "SDL_config.h" |
1190 | 23 |
24 /* Mutex functions using the OS/2 API */ | |
25 | |
26 #define INCL_DOSERRORS | |
27 #define INCL_DOSSEMAPHORES | |
28 #include <os2.h> | |
29 | |
30 #include "SDL_mutex.h" | |
31 | |
32 | |
33 struct SDL_mutex { | |
34 HMTX hmtxID; | |
35 }; | |
36 | |
37 /* Create a mutex */ | |
38 DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void) | |
39 { | |
40 SDL_mutex *mutex; | |
41 APIRET ulrc; | |
42 | |
43 /* Allocate mutex memory */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
44 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); |
1190 | 45 if (mutex) |
46 { | |
47 /* Create the mutex, with initial value signaled */ | |
48 ulrc = DosCreateMutexSem(NULL, // Create unnamed semaphore | |
49 &(mutex->hmtxID), // Pointer to handle | |
50 0L, // Flags: create it private (not shared) | |
51 FALSE); // Initial value: unowned | |
52 if (ulrc!=NO_ERROR) | |
53 { | |
54 SDL_SetError("Couldn't create mutex"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
55 SDL_free(mutex); |
1190 | 56 mutex = NULL; |
57 } | |
58 } else { | |
59 SDL_OutOfMemory(); | |
60 } | |
61 return(mutex); | |
62 } | |
63 | |
64 /* Free the mutex */ | |
65 DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex) | |
66 { | |
67 if ( mutex ) | |
68 { | |
69 if ( mutex->hmtxID ) | |
70 { | |
71 DosCloseMutexSem(mutex->hmtxID); | |
72 mutex->hmtxID = 0; | |
73 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
74 SDL_free(mutex); |
1190 | 75 } |
76 } | |
77 | |
78 /* Lock the mutex */ | |
79 DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex) | |
80 { | |
81 if ( mutex == NULL ) | |
82 { | |
83 SDL_SetError("Passed a NULL mutex"); | |
84 return -1; | |
85 } | |
86 if ( DosRequestMutexSem(mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR ) | |
87 { | |
88 SDL_SetError("Couldn't wait on mutex"); | |
89 return -1; | |
90 } | |
91 return(0); | |
92 } | |
93 | |
94 /* Unlock the mutex */ | |
95 DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex) | |
96 { | |
97 if ( mutex == NULL ) | |
98 { | |
99 SDL_SetError("Passed a NULL mutex"); | |
100 return -1; | |
101 } | |
102 if ( DosReleaseMutexSem(mutex->hmtxID) != NO_ERROR ) | |
103 { | |
104 SDL_SetError("Couldn't release mutex"); | |
105 return -1; | |
106 } | |
107 return(0); | |
108 } |