Mercurial > sdl-ios-xcode
annotate src/thread/amigaos/SDL_syssem.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | c71e05b4dc2e |
children | d910939febfa |
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 */ |
22 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
23 /* An implementation of semaphores using mutexes and condition variables */ |
0 | 24 |
25 #include "SDL_thread.h" | |
26 #include "SDL_systhread_c.h" | |
27 | |
28 | |
29 struct SDL_semaphore | |
30 { | |
31 struct SignalSemaphore Sem; | |
32 }; | |
33 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
34 #undef D |
0 | 35 |
36 #define D(x) | |
37 | |
38 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | |
39 { | |
40 SDL_sem *sem; | |
41 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
42 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
|
43 |
0 | 44 if ( ! sem ) { |
45 SDL_OutOfMemory(); | |
46 return(0); | |
47 } | |
48 | |
49 D(bug("Creating semaphore %lx...\n",sem)); | |
50 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
51 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
|
52 |
0 | 53 InitSemaphore(&sem->Sem); |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
54 |
0 | 55 return(sem); |
56 } | |
57 | |
58 void SDL_DestroySemaphore(SDL_sem *sem) | |
59 { | |
60 D(bug("Destroying semaphore %lx...\n",sem)); | |
61 | |
62 if ( sem ) { | |
63 // 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
|
64 SDL_free(sem); |
0 | 65 } |
66 } | |
67 | |
68 int SDL_SemTryWait(SDL_sem *sem) | |
69 { | |
70 if ( ! sem ) { | |
71 SDL_SetError("Passed a NULL semaphore"); | |
72 return -1; | |
73 } | |
74 | |
75 D(bug("TryWait semaphore...%lx\n",sem)); | |
76 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
77 ObtainSemaphore(&sem->Sem); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
78 // ReleaseSemaphore(&sem->Sem); |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
79 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
80 return 1; |
0 | 81 } |
82 | |
83 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | |
84 { | |
85 int retval; | |
86 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
87 |
0 | 88 if ( ! sem ) { |
89 SDL_SetError("Passed a NULL semaphore"); | |
90 return -1; | |
91 } | |
92 | |
93 D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem)); | |
94 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
95 /* 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
|
96 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
|
97 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
|
98 return 1; |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
99 } |
0 | 100 if(!(retval=AttemptSemaphore(&sem->Sem))) |
101 { | |
102 SDL_Delay(timeout); | |
103 retval=AttemptSemaphore(&sem->Sem); | |
104 } | |
105 | |
106 if(retval==TRUE) | |
107 { | |
108 // ReleaseSemaphore(&sem->Sem); | |
109 retval=1; | |
110 } | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
111 |
0 | 112 return retval; |
113 } | |
114 | |
115 int SDL_SemWait(SDL_sem *sem) | |
116 { | |
117 ObtainSemaphore(&sem->Sem); | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
118 return 0; |
0 | 119 } |
120 | |
121 Uint32 SDL_SemValue(SDL_sem *sem) | |
122 { | |
123 Uint32 value; | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
124 |
0 | 125 value = 0; |
126 if ( sem ) { | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
127 #ifdef STORMC4_WOS |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
128 value = sem->Sem.ssppc_SS.ss_NestCount; |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
129 #else |
0 | 130 value = sem->Sem.ss_NestCount; |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
131 #endif |
0 | 132 } |
133 return value; | |
134 } | |
135 | |
136 int SDL_SemPost(SDL_sem *sem) | |
137 { | |
138 if ( ! sem ) { | |
139 SDL_SetError("Passed a NULL semaphore"); | |
140 return -1; | |
141 } | |
142 D(bug("SemPost semaphore...%lx\n",sem)); | |
143 | |
144 ReleaseSemaphore(&sem->Sem); | |
145 return 0; | |
146 } | |
147 |