Mercurial > sdl-ios-xcode
annotate src/thread/amigaos/SDL_syssem.c @ 1613:2095da6364c9
Fixed building DLL on Windows
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 25 Mar 2006 20:40:30 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb |
rev | line source |
---|---|
0 | 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:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 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:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 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:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
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:
769
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:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
21
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
24 /* An implementation of semaphores using mutexes and condition variables */ |
0 | 25 |
26 #include "SDL_thread.h" | |
27 #include "SDL_systhread_c.h" | |
28 | |
29 | |
30 struct SDL_semaphore | |
31 { | |
32 struct SignalSemaphore Sem; | |
33 }; | |
34 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
35 #undef D |
0 | 36 |
37 #define D(x) | |
38 | |
39 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | |
40 { | |
41 SDL_sem *sem; | |
42 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
43 sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
44 |
0 | 45 if ( ! sem ) { |
46 SDL_OutOfMemory(); | |
47 return(0); | |
48 } | |
49 | |
50 D(bug("Creating semaphore %lx...\n",sem)); | |
51 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
52 SDL_memset(sem,0,sizeof(*sem)); |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
53 |
0 | 54 InitSemaphore(&sem->Sem); |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
55 |
0 | 56 return(sem); |
57 } | |
58 | |
59 void SDL_DestroySemaphore(SDL_sem *sem) | |
60 { | |
61 D(bug("Destroying semaphore %lx...\n",sem)); | |
62 | |
63 if ( sem ) { | |
64 // Condizioni per liberare i task in attesa? | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
65 SDL_free(sem); |
0 | 66 } |
67 } | |
68 | |
69 int SDL_SemTryWait(SDL_sem *sem) | |
70 { | |
71 if ( ! sem ) { | |
72 SDL_SetError("Passed a NULL semaphore"); | |
73 return -1; | |
74 } | |
75 | |
76 D(bug("TryWait semaphore...%lx\n",sem)); | |
77 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
78 ObtainSemaphore(&sem->Sem); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
79 // ReleaseSemaphore(&sem->Sem); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
80 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
81 return 1; |
0 | 82 } |
83 | |
84 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | |
85 { | |
86 int retval; | |
87 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
88 |
0 | 89 if ( ! sem ) { |
90 SDL_SetError("Passed a NULL semaphore"); | |
91 return -1; | |
92 } | |
93 | |
94 D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem)); | |
95 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
96 /* A timeout of 0 is an easy case */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
97 if ( timeout == 0 ) { |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
98 ObtainSemaphore(&sem->Sem); |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
99 return 1; |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
100 } |
0 | 101 if(!(retval=AttemptSemaphore(&sem->Sem))) |
102 { | |
103 SDL_Delay(timeout); | |
104 retval=AttemptSemaphore(&sem->Sem); | |
105 } | |
106 | |
107 if(retval==TRUE) | |
108 { | |
109 // ReleaseSemaphore(&sem->Sem); | |
110 retval=1; | |
111 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
112 |
0 | 113 return retval; |
114 } | |
115 | |
116 int SDL_SemWait(SDL_sem *sem) | |
117 { | |
118 ObtainSemaphore(&sem->Sem); | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
119 return 0; |
0 | 120 } |
121 | |
122 Uint32 SDL_SemValue(SDL_sem *sem) | |
123 { | |
124 Uint32 value; | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
125 |
0 | 126 value = 0; |
127 if ( sem ) { | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
128 #ifdef STORMC4_WOS |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
129 value = sem->Sem.ssppc_SS.ss_NestCount; |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
130 #else |
0 | 131 value = sem->Sem.ss_NestCount; |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
132 #endif |
0 | 133 } |
134 return value; | |
135 } | |
136 | |
137 int SDL_SemPost(SDL_sem *sem) | |
138 { | |
139 if ( ! sem ) { | |
140 SDL_SetError("Passed a NULL semaphore"); | |
141 return -1; | |
142 } | |
143 D(bug("SemPost semaphore...%lx\n",sem)); | |
144 | |
145 ReleaseSemaphore(&sem->Sem); | |
146 return 0; | |
147 } | |
148 |