Mercurial > sdl-ios-xcode
comparison src/thread/epoc/SDL_systhread.cpp @ 173:83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 11 Sep 2001 20:38:49 +0000 |
parents | |
children | e8157fcb3114 |
comparison
equal
deleted
inserted
replaced
172:37e3ca9254c7 | 173:83018110dce8 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000 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 | |
31 //#include <stdlib.h> | |
32 //#include <stdio.h> | |
33 | |
34 | |
35 extern "C" { | |
36 #undef NULL | |
37 #include "SDL_error.h" | |
38 #include "SDL_thread.h" | |
39 #include "SDL_systhread.h" | |
40 }; | |
41 | |
42 #include <e32std.h> | |
43 | |
44 | |
45 static int object_count; | |
46 | |
47 int RunThread(TAny* data) | |
48 { | |
49 SDL_RunThread(data); | |
50 return(0); | |
51 } | |
52 | |
53 | |
54 TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2) | |
55 { | |
56 return ((RThread*)(aPtr1))->Create(aName, | |
57 RunThread, | |
58 KDefaultStackSize, | |
59 NULL, | |
60 aPtr2); | |
61 } | |
62 | |
63 int CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2) | |
64 { | |
65 TBuf<16> name; | |
66 TInt status = KErrNone; | |
67 do | |
68 { | |
69 object_count++; | |
70 name.Format(_L("SDL_%x"), object_count); | |
71 status = aFunc(name, aPtr1, aPtr2); | |
72 } | |
73 while(status == KErrAlreadyExists); | |
74 return status; | |
75 } | |
76 | |
77 | |
78 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) | |
79 { | |
80 RThread rthread; | |
81 | |
82 TInt status = CreateUnique(NewThread, &rthread, args); | |
83 if (status != KErrNone) | |
84 { | |
85 delete(((RThread*)(thread->handle))); | |
86 thread->handle = NULL; | |
87 SDL_SetError("Not enough resources to create thread"); | |
88 return(-1); | |
89 } | |
90 rthread.Resume(); | |
91 thread->handle = rthread.Handle(); | |
92 return(0); | |
93 } | |
94 | |
95 void SDL_SYS_SetupThread(void) | |
96 { | |
97 return; | |
98 } | |
99 | |
100 Uint32 SDL_ThreadID(void) | |
101 { | |
102 RThread current; | |
103 TThreadId id = current.Id(); | |
104 return id; | |
105 } | |
106 | |
107 void SDL_SYS_WaitThread(SDL_Thread *thread) | |
108 { | |
109 RUndertaker taker; | |
110 taker.Create(); | |
111 TRequestStatus status; | |
112 taker.Logon(status, thread->handle); | |
113 User::WaitForRequest(status); | |
114 taker.Close(); | |
115 } | |
116 | |
117 /* WARNING: This function is really a last resort. | |
118 * Threads should be signaled and then exit by themselves. | |
119 * TerminateThread() doesn't perform stack and DLL cleanup. | |
120 */ | |
121 void SDL_SYS_KillThread(SDL_Thread *thread) | |
122 { | |
123 RThread rthread; | |
124 rthread.SetHandle(thread->handle); | |
125 rthread.Kill(0); | |
126 rthread.Close(); | |
127 } |