Mercurial > sdl-ios-xcode
annotate src/thread/os2/SDL_sysmutex.c @ 1330:450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 06 Feb 2006 08:28:51 +0000 |
parents | c9b51268668f |
children | 3692456e7b0f |
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 #include <stdio.h> | |
26 #include <stdlib.h> | |
27 #define INCL_DOSERRORS | |
28 #define INCL_DOSSEMAPHORES | |
29 #include <os2.h> | |
30 | |
31 #include "SDL_error.h" | |
32 #include "SDL_mutex.h" | |
33 | |
34 | |
35 struct SDL_mutex { | |
36 HMTX hmtxID; | |
37 }; | |
38 | |
39 /* Create a mutex */ | |
40 DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void) | |
41 { | |
42 SDL_mutex *mutex; | |
43 APIRET ulrc; | |
44 | |
45 /* Allocate mutex memory */ | |
46 mutex = (SDL_mutex *)malloc(sizeof(*mutex)); | |
47 if (mutex) | |
48 { | |
49 /* Create the mutex, with initial value signaled */ | |
50 ulrc = DosCreateMutexSem(NULL, // Create unnamed semaphore | |
51 &(mutex->hmtxID), // Pointer to handle | |
52 0L, // Flags: create it private (not shared) | |
53 FALSE); // Initial value: unowned | |
54 if (ulrc!=NO_ERROR) | |
55 { | |
56 SDL_SetError("Couldn't create mutex"); | |
57 free(mutex); | |
58 mutex = NULL; | |
59 } | |
60 } else { | |
61 SDL_OutOfMemory(); | |
62 } | |
63 return(mutex); | |
64 } | |
65 | |
66 /* Free the mutex */ | |
67 DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex) | |
68 { | |
69 if ( mutex ) | |
70 { | |
71 if ( mutex->hmtxID ) | |
72 { | |
73 DosCloseMutexSem(mutex->hmtxID); | |
74 mutex->hmtxID = 0; | |
75 } | |
76 free(mutex); | |
77 } | |
78 } | |
79 | |
80 /* Lock the mutex */ | |
81 DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex) | |
82 { | |
83 if ( mutex == NULL ) | |
84 { | |
85 SDL_SetError("Passed a NULL mutex"); | |
86 return -1; | |
87 } | |
88 if ( DosRequestMutexSem(mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR ) | |
89 { | |
90 SDL_SetError("Couldn't wait on mutex"); | |
91 return -1; | |
92 } | |
93 return(0); | |
94 } | |
95 | |
96 /* Unlock the mutex */ | |
97 DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex) | |
98 { | |
99 if ( mutex == NULL ) | |
100 { | |
101 SDL_SetError("Passed a NULL mutex"); | |
102 return -1; | |
103 } | |
104 if ( DosReleaseMutexSem(mutex->hmtxID) != NO_ERROR ) | |
105 { | |
106 SDL_SetError("Couldn't release mutex"); | |
107 return -1; | |
108 } | |
109 return(0); | |
110 } |