Mercurial > sdl-ios-xcode
annotate src/thread/os2/SDL_sysmutex.c @ 1338:604d73db6802
Removed uses of stdlib.h and string.h
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 09:29:18 +0000 |
parents | 3692456e7b0f |
children | c71e05b4dc2e |
rev | line source |
---|---|
1190 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1190
diff
changeset
|
3 Copyright (C) 1997-2006 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 */ | |
22 | |
23 /* Mutex functions using the OS/2 API */ | |
24 | |
25 #define INCL_DOSERRORS | |
26 #define INCL_DOSSEMAPHORES | |
27 #include <os2.h> | |
28 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
29 #include "SDL_stdlib.h" |
1190 | 30 #include "SDL_error.h" |
31 #include "SDL_mutex.h" | |
32 | |
33 | |
34 struct SDL_mutex { | |
35 HMTX hmtxID; | |
36 }; | |
37 | |
38 /* Create a mutex */ | |
39 DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void) | |
40 { | |
41 SDL_mutex *mutex; | |
42 APIRET ulrc; | |
43 | |
44 /* Allocate mutex memory */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
45 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); |
1190 | 46 if (mutex) |
47 { | |
48 /* Create the mutex, with initial value signaled */ | |
49 ulrc = DosCreateMutexSem(NULL, // Create unnamed semaphore | |
50 &(mutex->hmtxID), // Pointer to handle | |
51 0L, // Flags: create it private (not shared) | |
52 FALSE); // Initial value: unowned | |
53 if (ulrc!=NO_ERROR) | |
54 { | |
55 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
|
56 SDL_free(mutex); |
1190 | 57 mutex = NULL; |
58 } | |
59 } else { | |
60 SDL_OutOfMemory(); | |
61 } | |
62 return(mutex); | |
63 } | |
64 | |
65 /* Free the mutex */ | |
66 DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex) | |
67 { | |
68 if ( mutex ) | |
69 { | |
70 if ( mutex->hmtxID ) | |
71 { | |
72 DosCloseMutexSem(mutex->hmtxID); | |
73 mutex->hmtxID = 0; | |
74 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
75 SDL_free(mutex); |
1190 | 76 } |
77 } | |
78 | |
79 /* Lock the mutex */ | |
80 DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex) | |
81 { | |
82 if ( mutex == NULL ) | |
83 { | |
84 SDL_SetError("Passed a NULL mutex"); | |
85 return -1; | |
86 } | |
87 if ( DosRequestMutexSem(mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR ) | |
88 { | |
89 SDL_SetError("Couldn't wait on mutex"); | |
90 return -1; | |
91 } | |
92 return(0); | |
93 } | |
94 | |
95 /* Unlock the mutex */ | |
96 DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex) | |
97 { | |
98 if ( mutex == NULL ) | |
99 { | |
100 SDL_SetError("Passed a NULL mutex"); | |
101 return -1; | |
102 } | |
103 if ( DosReleaseMutexSem(mutex->hmtxID) != NO_ERROR ) | |
104 { | |
105 SDL_SetError("Couldn't release mutex"); | |
106 return -1; | |
107 } | |
108 return(0); | |
109 } |