diff options
Diffstat (limited to 'apps/plugins/sdl/src/thread/symbian')
-rw-r--r-- | apps/plugins/sdl/src/thread/symbian/SDL_sysmutex.cpp | 130 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/symbian/SDL_syssem.cpp | 214 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/symbian/SDL_systhread.cpp | 146 | ||||
-rw-r--r-- | apps/plugins/sdl/src/thread/symbian/SDL_systhread_c.h | 30 |
4 files changed, 520 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/thread/symbian/SDL_sysmutex.cpp b/apps/plugins/sdl/src/thread/symbian/SDL_sysmutex.cpp new file mode 100644 index 0000000000..f4b1aeaad2 --- /dev/null +++ b/apps/plugins/sdl/src/thread/symbian/SDL_sysmutex.cpp | |||
@@ -0,0 +1,130 @@ | |||
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@devolution.com | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | SDL_sysmutex.cpp | ||
25 | |||
26 | Epoc version by Markus Mertama (w@iki.fi) | ||
27 | */ | ||
28 | |||
29 | |||
30 | #ifdef SAVE_RCSID | ||
31 | static char rcsid = | ||
32 | "@(#) $Id: SDL_sysmutex.c,v 1.1.2.3 2000/06/22 15:25:23 hercules Exp $"; | ||
33 | #endif | ||
34 | |||
35 | /* Mutex functions using the Win32 API */ | ||
36 | |||
37 | //#include <stdio.h> | ||
38 | //#include <stdlib.h> | ||
39 | |||
40 | #include <e32std.h> | ||
41 | |||
42 | #include "epoc_sdl.h" | ||
43 | |||
44 | #include "SDL_error.h" | ||
45 | #include "SDL_mutex.h" | ||
46 | |||
47 | |||
48 | #ifdef EKA2 //??? | ||
49 | struct SDL_mutex | ||
50 | { | ||
51 | TInt handle; | ||
52 | }; | ||
53 | #else | ||
54 | struct _SDL_mutex | ||
55 | { | ||
56 | TInt handle; | ||
57 | }; | ||
58 | #endif | ||
59 | |||
60 | extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*); | ||
61 | |||
62 | TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*) | ||
63 | { | ||
64 | return ((RMutex*)aPtr1)->CreateGlobal(aName); | ||
65 | } | ||
66 | |||
67 | void DeleteMutex(TAny* aMutex) | ||
68 | { | ||
69 | SDL_DestroyMutex ((SDL_mutex*) aMutex); | ||
70 | } | ||
71 | |||
72 | /* Create a mutex */ | ||
73 | SDL_mutex *SDL_CreateMutex(void) | ||
74 | { | ||
75 | RMutex rmutex; | ||
76 | |||
77 | TInt status = CreateUnique(NewMutex, &rmutex, NULL); | ||
78 | if(status != KErrNone) | ||
79 | { | ||
80 | SDL_SetError("Couldn't create mutex"); | ||
81 | } | ||
82 | SDL_mutex* mutex = new /*(ELeave)*/ SDL_mutex; | ||
83 | mutex->handle = rmutex.Handle(); | ||
84 | EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem(DeleteMutex, mutex)); | ||
85 | return(mutex); | ||
86 | } | ||
87 | |||
88 | /* Free the mutex */ | ||
89 | void SDL_DestroyMutex(SDL_mutex *mutex) | ||
90 | { | ||
91 | if ( mutex ) | ||
92 | { | ||
93 | RMutex rmutex; | ||
94 | rmutex.SetHandle(mutex->handle); | ||
95 | if(rmutex.IsHeld()) | ||
96 | { | ||
97 | rmutex.Signal(); | ||
98 | } | ||
99 | rmutex.Close(); | ||
100 | EpocSdlEnv::RemoveCleanupItem(mutex); | ||
101 | delete(mutex); | ||
102 | mutex = NULL; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | /* Lock the mutex */ | ||
107 | int SDL_mutexP(SDL_mutex *mutex) | ||
108 | { | ||
109 | if ( mutex == NULL ) { | ||
110 | SDL_SetError("Passed a NULL mutex"); | ||
111 | return -1; | ||
112 | } | ||
113 | RMutex rmutex; | ||
114 | rmutex.SetHandle(mutex->handle); | ||
115 | rmutex.Wait(); | ||
116 | return(0); | ||
117 | } | ||
118 | |||
119 | /* Unlock the mutex */ | ||
120 | int SDL_mutexV(SDL_mutex *mutex) | ||
121 | { | ||
122 | if ( mutex == NULL ) { | ||
123 | SDL_SetError("Passed a NULL mutex"); | ||
124 | return -1; | ||
125 | } | ||
126 | RMutex rmutex; | ||
127 | rmutex.SetHandle(mutex->handle); | ||
128 | rmutex.Signal(); | ||
129 | return(0); | ||
130 | } | ||
diff --git a/apps/plugins/sdl/src/thread/symbian/SDL_syssem.cpp b/apps/plugins/sdl/src/thread/symbian/SDL_syssem.cpp new file mode 100644 index 0000000000..00f9901ee5 --- /dev/null +++ b/apps/plugins/sdl/src/thread/symbian/SDL_syssem.cpp | |||
@@ -0,0 +1,214 @@ | |||
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@devolution.com | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | SDL_syssem.cpp | ||
25 | |||
26 | Epoc version by Markus Mertama (w@iki.fi) | ||
27 | */ | ||
28 | |||
29 | #ifdef SAVE_RCSID | ||
30 | static char rcsid = | ||
31 | "@(#) $Id: SDL_syssem.c,v 1.1.2.4 2000/06/22 15:24:48 hercules Exp $"; | ||
32 | #endif | ||
33 | |||
34 | /* Semaphore functions using the Win32 API */ | ||
35 | |||
36 | //#include <stdio.h> | ||
37 | //#include <stdlib.h> | ||
38 | #include <e32std.h> | ||
39 | |||
40 | #include "SDL_error.h" | ||
41 | #include "SDL_thread.h" | ||
42 | |||
43 | |||
44 | #define SDL_MUTEX_TIMEOUT -2 | ||
45 | |||
46 | struct SDL_semaphore | ||
47 | { | ||
48 | TInt handle; | ||
49 | TInt count; | ||
50 | }; | ||
51 | |||
52 | |||
53 | extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*); | ||
54 | #ifndef EKA2 | ||
55 | extern TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2); | ||
56 | #endif | ||
57 | |||
58 | TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) | ||
59 | { | ||
60 | TInt value = *((TInt*) aPtr2); | ||
61 | return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value); | ||
62 | } | ||
63 | |||
64 | /* Create a semaphore */ | ||
65 | SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | ||
66 | { | ||
67 | RSemaphore s; | ||
68 | TInt status = CreateUnique(NewSema, &s, &initial_value); | ||
69 | if(status != KErrNone) | ||
70 | { | ||
71 | SDL_SetError("Couldn't create semaphore"); | ||
72 | } | ||
73 | SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore; | ||
74 | sem->handle = s.Handle(); | ||
75 | sem->count = initial_value; | ||
76 | return(sem); | ||
77 | } | ||
78 | |||
79 | /* Free the semaphore */ | ||
80 | void SDL_DestroySemaphore(SDL_sem *sem) | ||
81 | { | ||
82 | if ( sem ) | ||
83 | { | ||
84 | RSemaphore sema; | ||
85 | sema.SetHandle(sem->handle); | ||
86 | while(--sem->count) | ||
87 | sema.Signal(); | ||
88 | sema.Close(); | ||
89 | delete sem; | ||
90 | sem = NULL; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | #ifndef EKA2 | ||
95 | |||
96 | struct TInfo | ||
97 | { | ||
98 | TInfo(TInt aTime, TInt aHandle) : | ||
99 | iTime(aTime), iHandle(aHandle), iVal(0) {} | ||
100 | TInt iTime; | ||
101 | TInt iHandle; | ||
102 | TInt iVal; | ||
103 | }; | ||
104 | |||
105 | |||
106 | |||
107 | TBool ThreadRun(TAny* aInfo) | ||
108 | { | ||
109 | TInfo* info = STATIC_CAST(TInfo*, aInfo); | ||
110 | User::After(info->iTime); | ||
111 | RSemaphore sema; | ||
112 | sema.SetHandle(info->iHandle); | ||
113 | sema.Signal(); | ||
114 | info->iVal = SDL_MUTEX_TIMEOUT; | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | #endif | ||
119 | |||
120 | |||
121 | void _WaitAll(SDL_sem *sem) | ||
122 | { | ||
123 | //since SemTryWait may changed the counter. | ||
124 | //this may not be atomic, but hopes it works. | ||
125 | RSemaphore sema; | ||
126 | sema.SetHandle(sem->handle); | ||
127 | sema.Wait(); | ||
128 | while(sem->count < 0) | ||
129 | { | ||
130 | sema.Wait(); | ||
131 | } | ||
132 | } | ||
133 | |||
134 | int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | ||
135 | { | ||
136 | if ( ! sem ) { | ||
137 | SDL_SetError("Passed a NULL sem"); | ||
138 | return -1; | ||
139 | } | ||
140 | |||
141 | if ( timeout == SDL_MUTEX_MAXWAIT ) | ||
142 | { | ||
143 | _WaitAll(sem); | ||
144 | return SDL_MUTEX_MAXWAIT; | ||
145 | } | ||
146 | |||
147 | #ifdef EKA2 | ||
148 | |||
149 | RSemaphore sema; | ||
150 | sema.SetHandle(sem->handle); | ||
151 | if(KErrNone == sema.Wait(timeout)) | ||
152 | return 0; | ||
153 | return -1; | ||
154 | #else | ||
155 | RThread thread; | ||
156 | |||
157 | TInfo* info = new (ELeave)TInfo(timeout, sem->handle); | ||
158 | |||
159 | TInt status = CreateUnique(NewThread, &thread, info); | ||
160 | |||
161 | if(status != KErrNone) | ||
162 | return status; | ||
163 | |||
164 | thread.Resume(); | ||
165 | |||
166 | _WaitAll(sem); | ||
167 | |||
168 | if(thread.ExitType() == EExitPending) | ||
169 | { | ||
170 | thread.Kill(SDL_MUTEX_TIMEOUT); | ||
171 | } | ||
172 | |||
173 | thread.Close(); | ||
174 | |||
175 | return info->iVal; | ||
176 | #endif | ||
177 | } | ||
178 | |||
179 | int SDL_SemTryWait(SDL_sem *sem) | ||
180 | { | ||
181 | if(sem->count > 0) | ||
182 | { | ||
183 | sem->count--; | ||
184 | } | ||
185 | return SDL_MUTEX_TIMEOUT; | ||
186 | } | ||
187 | |||
188 | int SDL_SemWait(SDL_sem *sem) | ||
189 | { | ||
190 | return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); | ||
191 | } | ||
192 | |||
193 | /* Returns the current count of the semaphore */ | ||
194 | Uint32 SDL_SemValue(SDL_sem *sem) | ||
195 | { | ||
196 | if ( ! sem ) { | ||
197 | SDL_SetError("Passed a NULL sem"); | ||
198 | return 0; | ||
199 | } | ||
200 | return sem->count; | ||
201 | } | ||
202 | |||
203 | int SDL_SemPost(SDL_sem *sem) | ||
204 | { | ||
205 | if ( ! sem ) { | ||
206 | SDL_SetError("Passed a NULL sem"); | ||
207 | return -1; | ||
208 | } | ||
209 | sem->count++; | ||
210 | RSemaphore sema; | ||
211 | sema.SetHandle(sem->handle); | ||
212 | sema.Signal(); | ||
213 | return 0; | ||
214 | } | ||
diff --git a/apps/plugins/sdl/src/thread/symbian/SDL_systhread.cpp b/apps/plugins/sdl/src/thread/symbian/SDL_systhread.cpp new file mode 100644 index 0000000000..5e7adc5540 --- /dev/null +++ b/apps/plugins/sdl/src/thread/symbian/SDL_systhread.cpp | |||
@@ -0,0 +1,146 @@ | |||
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@devolution.com | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | SDL_systhread.cpp | ||
25 | Epoc thread management routines for SDL | ||
26 | |||
27 | Epoc version by Markus Mertama (w@iki.fi) | ||
28 | */ | ||
29 | |||
30 | #include "epoc_sdl.h" | ||
31 | |||
32 | //#include <stdlib.h> | ||
33 | //#include <stdio.h> | ||
34 | |||
35 | |||
36 | |||
37 | extern "C" { | ||
38 | #undef NULL | ||
39 | #include "SDL_error.h" | ||
40 | #include "SDL_thread.h" | ||
41 | #include "SDL_systhread.h" | ||
42 | #include "SDL_thread_c.h" | ||
43 | } | ||
44 | |||
45 | #include <e32std.h> | ||
46 | #include "epoc_sdl.h" | ||
47 | |||
48 | |||
49 | static int object_count; | ||
50 | |||
51 | int RunThread(TAny* data) | ||
52 | { | ||
53 | CTrapCleanup* cleanup = CTrapCleanup::New(); | ||
54 | TRAPD(err, SDL_RunThread(data)); | ||
55 | EpocSdlEnv::CleanupItems(); | ||
56 | delete cleanup; | ||
57 | return(err); | ||
58 | } | ||
59 | |||
60 | |||
61 | TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) | ||
62 | { | ||
63 | return ((RThread*)(aPtr1))->Create(aName, | ||
64 | RunThread, | ||
65 | KDefaultStackSize, | ||
66 | NULL, | ||
67 | aPtr2); | ||
68 | } | ||
69 | |||
70 | int CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2) | ||
71 | { | ||
72 | TBuf<16> name; | ||
73 | TInt status = KErrNone; | ||
74 | do | ||
75 | { | ||
76 | object_count++; | ||
77 | name.Format(_L("SDL_%x"), object_count); | ||
78 | status = aFunc(name, aPtr1, aPtr2); | ||
79 | } | ||
80 | while(status == KErrAlreadyExists); | ||
81 | return status; | ||
82 | } | ||
83 | |||
84 | |||
85 | int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | ||
86 | { | ||
87 | RThread rthread; | ||
88 | |||
89 | const TInt status = CreateUnique(NewThread, &rthread, args); | ||
90 | if (status != KErrNone) | ||
91 | { | ||
92 | delete(((RThread*)(thread->handle))); | ||
93 | thread->handle = NULL; | ||
94 | SDL_SetError("Not enough resources to create thread"); | ||
95 | return(-1); | ||
96 | } | ||
97 | rthread.Resume(); | ||
98 | thread->handle = rthread.Handle(); | ||
99 | return(0); | ||
100 | } | ||
101 | |||
102 | void SDL_SYS_SetupThread(void) | ||
103 | { | ||
104 | return; | ||
105 | } | ||
106 | |||
107 | Uint32 SDL_ThreadID(void) | ||
108 | { | ||
109 | RThread current; | ||
110 | const TThreadId id = current.Id(); | ||
111 | return id; | ||
112 | } | ||
113 | |||
114 | void SDL_SYS_WaitThread(SDL_Thread *thread) | ||
115 | { | ||
116 | SDL_TRACE1("Close thread", thread); | ||
117 | RThread t; | ||
118 | const TInt err = t.Open(thread->threadid); | ||
119 | if(err == KErrNone && t.ExitType() == EExitPending) | ||
120 | { | ||
121 | TRequestStatus status; | ||
122 | t.Logon(status); | ||
123 | User::WaitForRequest(status); | ||
124 | } | ||
125 | t.Close(); | ||
126 | |||
127 | /* RUndertaker taker; | ||
128 | taker.Create(); | ||
129 | TRequestStatus status; | ||
130 | taker.Logon(status, thread->handle); | ||
131 | User::WaitForRequest(status); | ||
132 | taker.Close();*/ | ||
133 | SDL_TRACE1("Closed thread", thread); | ||
134 | } | ||
135 | |||
136 | /* WARNING: This function is really a last resort. | ||
137 | * Threads should be signaled and then exit by themselves. | ||
138 | * TerminateThread() doesn't perform stack and DLL cleanup. | ||
139 | */ | ||
140 | void SDL_SYS_KillThread(SDL_Thread *thread) | ||
141 | { | ||
142 | RThread rthread; | ||
143 | rthread.SetHandle(thread->handle); | ||
144 | rthread.Kill(0); | ||
145 | rthread.Close(); | ||
146 | } | ||
diff --git a/apps/plugins/sdl/src/thread/symbian/SDL_systhread_c.h b/apps/plugins/sdl/src/thread/symbian/SDL_systhread_c.h new file mode 100644 index 0000000000..f5f1729cda --- /dev/null +++ b/apps/plugins/sdl/src/thread/symbian/SDL_systhread_c.h | |||
@@ -0,0 +1,30 @@ | |||
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@devolution.com | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | SDL_systhread_c.h | ||
25 | |||
26 | Epoc version by Markus Mertama (w@iki.fi) | ||
27 | */ | ||
28 | |||
29 | typedef int SYS_ThreadHandle; | ||
30 | |||