diff options
Diffstat (limited to 'apps/plugins/sdl/src/thread/dc')
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_syscond.c | 215 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_syscond_c.h | 23 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_sysmutex.c | 122 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_sysmutex_c.h | 23 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_syssem.c | 173 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_syssem_c.h | 23 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_systhread.c | 60 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/dc/SDL_systhread_c.h | 24 |
8 files changed, 0 insertions, 663 deletions
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_syscond.c b/apps/plugins/sdl/src/thread/dc/SDL_syscond.c deleted file mode 100644 index f6e7223e3d..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_syscond.c +++ /dev/null | |||
@@ -1,215 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
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 | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* An implementation of condition variables using semaphores and mutexes */ | ||
25 | /* | ||
26 | This implementation borrows heavily from the BeOS condition variable | ||
27 | implementation, written by Christopher Tate and Owen Smith. Thanks! | ||
28 | */ | ||
29 | |||
30 | #include "SDL_thread.h" | ||
31 | |||
32 | struct SDL_cond | ||
33 | { | ||
34 | SDL_mutex *lock; | ||
35 | int waiting; | ||
36 | int signals; | ||
37 | SDL_sem *wait_sem; | ||
38 | SDL_sem *wait_done; | ||
39 | }; | ||
40 | |||
41 | /* Create a condition variable */ | ||
42 | SDL_cond * SDL_CreateCond(void) | ||
43 | { | ||
44 | SDL_cond *cond; | ||
45 | |||
46 | cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); | ||
47 | if ( cond ) { | ||
48 | cond->lock = SDL_CreateMutex(); | ||
49 | cond->wait_sem = SDL_CreateSemaphore(0); | ||
50 | cond->wait_done = SDL_CreateSemaphore(0); | ||
51 | cond->waiting = cond->signals = 0; | ||
52 | if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) { | ||
53 | SDL_DestroyCond(cond); | ||
54 | cond = NULL; | ||
55 | } | ||
56 | } else { | ||
57 | SDL_OutOfMemory(); | ||
58 | } | ||
59 | return(cond); | ||
60 | } | ||
61 | |||
62 | /* Destroy a condition variable */ | ||
63 | void SDL_DestroyCond(SDL_cond *cond) | ||
64 | { | ||
65 | if ( cond ) { | ||
66 | if ( cond->wait_sem ) { | ||
67 | SDL_DestroySemaphore(cond->wait_sem); | ||
68 | } | ||
69 | if ( cond->wait_done ) { | ||
70 | SDL_DestroySemaphore(cond->wait_done); | ||
71 | } | ||
72 | if ( cond->lock ) { | ||
73 | SDL_DestroyMutex(cond->lock); | ||
74 | } | ||
75 | SDL_free(cond); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /* Restart one of the threads that are waiting on the condition variable */ | ||
80 | int SDL_CondSignal(SDL_cond *cond) | ||
81 | { | ||
82 | if ( ! cond ) { | ||
83 | SDL_SetError("Passed a NULL condition variable"); | ||
84 | return -1; | ||
85 | } | ||
86 | |||
87 | /* If there are waiting threads not already signalled, then | ||
88 | signal the condition and wait for the thread to respond. | ||
89 | */ | ||
90 | SDL_LockMutex(cond->lock); | ||
91 | if ( cond->waiting > cond->signals ) { | ||
92 | ++cond->signals; | ||
93 | SDL_SemPost(cond->wait_sem); | ||
94 | SDL_UnlockMutex(cond->lock); | ||
95 | SDL_SemWait(cond->wait_done); | ||
96 | } else { | ||
97 | SDL_UnlockMutex(cond->lock); | ||
98 | } | ||
99 | |||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | /* Restart all threads that are waiting on the condition variable */ | ||
104 | int SDL_CondBroadcast(SDL_cond *cond) | ||
105 | { | ||
106 | if ( ! cond ) { | ||
107 | SDL_SetError("Passed a NULL condition variable"); | ||
108 | return -1; | ||
109 | } | ||
110 | |||
111 | /* If there are waiting threads not already signalled, then | ||
112 | signal the condition and wait for the thread to respond. | ||
113 | */ | ||
114 | SDL_LockMutex(cond->lock); | ||
115 | if ( cond->waiting > cond->signals ) { | ||
116 | int i, num_waiting; | ||
117 | |||
118 | num_waiting = (cond->waiting - cond->signals); | ||
119 | cond->signals = cond->waiting; | ||
120 | for ( i=0; i<num_waiting; ++i ) { | ||
121 | SDL_SemPost(cond->wait_sem); | ||
122 | } | ||
123 | /* Now all released threads are blocked here, waiting for us. | ||
124 | Collect them all (and win fabulous prizes!) :-) | ||
125 | */ | ||
126 | SDL_UnlockMutex(cond->lock); | ||
127 | for ( i=0; i<num_waiting; ++i ) { | ||
128 | SDL_SemWait(cond->wait_done); | ||
129 | } | ||
130 | } else { | ||
131 | SDL_UnlockMutex(cond->lock); | ||
132 | } | ||
133 | |||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | /* Wait on the condition variable for at most 'ms' milliseconds. | ||
138 | The mutex must be locked before entering this function! | ||
139 | The mutex is unlocked during the wait, and locked again after the wait. | ||
140 | |||
141 | Typical use: | ||
142 | |||
143 | Thread A: | ||
144 | SDL_LockMutex(lock); | ||
145 | while ( ! condition ) { | ||
146 | SDL_CondWait(cond); | ||
147 | } | ||
148 | SDL_UnlockMutex(lock); | ||
149 | |||
150 | Thread B: | ||
151 | SDL_LockMutex(lock); | ||
152 | ... | ||
153 | condition = true; | ||
154 | ... | ||
155 | SDL_UnlockMutex(lock); | ||
156 | */ | ||
157 | int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) | ||
158 | { | ||
159 | int retval; | ||
160 | |||
161 | if ( ! cond ) { | ||
162 | SDL_SetError("Passed a NULL condition variable"); | ||
163 | return -1; | ||
164 | } | ||
165 | |||
166 | /* Obtain the protection mutex, and increment the number of waiters. | ||
167 | This allows the signal mechanism to only perform a signal if there | ||
168 | are waiting threads. | ||
169 | */ | ||
170 | SDL_LockMutex(cond->lock); | ||
171 | ++cond->waiting; | ||
172 | SDL_UnlockMutex(cond->lock); | ||
173 | |||
174 | /* Unlock the mutex, as is required by condition variable semantics */ | ||
175 | SDL_UnlockMutex(mutex); | ||
176 | |||
177 | /* Wait for a signal */ | ||
178 | if ( ms == SDL_MUTEX_MAXWAIT ) { | ||
179 | retval = SDL_SemWait(cond->wait_sem); | ||
180 | } else { | ||
181 | retval = SDL_SemWaitTimeout(cond->wait_sem, ms); | ||
182 | } | ||
183 | |||
184 | /* Let the signaler know we have completed the wait, otherwise | ||
185 | the signaler can race ahead and get the condition semaphore | ||
186 | if we are stopped between the mutex unlock and semaphore wait, | ||
187 | giving a deadlock. See the following URL for details: | ||
188 | http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html | ||
189 | */ | ||
190 | SDL_LockMutex(cond->lock); | ||
191 | if ( cond->signals > 0 ) { | ||
192 | /* If we timed out, we need to eat a condition signal */ | ||
193 | if ( retval > 0 ) { | ||
194 | SDL_SemWait(cond->wait_sem); | ||
195 | } | ||
196 | /* We always notify the signal thread that we are done */ | ||
197 | SDL_SemPost(cond->wait_done); | ||
198 | |||
199 | /* Signal handshake complete */ | ||
200 | --cond->signals; | ||
201 | } | ||
202 | --cond->waiting; | ||
203 | SDL_UnlockMutex(cond->lock); | ||
204 | |||
205 | /* Lock the mutex, as is required by condition variable semantics */ | ||
206 | SDL_LockMutex(mutex); | ||
207 | |||
208 | return retval; | ||
209 | } | ||
210 | |||
211 | /* Wait on the condition variable forever */ | ||
212 | int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) | ||
213 | { | ||
214 | return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT); | ||
215 | } | ||
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_syscond_c.h b/apps/plugins/sdl/src/thread/dc/SDL_syscond_c.h deleted file mode 100644 index 1120b2d80d..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_syscond_c.h +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
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 | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_sysmutex.c b/apps/plugins/sdl/src/thread/dc/SDL_sysmutex.c deleted file mode 100644 index c6c465131b..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_sysmutex.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
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 | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* An implementation of mutexes using semaphores */ | ||
25 | |||
26 | #include "SDL_thread.h" | ||
27 | #include "SDL_systhread_c.h" | ||
28 | |||
29 | #include <arch/spinlock.h> | ||
30 | |||
31 | struct SDL_mutex { | ||
32 | int recursive; | ||
33 | Uint32 owner; | ||
34 | spinlock_t mutex; | ||
35 | }; | ||
36 | |||
37 | /* Create a mutex */ | ||
38 | SDL_mutex *SDL_CreateMutex(void) | ||
39 | { | ||
40 | SDL_mutex *mutex; | ||
41 | |||
42 | /* Allocate mutex memory */ | ||
43 | mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); | ||
44 | if ( mutex ) { | ||
45 | spinlock_init(&mutex->mutex); | ||
46 | mutex->recursive = 0; | ||
47 | mutex->owner = 0; | ||
48 | } else { | ||
49 | SDL_OutOfMemory(); | ||
50 | } | ||
51 | return mutex; | ||
52 | } | ||
53 | |||
54 | /* Free the mutex */ | ||
55 | void SDL_DestroyMutex(SDL_mutex *mutex) | ||
56 | { | ||
57 | if ( mutex ) { | ||
58 | SDL_free(mutex); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /* Lock the semaphore */ | ||
63 | int SDL_mutexP(SDL_mutex *mutex) | ||
64 | { | ||
65 | #if SDL_THREADS_DISABLED | ||
66 | return SDL_arraysize(return ),0; | ||
67 | #else | ||
68 | Uint32 this_thread; | ||
69 | |||
70 | if ( mutex == NULL ) { | ||
71 | SDL_SetError("Passed a NULL mutex"); | ||
72 | return -1; | ||
73 | } | ||
74 | |||
75 | this_thread = SDL_ThreadID(); | ||
76 | if ( mutex->owner == this_thread ) { | ||
77 | ++mutex->recursive; | ||
78 | } else { | ||
79 | /* The order of operations is important. | ||
80 | We set the locking thread id after we obtain the lock | ||
81 | so unlocks from other threads will fail. | ||
82 | */ | ||
83 | spinlock_lock(&mutex->mutex); | ||
84 | mutex->owner = this_thread; | ||
85 | mutex->recursive = 0; | ||
86 | } | ||
87 | |||
88 | return 0; | ||
89 | #endif /* SDL_THREADS_DISABLED */ | ||
90 | } | ||
91 | |||
92 | /* Unlock the mutex */ | ||
93 | int SDL_mutexV(SDL_mutex *mutex) | ||
94 | { | ||
95 | #if SDL_THREADS_DISABLED | ||
96 | return 0; | ||
97 | #else | ||
98 | if ( mutex == NULL ) { | ||
99 | SDL_SetError("Passed a NULL mutex"); | ||
100 | return -1; | ||
101 | } | ||
102 | |||
103 | /* If we don't own the mutex, we can't unlock it */ | ||
104 | if ( SDL_ThreadID() != mutex->owner ) { | ||
105 | SDL_SetError("mutex not owned by this thread"); | ||
106 | return -1; | ||
107 | } | ||
108 | |||
109 | if ( mutex->recursive ) { | ||
110 | --mutex->recursive; | ||
111 | } else { | ||
112 | /* The order of operations is important. | ||
113 | First reset the owner so another thread doesn't lock | ||
114 | the mutex and set the ownership before we reset it, | ||
115 | then release the lock semaphore. | ||
116 | */ | ||
117 | mutex->owner = 0; | ||
118 | spinlock_unlock(&mutex->mutex); | ||
119 | } | ||
120 | return 0; | ||
121 | #endif /* SDL_THREADS_DISABLED */ | ||
122 | } | ||
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_sysmutex_c.h b/apps/plugins/sdl/src/thread/dc/SDL_sysmutex_c.h deleted file mode 100644 index 1120b2d80d..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_sysmutex_c.h +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
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 | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_syssem.c b/apps/plugins/sdl/src/thread/dc/SDL_syssem.c deleted file mode 100644 index 9831ccdbd7..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_syssem.c +++ /dev/null | |||
@@ -1,173 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
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 | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | |||
23 | #include <errno.h> | ||
24 | |||
25 | #include "SDL_config.h" | ||
26 | |||
27 | /* An implementation of semaphores using mutexes and condition variables */ | ||
28 | |||
29 | #include "SDL_timer.h" | ||
30 | #include "SDL_thread.h" | ||
31 | #include "SDL_systhread_c.h" | ||
32 | |||
33 | |||
34 | #if SDL_THREADS_DISABLED | ||
35 | |||
36 | SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | ||
37 | { | ||
38 | SDL_SetError("SDL not configured with thread support"); | ||
39 | return (SDL_sem *)0; | ||
40 | } | ||
41 | |||
42 | void SDL_DestroySemaphore(SDL_sem *sem) | ||
43 | { | ||
44 | return; | ||
45 | } | ||
46 | |||
47 | int SDL_SemTryWait(SDL_sem *sem) | ||
48 | { | ||
49 | SDL_SetError("SDL not configured with thread support"); | ||
50 | return -1; | ||
51 | } | ||
52 | |||
53 | int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | ||
54 | { | ||
55 | SDL_SetError("SDL not configured with thread support"); | ||
56 | return -1; | ||
57 | } | ||
58 | |||
59 | int SDL_SemWait(SDL_sem *sem) | ||
60 | { | ||
61 | SDL_SetError("SDL not configured with thread support"); | ||
62 | return -1; | ||
63 | } | ||
64 | |||
65 | Uint32 SDL_SemValue(SDL_sem *sem) | ||
66 | { | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | int SDL_SemPost(SDL_sem *sem) | ||
71 | { | ||
72 | SDL_SetError("SDL not configured with thread support"); | ||
73 | return -1; | ||
74 | } | ||
75 | |||
76 | #else | ||
77 | |||
78 | #include <kos/sem.h> | ||
79 | |||
80 | struct SDL_semaphore | ||
81 | { | ||
82 | semaphore_t sem; | ||
83 | }; | ||
84 | |||
85 | SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | ||
86 | { | ||
87 | return (SDL_sem *)sem_create(initial_value); | ||
88 | } | ||
89 | |||
90 | /* WARNING: | ||
91 | You cannot call this function when another thread is using the semaphore. | ||
92 | */ | ||
93 | void SDL_DestroySemaphore(SDL_sem *sem) | ||
94 | { | ||
95 | if ( ! sem ) { | ||
96 | SDL_SetError("Passed a NULL semaphore"); | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | sem_destroy(&sem->sem); | ||
101 | } | ||
102 | |||
103 | int SDL_SemTryWait(SDL_sem *sem) | ||
104 | { | ||
105 | int retval; | ||
106 | |||
107 | if ( ! sem ) { | ||
108 | SDL_SetError("Passed a NULL semaphore"); | ||
109 | return -1; | ||
110 | } | ||
111 | |||
112 | retval = sem_trywait(&sem->sem); | ||
113 | if (retval==0) return 0; | ||
114 | else return SDL_MUTEX_TIMEDOUT; | ||
115 | |||
116 | return retval; | ||
117 | } | ||
118 | |||
119 | int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | ||
120 | { | ||
121 | int retval; | ||
122 | |||
123 | if ( ! sem ) { | ||
124 | SDL_SetError("Passed a NULL semaphore"); | ||
125 | return -1; | ||
126 | } | ||
127 | |||
128 | /* A timeout of 0 is an easy case */ | ||
129 | if ( timeout == 0 ) { | ||
130 | return SDL_SemTryWait(sem); | ||
131 | } | ||
132 | |||
133 | retval = sem_wait_timed(&sem->sem,timeout); | ||
134 | if (retval==-1) retval= SDL_MUTEX_TIMEDOUT; | ||
135 | |||
136 | return retval; | ||
137 | } | ||
138 | |||
139 | int SDL_SemWait(SDL_sem *sem) | ||
140 | { | ||
141 | int retval; | ||
142 | |||
143 | if ( ! sem ) { | ||
144 | SDL_SetError("Passed a NULL semaphore"); | ||
145 | return -1; | ||
146 | } | ||
147 | |||
148 | while ( ((retval = sem_wait(&sem->sem)) == -1) && (errno == EINTR) ) {} | ||
149 | return retval; | ||
150 | } | ||
151 | |||
152 | Uint32 SDL_SemValue(SDL_sem *sem) | ||
153 | { | ||
154 | if ( ! sem ) { | ||
155 | SDL_SetError("Passed a NULL semaphore"); | ||
156 | return -1; | ||
157 | } | ||
158 | |||
159 | return sem_count(&sem->sem); | ||
160 | } | ||
161 | |||
162 | int SDL_SemPost(SDL_sem *sem) | ||
163 | { | ||
164 | if ( ! sem ) { | ||
165 | SDL_SetError("Passed a NULL semaphore"); | ||
166 | return -1; | ||
167 | } | ||
168 | |||
169 | sem_signal(&sem->sem); | ||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | #endif /* SDL_THREADS_DISABLED */ | ||
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_syssem_c.h b/apps/plugins/sdl/src/thread/dc/SDL_syssem_c.h deleted file mode 100644 index 1120b2d80d..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_syssem_c.h +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
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 | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_systhread.c b/apps/plugins/sdl/src/thread/dc/SDL_systhread.c deleted file mode 100644 index dd26675491..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_systhread.c +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
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 | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | /* Thread management routines for SDL */ | ||
25 | |||
26 | #include "SDL_thread.h" | ||
27 | #include "../SDL_thread_c.h" | ||
28 | #include "../SDL_systhread.h" | ||
29 | |||
30 | #include <kos/thread.h> | ||
31 | |||
32 | int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | ||
33 | { | ||
34 | thread->handle = thd_create(SDL_RunThread,args); | ||
35 | if (thread->handle == NULL) { | ||
36 | SDL_SetError("Not enough resources to create thread"); | ||
37 | return(-1); | ||
38 | } | ||
39 | return(0); | ||
40 | } | ||
41 | |||
42 | void SDL_SYS_SetupThread(void) | ||
43 | { | ||
44 | return; | ||
45 | } | ||
46 | |||
47 | Uint32 SDL_ThreadID(void) | ||
48 | { | ||
49 | return (Uint32)thd_get_current(); | ||
50 | } | ||
51 | |||
52 | void SDL_SYS_WaitThread(SDL_Thread *thread) | ||
53 | { | ||
54 | thd_wait(thread->handle); | ||
55 | } | ||
56 | |||
57 | void SDL_SYS_KillThread(SDL_Thread *thread) | ||
58 | { | ||
59 | thd_destroy(thread->handle); | ||
60 | } | ||
diff --git a/apps/plugins/sdl/src/thread/dc/SDL_systhread_c.h b/apps/plugins/sdl/src/thread/dc/SDL_systhread_c.h deleted file mode 100644 index 3cda1a4a51..0000000000 --- a/apps/plugins/sdl/src/thread/dc/SDL_systhread_c.h +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 Sam Lantinga | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
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 | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public | ||
16 | License along with this library; if not, write to the Free | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | typedef struct kthread* SYS_ThreadHandle; | ||