annotate src/thread/symbian/SDL_syssem.cpp @ 4127:6cb18cf1777e SDL-1.2

Updated gcc-fat.sh to build on Mac OS X 10.5
author Sam Lantinga <slouken@libsdl.org>
date Mon, 31 Dec 2007 00:03:33 +0000
parents e85e65aec22f
children a1b03ba2fcd0
rev   line source
3975
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 Library General Public License for more details.
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@devolution.com
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 /*
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 SDL_syssem.cpp
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 Epoc version by Markus Mertama (w@iki.fi)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #ifdef SAVE_RCSID
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 static char rcsid =
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 "@(#) $Id: SDL_syssem.c,v 1.1.2.4 2000/06/22 15:24:48 hercules Exp $";
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 /* Semaphore functions using the Win32 API */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 //#include <stdio.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 //#include <stdlib.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include <e32std.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #include "SDL_error.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #include "SDL_thread.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #define SDL_MUTEX_TIMEOUT -2
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 struct SDL_semaphore
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 TInt handle;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 TInt count;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 };
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 #ifndef EKA2
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 extern TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 TInt value = *((TInt*) aPtr2);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 /* Create a semaphore */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 RSemaphore s;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 TInt status = CreateUnique(NewSema, &s, &initial_value);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 if(status != KErrNone)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 SDL_SetError("Couldn't create semaphore");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 sem->handle = s.Handle();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 sem->count = initial_value;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 return(sem);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 /* Free the semaphore */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 void SDL_DestroySemaphore(SDL_sem *sem)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 if ( sem )
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 RSemaphore sema;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 sema.SetHandle(sem->handle);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 while(--sem->count)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 sema.Signal();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 sema.Close();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 delete sem;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 sem = NULL;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 #ifndef EKA2
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 struct TInfo
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 TInfo(TInt aTime, TInt aHandle) :
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 iTime(aTime), iHandle(aHandle), iVal(0) {}
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 TInt iTime;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 TInt iHandle;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 TInt iVal;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 };
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 TBool ThreadRun(TAny* aInfo)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 TInfo* info = STATIC_CAST(TInfo*, aInfo);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 User::After(info->iTime);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 RSemaphore sema;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 sema.SetHandle(info->iHandle);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 sema.Signal();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 info->iVal = SDL_MUTEX_TIMEOUT;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 return 0;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 void _WaitAll(SDL_sem *sem)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 //since SemTryWait may changed the counter.
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 //this may not be atomic, but hopes it works.
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 RSemaphore sema;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 sema.SetHandle(sem->handle);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 sema.Wait();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 while(sem->count < 0)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 sema.Wait();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 if ( ! sem ) {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 SDL_SetError("Passed a NULL sem");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 return -1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 if ( timeout == SDL_MUTEX_MAXWAIT )
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 _WaitAll(sem);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 return SDL_MUTEX_MAXWAIT;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 #ifdef EKA2
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 RSemaphore sema;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 sema.SetHandle(sem->handle);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 if(KErrNone == sema.Wait(timeout))
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 return 0;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 return -1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 #else
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 RThread thread;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 TInfo* info = new (ELeave)TInfo(timeout, sem->handle);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 TInt status = CreateUnique(NewThread, &thread, info);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 if(status != KErrNone)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 return status;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 thread.Resume();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 _WaitAll(sem);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 if(thread.ExitType() == EExitPending)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 thread.Kill(SDL_MUTEX_TIMEOUT);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 thread.Close();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 return info->iVal;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 int SDL_SemTryWait(SDL_sem *sem)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 if(sem->count > 0)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 sem->count--;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 return SDL_MUTEX_TIMEOUT;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 int SDL_SemWait(SDL_sem *sem)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 /* Returns the current count of the semaphore */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 Uint32 SDL_SemValue(SDL_sem *sem)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 if ( ! sem ) {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 SDL_SetError("Passed a NULL sem");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 return 0;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 return sem->count;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 int SDL_SemPost(SDL_sem *sem)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 if ( ! sem ) {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 SDL_SetError("Passed a NULL sem");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 return -1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 sem->count++;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 RSemaphore sema;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 sema.SetHandle(sem->handle);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 sema.Signal();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 return 0;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 }