0
|
1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32\kernel\skernel.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <kernel/kern_priv.h>
|
|
19 |
#include "execs.h"
|
|
20 |
|
|
21 |
#define iMState iWaitLink.iSpare1 // Allow a sensible name to be used for iMState
|
|
22 |
|
|
23 |
#ifdef BTRACE_SYMBIAN_KERNEL_SYNC
|
|
24 |
#define BTRACE_KS(sub,obj) {BTraceContext4(BTrace::ESymbianKernelSync, (sub), (obj));}
|
|
25 |
#define COND_BTRACE_KS(cond,sub,obj) if (cond) {BTraceContext4(BTrace::ESymbianKernelSync, (sub), (obj));}
|
|
26 |
#define BTRACE_KS2(sub,obj1,obj2) {BTraceContext8(BTrace::ESymbianKernelSync, (sub), (obj1), (obj2));}
|
|
27 |
#define COND_BTRACE_KS2(cond,sub,obj1,obj2) if (cond) {BTraceContext4(BTrace::ESymbianKernelSync, (sub), (obj1), (obj2));}
|
|
28 |
#define BTRACE_KSC(sub) {TKName n; Name(n); BTraceContextN(BTrace::ESymbianKernelSync, (sub), this, iOwner, n.Ptr(), n.Size());}
|
|
29 |
#define COND_BTRACE_KSC(cond,sub) if (cond) {TKName n; Name(n); BTraceContextN(BTrace::ESymbianKernelSync, (sub), this, iOwner, n.Ptr(), n.Size());}
|
|
30 |
#else
|
|
31 |
#define BTRACE_KS(sub,obj)
|
|
32 |
#define COND_BTRACE_KS(cond,sub,obj)
|
|
33 |
#define BTRACE_KS2(sub,obj1,obj2)
|
|
34 |
#define COND_BTRACE_KS2(cond,sub,obj1,obj2)
|
|
35 |
#define BTRACE_KSC(sub)
|
|
36 |
#define COND_BTRACE_KSC(cond,sub)
|
|
37 |
#endif
|
|
38 |
|
|
39 |
|
|
40 |
/********************************************
|
|
41 |
* Semaphore
|
|
42 |
********************************************/
|
|
43 |
|
|
44 |
// Enter and return with system unlocked.
|
|
45 |
DSemaphore::~DSemaphore()
|
|
46 |
{
|
|
47 |
NKern::LockSystem();
|
|
48 |
Reset();
|
|
49 |
BTRACE_KS(BTrace::ESemaphoreDestroy, this);
|
|
50 |
NKern::UnlockSystem();
|
|
51 |
}
|
|
52 |
|
|
53 |
// Enter and return with system unlocked.
|
|
54 |
TInt DSemaphore::Create(DObject* aOwner, const TDesC* aName, TInt aInitialCount, TBool aVisible)
|
|
55 |
{
|
|
56 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("DSemaphore::Create owner %O, name %lS, init count=%d, visible=%d",aOwner,aName,aInitialCount,aVisible));
|
|
57 |
if (aInitialCount<0)
|
|
58 |
return KErrArgument;
|
|
59 |
SetOwner(aOwner);
|
|
60 |
TInt r=KErrNone;
|
|
61 |
if (aName && aName->Length())
|
|
62 |
{
|
|
63 |
r=SetName(aName);
|
|
64 |
if (r!=KErrNone)
|
|
65 |
return r;
|
|
66 |
}
|
|
67 |
iCount=aInitialCount;
|
|
68 |
r = iWaitQ.Construct();
|
|
69 |
if (r==KErrNone && aVisible)
|
|
70 |
r=K::AddObject(this,ESemaphore);
|
|
71 |
COND_BTRACE_KSC(r==KErrNone, BTrace::ESemaphoreCreate);
|
|
72 |
return r;
|
|
73 |
}
|
|
74 |
|
|
75 |
// Wait for semaphore with timeout
|
|
76 |
// Enter with system locked, return with system unlocked.
|
|
77 |
TInt DSemaphore::Wait(TInt aNTicks)
|
|
78 |
{
|
|
79 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O Wait %d Timeout %d",this,iCount,aNTicks));
|
|
80 |
__ASSERT_DEBUG(TheCurrentThread->iMState==DThread::EReady,K::Fault(K::ESemWaitBadState));
|
|
81 |
__ASSERT_DEBUG(!TheCurrentThread->iWaitObj,K::Fault(K::ESemWaitBadWaitObj));
|
|
82 |
TInt r=KErrNone;
|
|
83 |
if (iResetting)
|
|
84 |
r=KErrGeneral;
|
|
85 |
else if (--iCount<0)
|
|
86 |
{
|
|
87 |
DThread* pC=TheCurrentThread;
|
|
88 |
pC->iMState=DThread::EWaitSemaphore;
|
|
89 |
pC->iWaitObj=this;
|
|
90 |
iWaitQ.Add(pC);
|
|
91 |
BTRACE_KS(BTrace::ESemaphoreBlock, this);
|
|
92 |
r=NKern::Block(aNTicks,NKern::ERelease,SYSTEM_LOCK);
|
|
93 |
__ASSERT_DEBUG(pC->iMState==DThread::EReady,K::Fault(K::ESemWaitBadState));
|
|
94 |
COND_BTRACE_KS(r==KErrNone, BTrace::ESemaphoreAcquire, this);
|
|
95 |
return r;
|
|
96 |
}
|
|
97 |
#ifdef BTRACE_SYMBIAN_KERNEL_SYNC
|
|
98 |
else
|
|
99 |
BTRACE_KS(BTrace::ESemaphoreAcquire, this);
|
|
100 |
#endif
|
|
101 |
NKern::UnlockSystem();
|
|
102 |
return r;
|
|
103 |
}
|
|
104 |
|
|
105 |
// Enter with system locked, return with system unlocked.
|
|
106 |
void DSemaphore::Signal()
|
|
107 |
{
|
|
108 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O Signal %d",this,iCount));
|
|
109 |
__ASSERT_DEBUG(TheCurrentThread->iMState==DThread::EReady,K::Fault(K::ESemSignalBadState));
|
|
110 |
COND_BTRACE_KS(!iResetting, BTrace::ESemaphoreRelease, this);
|
|
111 |
if (!iResetting && ++iCount<=0)
|
|
112 |
{
|
|
113 |
DThread* pT=iWaitQ.First();
|
|
114 |
iWaitQ.Remove(pT);
|
|
115 |
pT->iMState=DThread::EReady;
|
|
116 |
pT->iWaitObj=NULL;
|
|
117 |
#if defined(_DEBUG) && !defined(__SMP__)
|
|
118 |
// For crazy scheduler: if next thread is same priority as current, let it run
|
|
119 |
// Check before releasing it in case it preempts us and exits
|
|
120 |
TBool yield = EFalse;
|
|
121 |
if (TheSuperPage().KernelConfigFlags() & EKernelConfigCrazyScheduling
|
|
122 |
&& NCurrentThread()->iPriority == pT->iNThread.iPriority)
|
|
123 |
yield = ETrue;
|
|
124 |
#endif
|
|
125 |
NKern::ThreadRelease(&pT->iNThread,0,SYSTEM_LOCK);
|
|
126 |
#if defined(_DEBUG) && !defined(__SMP__)
|
|
127 |
// Actually do the yield
|
|
128 |
if (yield)
|
|
129 |
NKern::YieldTimeslice();
|
|
130 |
#endif
|
|
131 |
return;
|
|
132 |
}
|
|
133 |
NKern::UnlockSystem();
|
|
134 |
}
|
|
135 |
|
|
136 |
// Enter and return with system locked.
|
|
137 |
void DSemaphore::SignalN(TInt aCount)
|
|
138 |
{
|
|
139 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O SignalN(%d) %d",this,aCount,iCount));
|
|
140 |
__ASSERT_DEBUG(TheCurrentThread->iMState==DThread::EReady,K::Fault(K::ESemSignalBadState));
|
|
141 |
if (iResetting)
|
|
142 |
return;
|
|
143 |
if (iCount<0 && aCount>0)
|
|
144 |
{
|
|
145 |
while(aCount--)
|
|
146 |
{
|
|
147 |
BTRACE_KS(BTrace::ESemaphoreRelease, this);
|
|
148 |
if (++iCount<=0)
|
|
149 |
{
|
|
150 |
DThread* pT=iWaitQ.First();
|
|
151 |
iWaitQ.Remove(pT);
|
|
152 |
pT->iMState=DThread::EReady;
|
|
153 |
pT->iWaitObj=NULL;
|
|
154 |
#if defined(_DEBUG) && !defined(__SMP__)
|
|
155 |
// For crazy scheduler: if next thread is same priority as current, let it run
|
|
156 |
// Check before releasing it in case it preempts us and exits
|
|
157 |
TBool yield = EFalse;
|
|
158 |
if (TheSuperPage().KernelConfigFlags() & EKernelConfigCrazyScheduling
|
|
159 |
&& NCurrentThread()->iPriority == pT->iNThread.iPriority)
|
|
160 |
yield = ETrue;
|
|
161 |
#endif
|
|
162 |
NKern::ThreadRelease(&pT->iNThread,0,SYSTEM_LOCK);
|
|
163 |
#if defined(_DEBUG) && !defined(__SMP__)
|
|
164 |
// Actually do the yield
|
|
165 |
if (yield)
|
|
166 |
NKern::YieldTimeslice();
|
|
167 |
#endif
|
|
168 |
NKern::LockSystem();
|
|
169 |
if (iResetting)
|
|
170 |
return;
|
|
171 |
}
|
|
172 |
else
|
|
173 |
{
|
|
174 |
iCount+=aCount;
|
|
175 |
break;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
}
|
|
179 |
else if (aCount>0)
|
|
180 |
iCount+=aCount;
|
|
181 |
}
|
|
182 |
|
|
183 |
// Enter and return with system locked.
|
|
184 |
void DSemaphore::Reset()
|
|
185 |
{
|
|
186 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O Reset %d",this,iCount));
|
|
187 |
if (iResetting)
|
|
188 |
return;
|
|
189 |
iResetting = TRUE;
|
|
190 |
|
|
191 |
// We release the waiting threads before the suspended threads.
|
|
192 |
// Other code relies on this.
|
|
193 |
while(iCount<0)
|
|
194 |
{
|
|
195 |
iCount++;
|
|
196 |
DThread* pT=iWaitQ.First();
|
|
197 |
iWaitQ.Remove(pT);
|
|
198 |
pT->iMState=DThread::EReady;
|
|
199 |
pT->iWaitObj=NULL;
|
|
200 |
NKern::ThreadRelease(&pT->iNThread,KErrGeneral,SYSTEM_LOCK);
|
|
201 |
NKern::LockSystem();
|
|
202 |
}
|
|
203 |
while (!iSuspendedQ.IsEmpty())
|
|
204 |
{
|
|
205 |
DThread* pT=_LOFF(iSuspendedQ.First()->Deque(),DThread,iWaitLink);
|
|
206 |
pT->iMState=DThread::EReady;
|
|
207 |
pT->iWaitObj=NULL;
|
|
208 |
NKern::ThreadRelease(&pT->iNThread,KErrGeneral,SYSTEM_LOCK);
|
|
209 |
NKern::LockSystem();
|
|
210 |
}
|
|
211 |
iResetting = FALSE;
|
|
212 |
iCount=0;
|
|
213 |
}
|
|
214 |
|
|
215 |
// Enter and return with system locked.
|
|
216 |
void DSemaphore::WaitCancel(DThread* aThread)
|
|
217 |
{
|
|
218 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O WaitCancel(%O) %d",this,aThread,iCount));
|
|
219 |
iWaitQ.Remove(aThread);
|
|
220 |
++iCount;
|
|
221 |
}
|
|
222 |
|
|
223 |
// Enter and return with system locked.
|
|
224 |
void DSemaphore::WaitCancelSuspended(DThread* aThread)
|
|
225 |
{
|
|
226 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O WaitCanSusp(%O) %d",this,aThread,iCount));
|
|
227 |
aThread->iWaitLink.Deque();
|
|
228 |
}
|
|
229 |
|
|
230 |
// Enter and return with system locked.
|
|
231 |
void DSemaphore::SuspendWaitingThread(DThread* aThread)
|
|
232 |
{
|
|
233 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O SuspWait(%O) %d",this,aThread,iCount));
|
|
234 |
++iCount;
|
|
235 |
iWaitQ.Remove(aThread);
|
|
236 |
iSuspendedQ.Add(&aThread->iWaitLink); // OK if resetting since suspended queue is processed after wait queue
|
|
237 |
aThread->iMState=DThread::EWaitSemaphoreSuspended;
|
|
238 |
}
|
|
239 |
|
|
240 |
// Enter and return with system locked.
|
|
241 |
void DSemaphore::ResumeWaitingThread(DThread* aThread)
|
|
242 |
{
|
|
243 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O ResumeWait(%O) %d",this,aThread,iCount));
|
|
244 |
aThread->iWaitLink.Deque();
|
|
245 |
if (!iResetting && --iCount<0)
|
|
246 |
{
|
|
247 |
iWaitQ.Add(aThread);
|
|
248 |
aThread->iMState=DThread::EWaitSemaphore;
|
|
249 |
}
|
|
250 |
else
|
|
251 |
{
|
|
252 |
aThread->iMState=DThread::EReady;
|
|
253 |
aThread->iWaitObj=NULL;
|
|
254 |
NKern::ThreadRelease(&aThread->iNThread,iResetting?KErrGeneral:KErrNone);
|
|
255 |
}
|
|
256 |
}
|
|
257 |
|
|
258 |
// Enter and return with system locked.
|
|
259 |
void DSemaphore::ChangeWaitingThreadPriority(DThread* aThread, TInt aNewPriority)
|
|
260 |
{
|
|
261 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Semaphore %O ChangeWaitPri(%O,%d)",this,aThread,aNewPriority));
|
|
262 |
iWaitQ.ChangePriority(aThread,aNewPriority);
|
|
263 |
}
|
|
264 |
|
|
265 |
/********************************************
|
|
266 |
* Mutex
|
|
267 |
********************************************/
|
|
268 |
inline TThreadMutexCleanup::TThreadMutexCleanup(DMutex* aMutex)
|
|
269 |
: iMutex(aMutex)
|
|
270 |
{}
|
|
271 |
|
|
272 |
// Enter and return with system locked.
|
|
273 |
void TThreadMutexCleanup::Cleanup()
|
|
274 |
{
|
|
275 |
__KTRACE_OPT(KTHREAD,Kern::Printf("TThreadCleanup::Cleanup Free mutex %O",iMutex));
|
|
276 |
if (iMutex->iResetting)
|
|
277 |
{
|
|
278 |
iMutex->iCleanup.Remove();
|
|
279 |
iMutex->iCleanup.iThread=NULL;
|
|
280 |
#ifdef _DEBUG
|
|
281 |
iMutex->iOrderLink.Deque();
|
|
282 |
#endif
|
|
283 |
}
|
|
284 |
else
|
|
285 |
{
|
|
286 |
iMutex->iHoldCount=1;
|
|
287 |
iMutex->Signal();
|
|
288 |
NKern::LockSystem();
|
|
289 |
}
|
|
290 |
}
|
|
291 |
|
|
292 |
|
|
293 |
DMutex::DMutex()
|
|
294 |
: iCleanup(this)
|
|
295 |
{}
|
|
296 |
|
|
297 |
// Enter and return with system unlocked.
|
|
298 |
DMutex::~DMutex()
|
|
299 |
{
|
|
300 |
NKern::LockSystem();
|
|
301 |
Reset();
|
|
302 |
BTRACE_KS(BTrace::EMutexDestroy, this);
|
|
303 |
NKern::UnlockSystem();
|
|
304 |
}
|
|
305 |
|
|
306 |
// Enter and return with system unlocked.
|
|
307 |
TInt DMutex::Create(DObject* aOwner, const TDesC* aName, TBool aVisible, TUint aOrder)
|
|
308 |
{
|
|
309 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("DMutex::Create owner %O, name %lS, visible=%d, order=%02x",aOwner,aName,aVisible,aOrder));
|
|
310 |
iOrder = (TUint8)aOrder;
|
|
311 |
SetOwner(aOwner);
|
|
312 |
TInt r=KErrNone;
|
|
313 |
if (aName && aName->Length())
|
|
314 |
{
|
|
315 |
r=SetName(aName);
|
|
316 |
if (r!=KErrNone)
|
|
317 |
return r;
|
|
318 |
}
|
|
319 |
r = iWaitQ.Construct();
|
|
320 |
if (r==KErrNone && aVisible)
|
|
321 |
r=K::AddObject(this,EMutex);
|
|
322 |
COND_BTRACE_KSC(r==KErrNone, BTrace::EMutexCreate);
|
|
323 |
return r;
|
|
324 |
}
|
|
325 |
#ifdef _DEBUG
|
|
326 |
extern const SNThreadHandlers EpocThreadHandlers;
|
|
327 |
#endif
|
|
328 |
|
|
329 |
// Enter and return with system locked.
|
|
330 |
TInt DMutex::Wait()
|
|
331 |
{
|
|
332 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O Wait hold %O hldc=%d wtc=%d",this,iCleanup.iThread,iHoldCount,iWaitCount));
|
|
333 |
__ASSERT_SYSTEM_LOCK;
|
|
334 |
__ASSERT_DEBUG(NCurrentThread()->iHandlers==&EpocThreadHandlers, K::Fault(K::EMutexWaitNotDThread));
|
|
335 |
DThread* pC=TheCurrentThread;
|
|
336 |
__ASSERT_DEBUG(pC->iMState==DThread::EReady,K::Fault(K::EMutexWaitBadState));
|
|
337 |
__ASSERT_DEBUG(!pC->iWaitObj,K::Fault(K::EMutexWaitBadWaitObj));
|
|
338 |
#ifdef _DEBUG
|
|
339 |
SDblQue& ml = pC->iMutexList;
|
|
340 |
DMutex* m = ml.IsEmpty() ? NULL : _LOFF(ml.First(), DMutex, iOrderLink);
|
|
341 |
TUint last_mutex_order = m ? m->iOrder : KMutexOrdNone;
|
|
342 |
if (iCleanup.iThread!=pC && iOrder<KMutexOrdUser && iOrder>=last_mutex_order)
|
|
343 |
{
|
|
344 |
__KTRACE_OPT(KPANIC,Kern::Printf("Mutex ordering violation: holding mutex %O (%08x) order %d, trying to acquire mutex %O (%08x) order %d",m,m,last_mutex_order,this,this,iOrder));
|
|
345 |
K::Fault(K::EMutexOrderingViolation);
|
|
346 |
}
|
|
347 |
#endif
|
|
348 |
while(!iResetting && iCleanup.iThread)
|
|
349 |
{
|
|
350 |
if (iCleanup.iThread==pC)
|
|
351 |
{
|
|
352 |
++iHoldCount;
|
|
353 |
BTRACE_KS(BTrace::EMutexAcquire, this);
|
|
354 |
return KErrNone;
|
|
355 |
}
|
|
356 |
K::PINestLevel=0;
|
|
357 |
pC->iMState=DThread::EWaitMutex;
|
|
358 |
pC->iWaitObj=this;
|
|
359 |
++iWaitCount;
|
|
360 |
iWaitQ.Add(pC);
|
|
361 |
TInt p=pC->iWaitLink.iPriority;
|
|
362 |
if (p>iCleanup.iPriority)
|
|
363 |
iCleanup.ChangePriority(p);
|
|
364 |
BTRACE_KS(BTrace::EMutexBlock, this);
|
|
365 |
|
|
366 |
// If the thread is woken up normally as a result of the mutex being released
|
|
367 |
// this function will KErrNone and this thread will have been placed in
|
|
368 |
// EHoldMutexPending state. If the thread is killed while waiting this function
|
|
369 |
// will not return (since the exit handler will run instead).
|
|
370 |
// If the mutex is reset (or deleted) while the thread is waiting this function
|
|
371 |
// will return KErrGeneral and the thread will have been placed into EReady
|
|
372 |
// state. If however the mutex is reset (or deleted) while the thread is in
|
|
373 |
// EHoldMutexPending state, having already been woken up normally as a result
|
|
374 |
// of the mutex being released, this function will return KErrNone (since the
|
|
375 |
// return value is set at the point where the thread is released from its wait
|
|
376 |
// condition). However we can still detect this situation since the thread will
|
|
377 |
// have been placed into the EReady state when the mutex was reset.
|
|
378 |
TInt r=NKern::Block(0,NKern::ERelease|NKern::EClaim,SYSTEM_LOCK);
|
|
379 |
if (r==KErrNone && pC->iMState==DThread::EReady)
|
|
380 |
r = KErrGeneral; // mutex has been reset
|
|
381 |
if (r!=KErrNone) // if we get an error here...
|
|
382 |
{
|
|
383 |
__ASSERT_DEBUG(pC->iMState==DThread::EReady,K::Fault(K::EMutexWaitBadState));
|
|
384 |
return r; // ...bail out now - this mutex may no longer exist
|
|
385 |
}
|
|
386 |
pC->iMState=DThread::EReady;
|
|
387 |
pC->iWaitObj=NULL;
|
|
388 |
pC->iWaitLink.Deque(); // remove thread from iPendingQ
|
|
389 |
}
|
|
390 |
if (iResetting)
|
|
391 |
return KErrGeneral;
|
|
392 |
BTRACE_KS(BTrace::EMutexAcquire, this);
|
|
393 |
iHoldCount=1;
|
|
394 |
iCleanup.iPriority=TUint8(HighestWaitingPriority());
|
|
395 |
pC->AddCleanup(&iCleanup);
|
|
396 |
#ifdef _DEBUG
|
|
397 |
ml.AddHead(&iOrderLink);
|
|
398 |
#endif
|
|
399 |
return KErrNone;
|
|
400 |
}
|
|
401 |
|
|
402 |
// Enter with system locked, return with system unlocked.
|
|
403 |
void DMutex::Signal()
|
|
404 |
{
|
|
405 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O Signal hold=%O hldc=%d wtc=%d",this,iCleanup.iThread,iHoldCount,iWaitCount));
|
|
406 |
__ASSERT_SYSTEM_LOCK;
|
|
407 |
DThread* pC=TheCurrentThread;
|
|
408 |
__ASSERT_DEBUG(iCleanup.iThread==pC,K::Fault(K::EMutexSignalWrongThread));
|
|
409 |
__ASSERT_DEBUG(pC->iMState==DThread::EReady,K::Fault(K::EMutexSignalBadState));
|
|
410 |
COND_BTRACE_KS(!iResetting, BTrace::EMutexRelease, this);
|
|
411 |
if (!iResetting && --iHoldCount==0)
|
|
412 |
{
|
|
413 |
if (iWaitQ.NonEmpty())
|
|
414 |
{
|
|
415 |
// Wake up the next waiting thread.
|
|
416 |
// We MUST do this before reliquishing our inherited priority.
|
|
417 |
// We won't thrash on the system lock because inheritance ensures our priority is not
|
|
418 |
// lower than the waiting thread's and the scheduler will not round-robin a thread which
|
|
419 |
// holds a fast mutex (the system lock in this case).
|
|
420 |
WakeUpNextThread();
|
|
421 |
}
|
|
422 |
else
|
|
423 |
{
|
|
424 |
__ASSERT_DEBUG(iCleanup.iPriority==0,Kern::Fault("MutSigBadClnPri",iCleanup.iPriority));
|
|
425 |
}
|
|
426 |
iCleanup.iThread=NULL;
|
|
427 |
#ifdef _DEBUG
|
|
428 |
iOrderLink.Deque();
|
|
429 |
#endif
|
|
430 |
pC->iCleanupQ.Remove(&iCleanup); // remove cleanup item but don't set priority yet
|
|
431 |
if (iCleanup.iPriority!=0) // if cleanup item had nonzero priority may need to revert our priority
|
|
432 |
{
|
|
433 |
// Revert this thread's priority and release the system lock without thrashing.
|
|
434 |
// Relies on the fact that our MState is READY here.
|
|
435 |
pC->RevertPriority();
|
|
436 |
return;
|
|
437 |
}
|
|
438 |
}
|
|
439 |
NKern::UnlockSystem();
|
|
440 |
}
|
|
441 |
|
|
442 |
// Enter and return with system locked.
|
|
443 |
void DMutex::Reset()
|
|
444 |
{
|
|
445 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O Reset hold=%O hldc=%d wtc=%d",this,iCleanup.iThread,iHoldCount,iWaitCount));
|
|
446 |
__ASSERT_SYSTEM_LOCK;
|
|
447 |
if (iResetting)
|
|
448 |
return;
|
|
449 |
K::PINestLevel=0;
|
|
450 |
iResetting = TRUE;
|
|
451 |
|
|
452 |
// We release the pending threads first, then waiting threads, then suspended threads.
|
|
453 |
// Other code relies on this.
|
|
454 |
while (!iPendingQ.IsEmpty())
|
|
455 |
{
|
|
456 |
DThread* pT=_LOFF(iPendingQ.First()->Deque(),DThread,iWaitLink);
|
|
457 |
pT->iMState=DThread::EReady;
|
|
458 |
pT->iWaitObj=NULL;
|
|
459 |
NKern::FlashSystem();
|
|
460 |
}
|
|
461 |
while (iWaitQ.NonEmpty())
|
|
462 |
{
|
|
463 |
DThread* pT=iWaitQ.First();
|
|
464 |
iWaitQ.Remove(pT);
|
|
465 |
pT->iMState=DThread::EReady;
|
|
466 |
pT->iWaitObj=NULL;
|
|
467 |
NKern::ThreadRelease(&pT->iNThread,KErrGeneral,SYSTEM_LOCK);
|
|
468 |
NKern::LockSystem();
|
|
469 |
}
|
|
470 |
while (!iSuspendedQ.IsEmpty())
|
|
471 |
{
|
|
472 |
DThread* pT=_LOFF(iSuspendedQ.First()->Deque(),DThread,iWaitLink);
|
|
473 |
pT->iMState=DThread::EReady;
|
|
474 |
pT->iWaitObj=NULL;
|
|
475 |
NKern::ThreadRelease(&pT->iNThread,KErrGeneral,SYSTEM_LOCK);
|
|
476 |
NKern::LockSystem();
|
|
477 |
}
|
|
478 |
if (iCleanup.iThread)
|
|
479 |
{
|
|
480 |
iCleanup.Remove();
|
|
481 |
iCleanup.iThread=NULL;
|
|
482 |
#ifdef _DEBUG
|
|
483 |
iOrderLink.Deque();
|
|
484 |
#endif
|
|
485 |
}
|
|
486 |
iCleanup.iPriority=0;
|
|
487 |
iHoldCount=0;
|
|
488 |
iWaitCount=0;
|
|
489 |
iResetting = FALSE;
|
|
490 |
}
|
|
491 |
|
|
492 |
// Enter and return with system locked.
|
|
493 |
void DMutex::WaitCancel(DThread* aThread)
|
|
494 |
{
|
|
495 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O WaitCancel(%O)",this,aThread));
|
|
496 |
iWaitQ.Remove(aThread);
|
|
497 |
--iWaitCount;
|
|
498 |
K::PINestLevel=0;
|
|
499 |
TInt p=HighestWaitingPriority();
|
|
500 |
iCleanup.ChangePriority(p);
|
|
501 |
}
|
|
502 |
|
|
503 |
// Enter and return with system locked.
|
|
504 |
void DMutex::WaitCancelSuspended(DThread* aThread)
|
|
505 |
{
|
|
506 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O WaitCanSusp(%O)",this,aThread));
|
|
507 |
aThread->iWaitLink.Deque();
|
|
508 |
--iWaitCount;
|
|
509 |
}
|
|
510 |
|
|
511 |
// Enter and return with system locked.
|
|
512 |
void DMutex::SuspendWaitingThread(DThread* aThread)
|
|
513 |
{
|
|
514 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O SuspWait(%O)",this,aThread));
|
|
515 |
iWaitQ.Remove(aThread);
|
|
516 |
iSuspendedQ.Add(&aThread->iWaitLink); // OK if resetting since suspended queue is processed after wait queue
|
|
517 |
aThread->iMState=DThread::EWaitMutexSuspended;
|
|
518 |
K::PINestLevel=0;
|
|
519 |
TInt p=HighestWaitingPriority();
|
|
520 |
iCleanup.ChangePriority(p);
|
|
521 |
}
|
|
522 |
|
|
523 |
// Enter and return with system locked.
|
|
524 |
void DMutex::ResumeWaitingThread(DThread* aThread)
|
|
525 |
{
|
|
526 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O ResumeWait(%O)",this,aThread));
|
|
527 |
aThread->iWaitLink.Deque();
|
|
528 |
if (!iResetting)
|
|
529 |
{
|
|
530 |
if (iCleanup.iThread)
|
|
531 |
{
|
|
532 |
// mutex is held, so put this one back on wait queue
|
|
533 |
aThread->iMState=DThread::EWaitMutex;
|
|
534 |
iWaitQ.Add(aThread);
|
|
535 |
K::PINestLevel=0;
|
|
536 |
TInt p=aThread->iWaitLink.iPriority;
|
|
537 |
if (p>iCleanup.iPriority)
|
|
538 |
iCleanup.ChangePriority(p);
|
|
539 |
return;
|
|
540 |
}
|
|
541 |
aThread->iMState=DThread::EHoldMutexPending;
|
|
542 |
iPendingQ.Add(&aThread->iWaitLink);
|
|
543 |
--iWaitCount;
|
|
544 |
NKern::ThreadRelease(&aThread->iNThread,0);
|
|
545 |
}
|
|
546 |
else
|
|
547 |
{
|
|
548 |
// don't want to put it on the wait queue
|
|
549 |
aThread->iMState=DThread::EReady;
|
|
550 |
aThread->iWaitObj=NULL;
|
|
551 |
NKern::ThreadRelease(&aThread->iNThread,KErrGeneral);
|
|
552 |
}
|
|
553 |
}
|
|
554 |
|
|
555 |
// Enter and return with system locked.
|
|
556 |
void DMutex::ChangeWaitingThreadPriority(DThread* aThread, TInt aNewPriority)
|
|
557 |
{
|
|
558 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O ChangeWaitPri(%O,%d)",this,aThread,aNewPriority));
|
|
559 |
if (!iCleanup.iThread && aNewPriority>aThread->iWaitLink.iPriority && !iResetting)
|
|
560 |
{
|
|
561 |
// if the mutex is currently free and the thread's priority is being increased, wake up the thread
|
|
562 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O wake up %O wtc=%d",this,aThread,iWaitCount));
|
|
563 |
iWaitQ.Remove(aThread);
|
|
564 |
aThread->iWaitLink.iPriority=(TUint8)aNewPriority;
|
|
565 |
iPendingQ.Add(&aThread->iWaitLink);
|
|
566 |
aThread->iMState=DThread::EHoldMutexPending;
|
|
567 |
--iWaitCount;
|
|
568 |
NKern::ThreadRelease(&aThread->iNThread,0); // unfortunately this may well thrash but this should be a rare case
|
|
569 |
}
|
|
570 |
else
|
|
571 |
{
|
|
572 |
iWaitQ.ChangePriority(aThread,aNewPriority);
|
|
573 |
iCleanup.ChangePriority(iWaitQ.HighestPriority());
|
|
574 |
}
|
|
575 |
}
|
|
576 |
|
|
577 |
// Enter and return with system locked.
|
|
578 |
void DMutex::ChangePendingThreadPriority(DThread* aThread, TInt aNewPriority)
|
|
579 |
{
|
|
580 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O ChangePendPri(%O,%d)",this,aThread,aNewPriority));
|
|
581 |
if (!iCleanup.iThread && aNewPriority<aThread->iWaitLink.iPriority && !iResetting)
|
|
582 |
{
|
|
583 |
if (aNewPriority<HighestWaitingPriority())
|
|
584 |
{
|
|
585 |
// wake up the next thread
|
|
586 |
WakeUpNextThread();
|
|
587 |
}
|
|
588 |
}
|
|
589 |
aThread->iWaitLink.iPriority=(TUint8)aNewPriority;
|
|
590 |
}
|
|
591 |
|
|
592 |
// Enter and return with system locked.
|
|
593 |
void DMutex::WakeUpNextThread()
|
|
594 |
{
|
|
595 |
// wake up the next thread
|
|
596 |
DThread* pT=iWaitQ.First();
|
|
597 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O wake up %O wtc=%d",this,pT,iWaitCount));
|
|
598 |
iWaitQ.Remove(pT);
|
|
599 |
iPendingQ.Add(&pT->iWaitLink);
|
|
600 |
pT->iMState=DThread::EHoldMutexPending;
|
|
601 |
--iWaitCount;
|
|
602 |
NKern::ThreadRelease(&pT->iNThread,0);
|
|
603 |
// If next thread is same priority as current, let it have a go with the mutex
|
|
604 |
// Safe to inspect pT here as it can't have run yet, we've still got the system lock
|
|
605 |
if (NCurrentThread()->iPriority == pT->iNThread.iPriority)
|
|
606 |
NKern::YieldTimeslice();
|
|
607 |
}
|
|
608 |
|
|
609 |
// Called when a thread which was about to claim the mutex is suspended
|
|
610 |
// Enter and return with system locked.
|
|
611 |
#ifdef KSEMAPHORE
|
|
612 |
void DMutex::SuspendPendingThread(DThread* aThread)
|
|
613 |
#else
|
|
614 |
void DMutex::SuspendPendingThread(DThread*)
|
|
615 |
#endif
|
|
616 |
{
|
|
617 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O SuspendP(%O)",this,aThread));
|
|
618 |
if (!iResetting && !iCleanup.iThread && iWaitQ.NonEmpty())
|
|
619 |
WakeUpNextThread();
|
|
620 |
}
|
|
621 |
|
|
622 |
// Called when a pending thread exits
|
|
623 |
// Enter and return with system locked.
|
|
624 |
void DMutex::RemovePendingThread(DThread* aThread)
|
|
625 |
{
|
|
626 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O RemoveP(%O)",this,aThread));
|
|
627 |
aThread->iWaitLink.Deque();
|
|
628 |
if (!iResetting && !iCleanup.iThread && iWaitQ.NonEmpty())
|
|
629 |
WakeUpNextThread();
|
|
630 |
}
|
|
631 |
|
|
632 |
TInt DMutex::HighestWaitingPriority()
|
|
633 |
{
|
|
634 |
if (iWaitQ.NonEmpty())
|
|
635 |
return iWaitQ.HighestPriority();
|
|
636 |
return 0;
|
|
637 |
}
|
|
638 |
|
|
639 |
/********************************************
|
|
640 |
* Condition Variable
|
|
641 |
********************************************/
|
|
642 |
DCondVar::DCondVar()
|
|
643 |
{
|
|
644 |
}
|
|
645 |
|
|
646 |
DCondVar::~DCondVar()
|
|
647 |
{
|
|
648 |
NKern::LockSystem();
|
|
649 |
Reset();
|
|
650 |
BTRACE_KS(BTrace::ECondVarDestroy, this);
|
|
651 |
NKern::UnlockSystem();
|
|
652 |
}
|
|
653 |
|
|
654 |
// Enter and return with system unlocked.
|
|
655 |
TInt DCondVar::Create(DObject* aOwner, const TDesC* aName, TBool aVisible)
|
|
656 |
{
|
|
657 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("DCondVar::Create owner %O, name %lS, visible=%d",aOwner,aName,aVisible));
|
|
658 |
SetOwner(aOwner);
|
|
659 |
TInt r=KErrNone;
|
|
660 |
if (aName && aName->Length())
|
|
661 |
{
|
|
662 |
r=SetName(aName);
|
|
663 |
if (r!=KErrNone)
|
|
664 |
return r;
|
|
665 |
}
|
|
666 |
r = iWaitQ.Construct();
|
|
667 |
if (r==KErrNone && aVisible)
|
|
668 |
r=K::AddObject(this,ECondVar);
|
|
669 |
COND_BTRACE_KSC(r==KErrNone, BTrace::ECondVarCreate);
|
|
670 |
return r;
|
|
671 |
}
|
|
672 |
|
|
673 |
void DCondVar::WaitCancel(DThread* aThread)
|
|
674 |
{
|
|
675 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O WaitCancel(%O)", this, aThread));
|
|
676 |
iWaitQ.Remove(aThread);
|
|
677 |
if (--iWaitCount == 0)
|
|
678 |
iMutex = NULL;
|
|
679 |
}
|
|
680 |
|
|
681 |
void DCondVar::WaitCancelSuspended(DThread* aThread)
|
|
682 |
{
|
|
683 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O WaitCanSusp(%O)", this, aThread));
|
|
684 |
aThread->iWaitLink.Deque();
|
|
685 |
if (--iWaitCount == 0)
|
|
686 |
iMutex = NULL;
|
|
687 |
}
|
|
688 |
|
|
689 |
void DCondVar::SuspendWaitingThread(DThread* aThread)
|
|
690 |
{
|
|
691 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O SuspendWait(%O)", this, aThread));
|
|
692 |
iWaitQ.Remove(aThread);
|
|
693 |
iSuspendedQ.Add(&aThread->iWaitLink); // OK if resetting since suspended queue is processed after wait queue
|
|
694 |
aThread->iMState = DThread::EWaitCondVarSuspended;
|
|
695 |
}
|
|
696 |
|
|
697 |
void DCondVar::ResumeWaitingThread(DThread* aThread)
|
|
698 |
{
|
|
699 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O ResumeWait(%O)", this, aThread));
|
|
700 |
aThread->iWaitLink.Deque();
|
|
701 |
aThread->iMState = DThread::EWaitCondVar;
|
|
702 |
UnBlockThread(aThread, EFalse);
|
|
703 |
}
|
|
704 |
|
|
705 |
void DCondVar::ChangeWaitingThreadPriority(DThread* aThread, TInt aNewPriority)
|
|
706 |
{
|
|
707 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O ChangeWaitPri(%O,%d)", this, aThread, aNewPriority));
|
|
708 |
if (aNewPriority>aThread->iWaitLink.iPriority && !iResetting)
|
|
709 |
{
|
|
710 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CV %O wake up %O", this, aThread));
|
|
711 |
iWaitQ.Remove(aThread);
|
|
712 |
aThread->iWaitLink.iPriority = (TUint8)aNewPriority;
|
|
713 |
UnBlockThread(aThread, EFalse);
|
|
714 |
}
|
|
715 |
else
|
|
716 |
{
|
|
717 |
iWaitQ.ChangePriority(aThread, aNewPriority);
|
|
718 |
}
|
|
719 |
}
|
|
720 |
|
|
721 |
TInt DCondVar::Wait(DMutex* aMutex, TInt aTimeout)
|
|
722 |
{
|
|
723 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O Wait (M=%O, tmout=%d)", this, aMutex, aTimeout));
|
|
724 |
__ASSERT_SYSTEM_LOCK;
|
|
725 |
DMutex& m = *aMutex;
|
|
726 |
DThread* pC=TheCurrentThread;
|
|
727 |
__ASSERT_DEBUG(pC->iMState==DThread::EReady, K::Fault(K::ECondVarWaitBadState1));
|
|
728 |
if (iResetting)
|
|
729 |
return KErrGeneral;
|
|
730 |
if (aMutex->iCleanup.iThread != pC)
|
|
731 |
K::PanicCurrentThread(ECondVarWaitMutexNotLocked);
|
|
732 |
if (iMutex && iMutex!=aMutex)
|
|
733 |
return KErrInUse;
|
|
734 |
if (!iMutex)
|
|
735 |
iMutex = aMutex;
|
|
736 |
|
|
737 |
// set the current thread M-State to wait-for-condition-variable
|
|
738 |
pC->iMState = DThread::EWaitCondVar;
|
|
739 |
pC->iWaitObj = this;
|
|
740 |
iWaitQ.Add(pC);
|
|
741 |
++iWaitCount;
|
|
742 |
|
|
743 |
// unlock the associated mutex
|
|
744 |
TBool unlock = ETrue;
|
|
745 |
m.iHoldCount = 0;
|
|
746 |
if (m.iWaitQ.NonEmpty())
|
|
747 |
{
|
|
748 |
// Wake up the next waiting thread.
|
|
749 |
// We MUST do this before reliquishing our inherited priority.
|
|
750 |
// We won't thrash on the system lock because inheritance ensures our priority is not
|
|
751 |
// lower than the waiting thread's and the scheduler will not round-robin a thread which
|
|
752 |
// holds a fast mutex (the system lock in this case).
|
|
753 |
m.WakeUpNextThread();
|
|
754 |
}
|
|
755 |
else
|
|
756 |
{
|
|
757 |
__ASSERT_DEBUG(m.iCleanup.iPriority==0,Kern::Fault("MutSigBadClnPri",m.iCleanup.iPriority));
|
|
758 |
}
|
|
759 |
m.iCleanup.iThread=NULL;
|
|
760 |
#ifdef _DEBUG
|
|
761 |
m.iOrderLink.Deque();
|
|
762 |
#endif
|
|
763 |
pC->iCleanupQ.Remove(&m.iCleanup); // remove cleanup item but don't set priority yet
|
|
764 |
if (m.iCleanup.iPriority!=0) // if cleanup item had nonzero priority may need to revert our priority
|
|
765 |
{
|
|
766 |
// Revert this thread's priority and release the system lock without thrashing.
|
|
767 |
TInt p = pC->iDefaultPriority;
|
|
768 |
TInt c = pC->iCleanupQ.HighestPriority();
|
|
769 |
__KTRACE_OPT(KTHREAD,Kern::Printf("Thread %O CVRevertPriority def %d cleanup %d", pC, pC->iDefaultPriority, c));
|
|
770 |
if (c>p)
|
|
771 |
p=c;
|
|
772 |
if (p != pC->iNThread.i_NThread_BasePri)
|
|
773 |
{
|
|
774 |
iWaitQ.ChangePriority(pC, p);
|
|
775 |
NKern::ThreadSetPriority(&pC->iNThread, p, SYSTEM_LOCK); // anti-thrash
|
|
776 |
unlock = EFalse;
|
|
777 |
}
|
|
778 |
}
|
|
779 |
if (unlock)
|
|
780 |
NKern::UnlockSystem();
|
|
781 |
|
|
782 |
// reacquire the system lock and check if we need to block
|
|
783 |
NKern::LockSystem();
|
|
784 |
switch (pC->iMState)
|
|
785 |
{
|
|
786 |
case DThread::EReady: // condition variable deleted
|
|
787 |
return KErrGeneral;
|
|
788 |
case DThread::EHoldMutexPending: // condition variable signalled, mutex free
|
|
789 |
case DThread::EWaitMutex: // condition variable signalled, now waiting for mutex
|
|
790 |
case DThread::EWaitCondVar: // still waiting
|
|
791 |
break;
|
|
792 |
case DThread::ECreated:
|
|
793 |
case DThread::EDead:
|
|
794 |
case DThread::EWaitSemaphore:
|
|
795 |
case DThread::EWaitSemaphoreSuspended:
|
|
796 |
case DThread::EWaitMutexSuspended:
|
|
797 |
case DThread::EWaitCondVarSuspended:
|
|
798 |
default:
|
|
799 |
K::Fault(K::ECondVarWaitBadState2);
|
|
800 |
}
|
|
801 |
|
|
802 |
// block if necessary then reacquire the mutex
|
|
803 |
TInt r = KErrNone;
|
|
804 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Mutex %O Wait hold %O hldc=%d wtc=%d", &m, m.iCleanup.iThread, m.iHoldCount, m.iWaitCount));
|
|
805 |
#ifdef _DEBUG
|
|
806 |
SDblQue& ml = pC->iMutexList;
|
|
807 |
DMutex* mm = ml.IsEmpty() ? NULL : _LOFF(ml.First(), DMutex, iOrderLink);
|
|
808 |
TUint last_mutex_order = mm ? mm->iOrder : KMutexOrdNone;
|
|
809 |
if (m.iOrder<KMutexOrdUser && m.iOrder>=last_mutex_order)
|
|
810 |
K::Fault(K::EMutexOrderingViolation);
|
|
811 |
#endif
|
|
812 |
while(m.iCleanup.iThread || pC->iMState==DThread::EWaitMutex || pC->iMState==DThread::EWaitCondVar) // mutex can't be resetting since we have a handle on it
|
|
813 |
{
|
|
814 |
if (pC->iMState == DThread::EHoldMutexPending)
|
|
815 |
pC->iWaitLink.Deque();
|
|
816 |
if (pC->iMState!=DThread::EWaitCondVar && pC->iMState!=DThread::EWaitMutex)
|
|
817 |
{
|
|
818 |
K::PINestLevel = 0;
|
|
819 |
pC->iMState = DThread::EWaitMutex;
|
|
820 |
pC->iWaitObj = &m;
|
|
821 |
++m.iWaitCount;
|
|
822 |
m.iWaitQ.Add(pC);
|
|
823 |
TInt p = pC->iWaitLink.iPriority;
|
|
824 |
if (p>m.iCleanup.iPriority)
|
|
825 |
m.iCleanup.ChangePriority(p);
|
|
826 |
}
|
|
827 |
TInt tmout = pC->iMState==DThread::EWaitCondVar ? aTimeout : 0;
|
|
828 |
BTRACE_KS2(BTrace::ECondVarBlock, this, &m);
|
|
829 |
|
|
830 |
// The following possibilities exist here:
|
|
831 |
// 1. Normal operation: condition variable released and mutex is unlocked
|
|
832 |
// s=KErrNone, thread state EHoldMutexPending
|
|
833 |
// 2. Timeout while waiting for condition variable
|
|
834 |
// s=KErrTimedOut, thread state EReady
|
|
835 |
// 3. Condition variable reset while thread waiting for it
|
|
836 |
// s=KErrGeneral, thread state EReady
|
|
837 |
// 4. Mutex reset while thread waiting for it (after condition variable signalled)
|
|
838 |
// s=KErrGeneral, thread state EReady
|
|
839 |
// 5. Mutex reset while thread is in EHoldMutexPending state (after condition
|
|
840 |
// variable signalled and mutex unlocked)
|
|
841 |
// s=KErrNone, thread state EReady
|
|
842 |
// 6. Thread killed while waiting for mutex or condition variable
|
|
843 |
// Function doesn't return since exit handler runs instead.
|
|
844 |
TInt s = NKern::Block(tmout, NKern::ERelease|NKern::EClaim, SYSTEM_LOCK);
|
|
845 |
if (s==KErrNone && pC->iMState==DThread::EReady)
|
|
846 |
s = KErrGeneral;
|
|
847 |
if (s!=KErrNone && s!=KErrTimedOut) // if we get an error here...
|
|
848 |
{
|
|
849 |
__ASSERT_DEBUG(pC->iMState==DThread::EReady,K::Fault(K::EMutexWaitBadState));
|
|
850 |
return s; // ...bail out now - this condition variable may no longer exist
|
|
851 |
}
|
|
852 |
if (s==KErrTimedOut)
|
|
853 |
r = s;
|
|
854 |
BTRACE_KS2(BTrace::ECondVarWakeUp, this, &m);
|
|
855 |
}
|
|
856 |
__ASSERT_DEBUG(pC->iMState==DThread::EReady || pC->iMState==DThread::EHoldMutexPending,
|
|
857 |
K::Fault(K::ECondVarWaitBadState3));
|
|
858 |
if (pC->iMState == DThread::EHoldMutexPending)
|
|
859 |
pC->iWaitLink.Deque(); // remove thread from iPendingQ
|
|
860 |
pC->iMState = DThread::EReady;
|
|
861 |
pC->iWaitObj = NULL;
|
|
862 |
m.iHoldCount = 1;
|
|
863 |
m.iCleanup.iPriority = TUint8(m.HighestWaitingPriority());
|
|
864 |
pC->AddCleanup(&m.iCleanup);
|
|
865 |
#ifdef _DEBUG
|
|
866 |
ml.AddHead(&m.iOrderLink);
|
|
867 |
#endif
|
|
868 |
return r;
|
|
869 |
}
|
|
870 |
|
|
871 |
void DCondVar::UnBlockThread(DThread* t, TBool aUnlock)
|
|
872 |
{
|
|
873 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O UnBlockThread %O M:%d U:%d", this, t, t->iMState, aUnlock));
|
|
874 |
if (iResetting)
|
|
875 |
{
|
|
876 |
t->iWaitObj = NULL;
|
|
877 |
t->iMState = DThread::EReady;
|
|
878 |
#if defined(_DEBUG) && !defined(__SMP__)
|
|
879 |
// For crazy scheduler: if next thread is same priority as current, let it run
|
|
880 |
// Check before releasing it in case it preempts us and exits
|
|
881 |
TBool yield = EFalse;
|
|
882 |
if (TheSuperPage().KernelConfigFlags() & EKernelConfigCrazyScheduling
|
|
883 |
&& NCurrentThread()->iPriority == t->iNThread.iPriority)
|
|
884 |
yield = ETrue;
|
|
885 |
#endif
|
|
886 |
if (aUnlock)
|
|
887 |
NKern::ThreadRelease(&t->iNThread, KErrGeneral, SYSTEM_LOCK);
|
|
888 |
else
|
|
889 |
NKern::ThreadRelease(&t->iNThread, KErrGeneral);
|
|
890 |
#if defined(_DEBUG) && !defined(__SMP__)
|
|
891 |
// Actually do the yield
|
|
892 |
if (yield)
|
|
893 |
NKern::YieldTimeslice();
|
|
894 |
#endif
|
|
895 |
return;
|
|
896 |
}
|
|
897 |
t->iWaitObj = iMutex;
|
|
898 |
if (t->iMState == DThread::EWaitCondVar)
|
|
899 |
{
|
|
900 |
if (iMutex->iCleanup.iThread)
|
|
901 |
{
|
|
902 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("WaitThread %O -> EWaitMutex", t));
|
|
903 |
t->iMState = DThread::EWaitMutex;
|
|
904 |
iMutex->iWaitQ.Add(t);
|
|
905 |
++iMutex->iWaitCount;
|
|
906 |
K::PINestLevel = 0;
|
|
907 |
TInt p = t->iWaitLink.iPriority;
|
|
908 |
if (p > iMutex->iCleanup.iPriority)
|
|
909 |
iMutex->iCleanup.ChangePriority(p);
|
|
910 |
}
|
|
911 |
else
|
|
912 |
{
|
|
913 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("WaitThread %O -> EHoldMutexPending", t));
|
|
914 |
t->iMState = DThread::EHoldMutexPending;
|
|
915 |
iMutex->iPendingQ.Add(&t->iWaitLink);
|
|
916 |
if (aUnlock)
|
|
917 |
NKern::ThreadRelease(&t->iNThread, 0, SYSTEM_LOCK);
|
|
918 |
else
|
|
919 |
NKern::ThreadRelease(&t->iNThread, 0);
|
|
920 |
aUnlock = EFalse;
|
|
921 |
}
|
|
922 |
}
|
|
923 |
else if (t->iMState == DThread::EWaitCondVarSuspended)
|
|
924 |
{
|
|
925 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("WaitThread %O -> EWaitMutexSusp", t));
|
|
926 |
t->iMState = DThread::EWaitMutexSuspended;
|
|
927 |
iMutex->iSuspendedQ.Add(&t->iWaitLink);
|
|
928 |
++iMutex->iWaitCount;
|
|
929 |
}
|
|
930 |
else
|
|
931 |
K::Fault(K::ECondVarUnBlockBadState);
|
|
932 |
if (--iWaitCount == 0)
|
|
933 |
iMutex = NULL;
|
|
934 |
if (aUnlock)
|
|
935 |
NKern::UnlockSystem();
|
|
936 |
}
|
|
937 |
|
|
938 |
void DCondVar::Signal()
|
|
939 |
{
|
|
940 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O Signal", this));
|
|
941 |
__ASSERT_SYSTEM_LOCK;
|
|
942 |
BTRACE_KS2(BTrace::ECondVarSignal, this, iMutex);
|
|
943 |
DThread* t = NULL;
|
|
944 |
if (iWaitQ.NonEmpty())
|
|
945 |
{
|
|
946 |
t = iWaitQ.First();
|
|
947 |
iWaitQ.Remove(t);
|
|
948 |
}
|
|
949 |
else if (!iSuspendedQ.IsEmpty())
|
|
950 |
{
|
|
951 |
t = _LOFF(iSuspendedQ.First()->Deque(), DThread, iWaitLink);
|
|
952 |
}
|
|
953 |
if (t)
|
|
954 |
UnBlockThread(t, ETrue);
|
|
955 |
else
|
|
956 |
NKern::UnlockSystem();
|
|
957 |
}
|
|
958 |
|
|
959 |
// On entry the specified mutex is held by the current thread
|
|
960 |
// Enter and return with system locked
|
|
961 |
void DCondVar::Broadcast(DMutex* m)
|
|
962 |
{
|
|
963 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O Broadcast", this));
|
|
964 |
__ASSERT_SYSTEM_LOCK;
|
|
965 |
BTRACE_KS2(BTrace::ECondVarBroadcast, this, m);
|
|
966 |
while (iMutex == m)
|
|
967 |
{
|
|
968 |
Signal();
|
|
969 |
NKern::LockSystem();
|
|
970 |
}
|
|
971 |
}
|
|
972 |
|
|
973 |
void DCondVar::Reset()
|
|
974 |
{
|
|
975 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("CondVar %O Reset", this));
|
|
976 |
__ASSERT_SYSTEM_LOCK;
|
|
977 |
if (iResetting)
|
|
978 |
return;
|
|
979 |
iResetting = TRUE;
|
|
980 |
|
|
981 |
// We release the waiting threads first, then suspended threads.
|
|
982 |
// Other code relies on this.
|
|
983 |
while (iWaitQ.NonEmpty())
|
|
984 |
{
|
|
985 |
DThread* pT=iWaitQ.First();
|
|
986 |
iWaitQ.Remove(pT);
|
|
987 |
pT->iMState=DThread::EReady;
|
|
988 |
pT->iWaitObj=NULL;
|
|
989 |
NKern::ThreadRelease(&pT->iNThread, KErrGeneral, SYSTEM_LOCK);
|
|
990 |
NKern::LockSystem();
|
|
991 |
}
|
|
992 |
while (!iSuspendedQ.IsEmpty())
|
|
993 |
{
|
|
994 |
DThread* pT=_LOFF(iSuspendedQ.First()->Deque(),DThread,iWaitLink);
|
|
995 |
pT->iMState=DThread::EReady;
|
|
996 |
pT->iWaitObj=NULL;
|
|
997 |
NKern::ThreadRelease(&pT->iNThread, KErrGeneral, SYSTEM_LOCK);
|
|
998 |
NKern::LockSystem();
|
|
999 |
}
|
|
1000 |
iMutex = NULL;
|
|
1001 |
iResetting = FALSE;
|
|
1002 |
}
|
|
1003 |
|
|
1004 |
TInt ExecHandler::CondVarWait(DCondVar* aCondVar, TInt aMutexHandle, TInt aTimeout)
|
|
1005 |
{
|
|
1006 |
if (aTimeout)
|
|
1007 |
{
|
|
1008 |
if (aTimeout<0)
|
|
1009 |
{
|
|
1010 |
NKern::UnlockSystem();
|
|
1011 |
return KErrArgument;
|
|
1012 |
}
|
|
1013 |
|
|
1014 |
// Convert microseconds to NTimer ticks, rounding up
|
|
1015 |
TInt ntp = NKern::TickPeriod();
|
|
1016 |
aTimeout += ntp-1;
|
|
1017 |
aTimeout /= ntp;
|
|
1018 |
}
|
|
1019 |
DThread* t = TheCurrentThread;
|
|
1020 |
DMutex* m = (DMutex*)K::ObjectFromHandle(aMutexHandle, EMutex);
|
|
1021 |
m->CheckedOpen();
|
|
1022 |
t->iTempObj = m;
|
|
1023 |
TInt r = aCondVar->Wait(m, aTimeout);
|
|
1024 |
t->iTempObj = NULL;
|
|
1025 |
TInt c = m->Dec();
|
|
1026 |
if (c==1)
|
|
1027 |
{
|
|
1028 |
NKern::ThreadEnterCS();
|
|
1029 |
NKern::UnlockSystem();
|
|
1030 |
K::ObjDelete(m);
|
|
1031 |
NKern::ThreadLeaveCS();
|
|
1032 |
}
|
|
1033 |
else
|
|
1034 |
NKern::UnlockSystem();
|
|
1035 |
return r;
|
|
1036 |
}
|
|
1037 |
|
|
1038 |
void ExecHandler::CondVarSignal(DCondVar* aCondVar)
|
|
1039 |
{
|
|
1040 |
aCondVar->Signal();
|
|
1041 |
}
|
|
1042 |
|
|
1043 |
void ExecHandler::CondVarBroadcast(DCondVar* aCondVar)
|
|
1044 |
{
|
|
1045 |
TBool wm = EFalse;
|
|
1046 |
DMutex* m = aCondVar->iMutex;
|
|
1047 |
if (m) // if no mutex, no-one is waiting so no-op
|
|
1048 |
{
|
|
1049 |
aCondVar->CheckedOpen();
|
|
1050 |
m->CheckedOpen();
|
|
1051 |
NKern::ThreadEnterCS();
|
|
1052 |
if (m->iCleanup.iThread != TheCurrentThread)
|
|
1053 |
{
|
|
1054 |
wm = ETrue;
|
|
1055 |
m->Wait();
|
|
1056 |
NKern::FlashSystem();
|
|
1057 |
}
|
|
1058 |
aCondVar->Broadcast(m);
|
|
1059 |
if (wm)
|
|
1060 |
m->Signal();
|
|
1061 |
else
|
|
1062 |
NKern::UnlockSystem();
|
|
1063 |
m->Close(NULL);
|
|
1064 |
aCondVar->Close(NULL);
|
|
1065 |
NKern::ThreadLeaveCS();
|
|
1066 |
}
|
|
1067 |
else
|
|
1068 |
NKern::UnlockSystem();
|
|
1069 |
}
|
|
1070 |
|
|
1071 |
TInt ExecHandler::CondVarCreate(const TDesC8* aName, TOwnerType aType)
|
|
1072 |
{
|
|
1073 |
TKName n;
|
|
1074 |
DObject* pO=NULL;
|
|
1075 |
const TDesC* pN=NULL;
|
|
1076 |
if (aName)
|
|
1077 |
{
|
|
1078 |
Kern::KUDesGet(n,*aName);
|
|
1079 |
pN=&n;
|
|
1080 |
}
|
|
1081 |
else if (aType==EOwnerThread)
|
|
1082 |
pO=TheCurrentThread;
|
|
1083 |
else
|
|
1084 |
pO=TheCurrentThread->iOwningProcess;
|
|
1085 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Exec::CondVarCreate %lS", aName));
|
|
1086 |
NKern::ThreadEnterCS();
|
|
1087 |
TInt r=KErrNoMemory;
|
|
1088 |
DCondVar* pV = new DCondVar;
|
|
1089 |
if (pV)
|
|
1090 |
{
|
|
1091 |
r = pV->Create(pO, pN, ETrue);
|
|
1092 |
if (r==KErrNone && aName)
|
|
1093 |
pV->SetProtection(n.Length()? DObject::EGlobal : DObject::EProtected);
|
|
1094 |
if (r==KErrNone)
|
|
1095 |
r = K::MakeHandle(aType, pV);
|
|
1096 |
if (r<KErrNone)
|
|
1097 |
pV->Close(NULL);
|
|
1098 |
}
|
|
1099 |
NKern::ThreadLeaveCS();
|
|
1100 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("Exec::CondVarCreate returns %d",r));
|
|
1101 |
return r;
|
|
1102 |
}
|
|
1103 |
|
|
1104 |
/********************************************
|
|
1105 |
* Chunk
|
|
1106 |
********************************************/
|
|
1107 |
DChunk::DChunk()
|
|
1108 |
{
|
|
1109 |
}
|
|
1110 |
|
|
1111 |
DChunk::~DChunk()
|
|
1112 |
{
|
|
1113 |
__COND_DEBUG_EVENT(iAttributes&EConstructed, EEventDeleteChunk, this);
|
|
1114 |
}
|
|
1115 |
|
|
1116 |
|
|
1117 |
void DChunk::SetPaging(TUint /*aCreateAtt*/)
|
|
1118 |
{// Default implementation of virtual method that does nothing.
|
|
1119 |
}
|
|
1120 |
|
|
1121 |
TInt DChunk::Create(SChunkCreateInfo& aInfo)
|
|
1122 |
{
|
|
1123 |
SetOwner(aInfo.iOwner);
|
|
1124 |
TInt r=KErrNone;
|
|
1125 |
TBool named = (aInfo.iName.Ptr() && aInfo.iName.Length());
|
|
1126 |
if (named)
|
|
1127 |
{
|
|
1128 |
r=SetName(&aInfo.iName);
|
|
1129 |
if (r!=KErrNone)
|
|
1130 |
return r;
|
|
1131 |
}
|
|
1132 |
|
|
1133 |
switch(aInfo.iType)
|
|
1134 |
{
|
|
1135 |
case ESharedKernelMultiple:
|
|
1136 |
SetProtection(DObject::EProtected);
|
|
1137 |
// fall through...
|
|
1138 |
case ESharedIo:
|
|
1139 |
case ESharedKernelSingle:
|
|
1140 |
// Shared kernel chunks can't be adjusted from user side
|
|
1141 |
iControllingOwner = K::TheKernelProcess->iId;
|
|
1142 |
iRestrictions = EChunkPreventAdjust;
|
|
1143 |
break;
|
|
1144 |
|
|
1145 |
default:
|
|
1146 |
if(aInfo.iGlobal)
|
|
1147 |
SetProtection(named ? DObject::EGlobal : DObject::EProtected);
|
|
1148 |
iControllingOwner=TheCurrentThread->iOwningProcess->iId;
|
|
1149 |
}
|
|
1150 |
// Check if chunk is to own its memory
|
|
1151 |
if (aInfo.iAtt & TChunkCreate::EMemoryNotOwned)
|
|
1152 |
iAttributes |= EMemoryNotOwned;
|
|
1153 |
|
|
1154 |
// Verify and save the mapping attributes.
|
|
1155 |
__ASSERT_COMPILE(DChunk::ENormal == 0);
|
|
1156 |
switch( aInfo.iAtt & TChunkCreate::EMappingMask)
|
|
1157 |
{
|
|
1158 |
case TChunkCreate::ENormal:
|
|
1159 |
break;
|
|
1160 |
case TChunkCreate::EDoubleEnded:
|
|
1161 |
iAttributes |= EDoubleEnded;
|
|
1162 |
break;
|
|
1163 |
case TChunkCreate::EDisconnected:
|
|
1164 |
iAttributes |= EDisconnected;
|
|
1165 |
break;
|
|
1166 |
case TChunkCreate::ECache:
|
|
1167 |
// Use TCB check to help keep cache chunks internal...
|
|
1168 |
if(!Kern::CurrentThreadHasCapability(ECapabilityTCB,__PLATSEC_DIAGNOSTIC_STRING("DChunk::Create")))
|
|
1169 |
return KErrPermissionDenied;
|
|
1170 |
iAttributes |= EDisconnected|ECache;
|
|
1171 |
break;
|
|
1172 |
default:
|
|
1173 |
return KErrArgument;
|
|
1174 |
}
|
|
1175 |
|
|
1176 |
// Save the clear byte.
|
|
1177 |
iClearByte = aInfo.iClearByte;
|
|
1178 |
|
|
1179 |
// Determine the data paging attributes.
|
|
1180 |
SetPaging(aInfo.iAtt);
|
|
1181 |
|
|
1182 |
r=DoCreate(aInfo);
|
|
1183 |
if (r!=KErrNone)
|
|
1184 |
return r;
|
|
1185 |
|
|
1186 |
r=K::AddObject(this,EChunk);
|
|
1187 |
if (r==KErrNone)
|
|
1188 |
{
|
|
1189 |
iAttributes|=EConstructed;
|
|
1190 |
__DEBUG_EVENT(EEventNewChunk, this);
|
|
1191 |
}
|
|
1192 |
return r;
|
|
1193 |
}
|
|
1194 |
|
|
1195 |
TInt DChunk::AddToProcess(DProcess* aProcess)
|
|
1196 |
{
|
|
1197 |
__KTRACE_OPT(KEXEC,Kern::Printf("Adding chunk %O to process %O",this,aProcess));
|
|
1198 |
TInt r=aProcess->AddChunk(this,EFalse);
|
|
1199 |
if (r==KErrAccessDenied)
|
|
1200 |
{
|
|
1201 |
__KTRACE_OPT(KEXEC,Kern::Printf("Chunk is private - will not be mapped in to process"));
|
|
1202 |
r=KErrNone;
|
|
1203 |
}
|
|
1204 |
return r;
|
|
1205 |
}
|
|
1206 |
|
|
1207 |
|
|
1208 |
void DChunk::BTracePrime(TInt aCategory)
|
|
1209 |
{
|
|
1210 |
#ifdef BTRACE_CHUNKS
|
|
1211 |
if (aCategory == BTrace::EChunks || aCategory == -1)
|
|
1212 |
{
|
|
1213 |
TKName nameBuf;
|
|
1214 |
Name(nameBuf);
|
|
1215 |
BTraceN(BTrace::EChunks,BTrace::EChunkCreated,this,iMaxSize,nameBuf.Ptr(),nameBuf.Size());
|
|
1216 |
if(iOwningProcess)
|
|
1217 |
BTrace8(BTrace::EChunks,BTrace::EChunkOwner,this,iOwningProcess);
|
|
1218 |
BTrace12(BTrace::EChunks,BTrace::EChunkInfo,this,iChunkType,iAttributes);
|
|
1219 |
}
|
|
1220 |
#endif
|
|
1221 |
}
|
|
1222 |
|
|
1223 |
|
|
1224 |
SChunkCreateInfo::SChunkCreateInfo()
|
|
1225 |
{
|
|
1226 |
memset(this,0,sizeof(*this));
|
|
1227 |
iClearByte = KChunkClearByteDefault;
|
|
1228 |
}
|
|
1229 |
|
|
1230 |
|
|
1231 |
|
|
1232 |
/**
|
|
1233 |
Create a chunk which can be shared between kernel and user code.
|
|
1234 |
|
|
1235 |
Once created, the chunk owns a region of linear address space of the size requested.
|
|
1236 |
This region is empty (uncommitted) so before it can be used either RAM or I/O
|
|
1237 |
devices must be mapped into it. This is achieved with the Commit functions:
|
|
1238 |
|
|
1239 |
- Kern::ChunkCommit()
|
|
1240 |
- Kern::ChunkCommitContiguous()
|
|
1241 |
- Kern::ChunkCommitPhysical()
|
|
1242 |
|
|
1243 |
|
|
1244 |
@param aCreateInfo A structure containing the required attributes of the chunk.
|
|
1245 |
See TChunkCreateInfo.
|
|
1246 |
|
|
1247 |
@param aChunk On return, this is set to point to the created chunk object.
|
|
1248 |
This pointer is required as an argument for other functions
|
|
1249 |
dealing with Shared Chunks.
|
|
1250 |
|
|
1251 |
@param aKernAddr On return, this is set to the linear address in the kernel
|
|
1252 |
process where the chunk's memory starts. This address should
|
|
1253 |
only be used when executing kernel code; user code must not
|
|
1254 |
use this address.
|
|
1255 |
|
|
1256 |
@param aMapAttr On return, this is set to the mmu mapping attributes used for
|
|
1257 |
the chunk. This is a value constructed from the bit masks in
|
|
1258 |
the enumeration TMappingAttributes.
|
|
1259 |
The typical use for this value is to use it as an argument to
|
|
1260 |
the Cache::SyncMemoryBeforeDmaWrite() and
|
|
1261 |
Cache::SyncMemoryBeforeDmaRead() methods.
|
|
1262 |
|
|
1263 |
@return KErrNone, if successful; otherwise one of the other system wide error codes.
|
|
1264 |
|
|
1265 |
@pre Calling thread must be in a critical section.
|
|
1266 |
@pre No fast mutex can be held.
|
|
1267 |
@pre Call in a thread context.
|
|
1268 |
@pre Kernel must be unlocked.
|
|
1269 |
@pre interrupts enabled
|
|
1270 |
|
|
1271 |
@see TChunkCreateInfo
|
|
1272 |
*/
|
|
1273 |
EXPORT_C TInt Kern::ChunkCreate(const TChunkCreateInfo& aInfo, DChunk*& aChunk, TLinAddr& aKernAddr, TUint32& aMapAttr)
|
|
1274 |
{
|
|
1275 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ChunkCreate");
|
|
1276 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCreate type %d, maxSize %08x, mapAttr %08x", aInfo.iType, aInfo.iMaxSize, aInfo.iMapAttr));
|
|
1277 |
SChunkCreateInfo c;
|
|
1278 |
switch(aInfo.iType)
|
|
1279 |
{
|
|
1280 |
// Assert that chunk type enums are consistent between those used by TChunkCreateInfo and SChunkCreateInfo
|
|
1281 |
__ASSERT_COMPILE((TInt)TChunkCreateInfo::ESharedKernelSingle == (TInt)::ESharedKernelSingle);
|
|
1282 |
__ASSERT_COMPILE((TInt)TChunkCreateInfo::ESharedKernelMultiple == (TInt)::ESharedKernelMultiple);
|
|
1283 |
|
|
1284 |
case TChunkCreateInfo::ESharedKernelSingle:
|
|
1285 |
case TChunkCreateInfo::ESharedKernelMultiple:
|
|
1286 |
c.iType = (TChunkType)aInfo.iType;
|
|
1287 |
c.iAtt = TChunkCreate::EDisconnected | (aInfo.iOwnsMemory? 0 : TChunkCreate::EMemoryNotOwned);
|
|
1288 |
c.iGlobal = ETrue;
|
|
1289 |
c.iForceFixed = ETrue;
|
|
1290 |
c.iMaxSize = aInfo.iMaxSize;
|
|
1291 |
c.iMapAttr = aInfo.iMapAttr;
|
|
1292 |
c.iOperations = SChunkCreateInfo::EAdjust; // To allocated virtual address space
|
|
1293 |
c.iDestroyedDfc = aInfo.iDestroyedDfc;
|
|
1294 |
break;
|
|
1295 |
|
|
1296 |
default:
|
|
1297 |
return KErrArgument;
|
|
1298 |
}
|
|
1299 |
|
|
1300 |
TInt r = K::TheKernelProcess->NewChunk(aChunk, c, aKernAddr);
|
|
1301 |
if(r==KErrNone)
|
|
1302 |
aMapAttr = aChunk->iMapAttr;
|
|
1303 |
else
|
|
1304 |
{
|
|
1305 |
if(aChunk)
|
|
1306 |
aChunk->Close(NULL), aChunk=0; // can't have been added so NULL
|
|
1307 |
}
|
|
1308 |
|
|
1309 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCreate returns %d aChunk=%08x aKernAddr=%08x",r,aChunk,aKernAddr));
|
|
1310 |
return r;
|
|
1311 |
}
|
|
1312 |
|
|
1313 |
|
|
1314 |
|
|
1315 |
/**
|
|
1316 |
Commit RAM to a shared chunk which was previously created with Kern::ChunkCreate().
|
|
1317 |
The memory pages to commit are obtained from the system's free pool.
|
|
1318 |
|
|
1319 |
This method may only be used if the chunk was created with
|
|
1320 |
TChunkCreateInfo::iOwnsMemory set to true.
|
|
1321 |
|
|
1322 |
@param aChunk Pointer to the chunk.
|
|
1323 |
|
|
1324 |
@param aOffset The offset (in bytes) from start of chunk, which indicates the start
|
|
1325 |
of the memory region to be committed. Must be a multiple of the MMU
|
|
1326 |
page size.
|
|
1327 |
|
|
1328 |
@param aSize Number of bytes to commit. Must be a multiple of the MMU page size.
|
|
1329 |
|
|
1330 |
@return KErrNone, if successful; otherwise one of the other system wide error codes.
|
|
1331 |
|
|
1332 |
@pre Calling thread must be in a critical section.
|
|
1333 |
@pre No fast mutex can be held.
|
|
1334 |
@pre Call in a thread context.
|
|
1335 |
@pre Kernel must be unlocked.
|
|
1336 |
@pre interrupts enabled
|
|
1337 |
|
|
1338 |
@post Calling thread is in a critical section.
|
|
1339 |
*/
|
|
1340 |
EXPORT_C TInt Kern::ChunkCommit(DChunk* aChunk, TInt aOffset, TInt aSize)
|
|
1341 |
{
|
|
1342 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ChunkCommit");
|
|
1343 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommit aChunk=%08x, aOffset=%08x, aSize=%08x", aChunk, aOffset, aSize));
|
|
1344 |
__ASSERT_DEBUG(aChunk->iChunkType == ESharedKernelSingle || aChunk->iChunkType == ESharedKernelMultiple, K::Fault(K::EChunkCommitBadType));
|
|
1345 |
TInt r = aChunk->Commit(aOffset, aSize);
|
|
1346 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommit returns %d",r));
|
|
1347 |
return r;
|
|
1348 |
}
|
|
1349 |
|
|
1350 |
|
|
1351 |
/**
|
|
1352 |
Commit RAM to a shared chunk which was previously created with Kern::ChunkCreate().
|
|
1353 |
The memory pages to commit are obtained from the system's free pool and will have
|
|
1354 |
physically contiguous addresses.
|
|
1355 |
|
|
1356 |
This method may only be used if the chunk was created with
|
|
1357 |
TChunkCreateInfo::iOwnsMemory set to true.
|
|
1358 |
|
|
1359 |
@param aChunk Pointer to the chunk.
|
|
1360 |
|
|
1361 |
@param aOffset The offset (in bytes) from start of chunk, which indicates
|
|
1362 |
the start of the memory region to be committed. Must be a
|
|
1363 |
multiple of the MMU page size.
|
|
1364 |
|
|
1365 |
@param aSize Number of bytes to commit. Must be a multiple of the MMU
|
|
1366 |
page size.
|
|
1367 |
|
|
1368 |
@param aPhysicalAddress On return, this is set to the physical address of the first
|
|
1369 |
page of memory which was committed. I.e. the page at
|
|
1370 |
aOffset.
|
|
1371 |
|
|
1372 |
@return KErrNone, if successful;
|
|
1373 |
KErrNoMemory, if there is insufficient free memory, or there is not a
|
|
1374 |
contiguous region of the requested size;
|
|
1375 |
otherwise one of the other system wide error codes.
|
|
1376 |
|
|
1377 |
@pre Calling thread must be in a critical section.
|
|
1378 |
@pre No fast mutex can be held.
|
|
1379 |
@pre Call in a thread context.
|
|
1380 |
@pre Kernel must be unlocked.
|
|
1381 |
@pre interrupts enabled
|
|
1382 |
|
|
1383 |
@post Calling thread is in a critical section.
|
|
1384 |
*/
|
|
1385 |
EXPORT_C TInt Kern::ChunkCommitContiguous(DChunk* aChunk, TInt aOffset, TInt aSize, TUint32& aPhysicalAddress)
|
|
1386 |
{
|
|
1387 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ChunkCommitContiguous");
|
|
1388 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommitContiguous aChunk=%08x, aOffset=%08x, aSize=%08x", aChunk, aOffset, aSize));
|
|
1389 |
__ASSERT_DEBUG(aChunk->iChunkType == ESharedKernelSingle || aChunk->iChunkType == ESharedKernelMultiple, K::Fault(K::EChunkCommitBadType));
|
|
1390 |
TInt r = aChunk->Commit(aOffset, aSize, DChunk::ECommitContiguous, &aPhysicalAddress);
|
|
1391 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommitContiguous returns %d aPhysicalAddress=%08x",r,aPhysicalAddress));
|
|
1392 |
return r;
|
|
1393 |
}
|
|
1394 |
|
|
1395 |
|
|
1396 |
/**
|
|
1397 |
Commit memory to a shared chunk which was previously created with
|
|
1398 |
Kern::ChunkCreate().
|
|
1399 |
|
|
1400 |
The physical region committed is that which starts at the supplied physical address.
|
|
1401 |
Typically, this region either represents memory mapped i/o, or RAM which has been
|
|
1402 |
set aside for special use at system boot time.
|
|
1403 |
|
|
1404 |
This method may only be used if the chunk was created with
|
|
1405 |
TChunkCreateInfo::iOwnsMemory set to false.
|
|
1406 |
|
|
1407 |
@param aChunk Pointer to the chunk.
|
|
1408 |
|
|
1409 |
@param aOffset The offset (in bytes) from start of chunk, which indicates
|
|
1410 |
the start of the memory region to be committed. Must be a
|
|
1411 |
multiple of the MMU page size.
|
|
1412 |
|
|
1413 |
@param aSize Number of bytes to commit. Must be a multiple of the MMU
|
|
1414 |
page size.
|
|
1415 |
|
|
1416 |
@param aPhysicalAddress The physical address of the memory to be commited to the
|
|
1417 |
chunk. Must be a multiple of the MMU page size.
|
|
1418 |
|
|
1419 |
@return KErrNone, if successful; otherwise one of the other system wide error codes.
|
|
1420 |
|
|
1421 |
@pre Calling thread must be in a critical section.
|
|
1422 |
@pre No fast mutex can be held.
|
|
1423 |
@pre Call in a thread context.
|
|
1424 |
@pre Kernel must be unlocked.
|
|
1425 |
@pre interrupts enabled
|
|
1426 |
|
|
1427 |
@post Calling thread is in a critical section.
|
|
1428 |
*/
|
|
1429 |
EXPORT_C TInt Kern::ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, TUint32 aPhysicalAddress)
|
|
1430 |
{
|
|
1431 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, TUint32 aPhysicalAddress)");
|
|
1432 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommitPhysical aChunk=%08x, aOffset=%08x, aSize=%08x aPhysicalAddress=%08x", aChunk, aOffset, aSize, aPhysicalAddress));
|
|
1433 |
__ASSERT_DEBUG(aChunk->iChunkType == ESharedKernelSingle || aChunk->iChunkType == ESharedKernelMultiple, K::Fault(K::EChunkCommitBadType));
|
|
1434 |
TInt r = aChunk->Commit(aOffset, aSize, DChunk::ECommitContiguousPhysical, (TUint32*)aPhysicalAddress);
|
|
1435 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommit returns %d",r));
|
|
1436 |
return r;
|
|
1437 |
}
|
|
1438 |
|
|
1439 |
|
|
1440 |
/**
|
|
1441 |
Commit memory to a shared chunk which was previously created with
|
|
1442 |
Kern::ChunkCreate().
|
|
1443 |
|
|
1444 |
The physical region committed is determined by the list of physical addresses
|
|
1445 |
supplied to this function. Typically, this region either represents memory mapped
|
|
1446 |
i/o, or RAM which has been set aside for special use at system boot time.
|
|
1447 |
|
|
1448 |
This method may only be used if the chunk was created with
|
|
1449 |
TChunkCreateInfo::iOwnsMemory set to false.
|
|
1450 |
|
|
1451 |
@param aChunk Pointer to the chunk.
|
|
1452 |
|
|
1453 |
@param aOffset The offset (in bytes) from start of chunk, which indicates
|
|
1454 |
the start of the memory region to be committed. Must be a
|
|
1455 |
multiple of the MMU page size.
|
|
1456 |
|
|
1457 |
@param aSize Number of bytes to commit. Must be a multiple of the MMU
|
|
1458 |
page size.
|
|
1459 |
|
|
1460 |
@param aPhysicalAddress A pointer to a list of physical addresses, one address for
|
|
1461 |
each page of memory committed. Each physical address must be
|
|
1462 |
a multiple of the MMU page size.
|
|
1463 |
|
|
1464 |
@return KErrNone, if successful; otherwise one of the other system wide error codes.
|
|
1465 |
|
|
1466 |
@pre Calling thread must be in a critical section.
|
|
1467 |
@pre No fast mutex can be held.
|
|
1468 |
@pre Call in a thread context.
|
|
1469 |
@pre Kernel must be unlocked.
|
|
1470 |
@pre interrupts enabled
|
|
1471 |
|
|
1472 |
@post Calling thread is in a critical section.
|
|
1473 |
*/
|
|
1474 |
EXPORT_C TInt Kern::ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, const TUint32* aPhysicalAddressList)
|
|
1475 |
{
|
|
1476 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ChunkCommitPhysical(DChunk* aChunk, TInt aOffset, TInt aSize, const TUint32* aPhysicalAddressList)");
|
|
1477 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommitPhysical aChunk=%08x, aOffset=%08x, aSize=%08x aPhysicalAddressList=%08x", aChunk, aOffset, aSize, aPhysicalAddressList));
|
|
1478 |
__ASSERT_DEBUG(aChunk->iChunkType == ESharedKernelSingle || aChunk->iChunkType == ESharedKernelMultiple, K::Fault(K::EChunkCommitBadType));
|
|
1479 |
TInt r = aChunk->Commit(aOffset, aSize, DChunk::ECommitDiscontiguousPhysical, (TUint32*)aPhysicalAddressList);
|
|
1480 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkCommit returns %d",r));
|
|
1481 |
return r;
|
|
1482 |
}
|
|
1483 |
|
|
1484 |
|
|
1485 |
/**
|
|
1486 |
Close a chunk created with Kern::ChunkCreate().
|
|
1487 |
|
|
1488 |
If the reference count of the chunk has gone to zero, any memory
|
|
1489 |
committed to the chunk will be decommited immediately but the chunk
|
|
1490 |
object will be deleted asynchronously.
|
|
1491 |
|
|
1492 |
@param aChunk Pointer to the chunk.
|
|
1493 |
|
|
1494 |
@return True if the reference count of the chunk has gone to zero.
|
|
1495 |
False otherwise.
|
|
1496 |
|
|
1497 |
@pre Calling thread must be in a critical section.
|
|
1498 |
@pre No fast mutex can be held.
|
|
1499 |
@pre Call in a thread context.
|
|
1500 |
@pre Kernel must be unlocked.
|
|
1501 |
@pre interrupts enabled
|
|
1502 |
*/
|
|
1503 |
EXPORT_C TBool Kern::ChunkClose(DChunk* aChunk)
|
|
1504 |
{
|
|
1505 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkClose aChunk=%08x", aChunk));
|
|
1506 |
|
|
1507 |
TBool r = (aChunk->Dec() == 1);
|
|
1508 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkClose returns %d",r));
|
|
1509 |
if (r)
|
|
1510 |
{
|
|
1511 |
// Decommit all the memory from the chunk which is safe as no further
|
|
1512 |
// reference can be made to the chunk now its access count is 0. Decommit
|
|
1513 |
// is required to ensure any committed pages have their usage count
|
|
1514 |
// decremented immediately to allow any physically committed memory to
|
|
1515 |
// be freed after this method which may occur before aChunk is deleted.
|
|
1516 |
aChunk->Decommit(0, aChunk->MaxSize());
|
|
1517 |
aChunk->AsyncDelete();
|
|
1518 |
}
|
|
1519 |
return r;
|
|
1520 |
}
|
|
1521 |
|
|
1522 |
|
|
1523 |
/**
|
|
1524 |
Open a shared chunk in which the given address lies.
|
|
1525 |
|
|
1526 |
@param aThread The thread in whose process the given address lies.
|
|
1527 |
If aThread is zero, then the current thread is used.
|
|
1528 |
|
|
1529 |
@param aAddress An address in the given threads process.
|
|
1530 |
|
|
1531 |
@param aWrite A flag which is true if the chunk memory is intended to be
|
|
1532 |
written to, false otherwise.
|
|
1533 |
|
|
1534 |
@param aOffset On return, this is set to the offset within the chunk which
|
|
1535 |
correspons to aAddress.
|
|
1536 |
|
|
1537 |
@return If the supplied address is within a shared chunk mapped into aThread's
|
|
1538 |
process, then the returned value is a pointer to this chunk.
|
|
1539 |
Otherwise zero is returned.
|
|
1540 |
|
|
1541 |
@pre Calling thread must be in a critical section.
|
|
1542 |
@pre No fast mutex can be held.
|
|
1543 |
@pre Call in a thread context.
|
|
1544 |
@pre Kernel must be unlocked.
|
|
1545 |
@pre interrupts enabled
|
|
1546 |
|
|
1547 |
@post If a chunk pointer is returned, then the access count on this chunk has been
|
|
1548 |
incremented. I.e. Open() has been called on it.
|
|
1549 |
*/
|
|
1550 |
EXPORT_C DChunk* Kern::OpenSharedChunk(DThread* aThread,const TAny* aAddress, TBool aWrite, TInt& aOffset)
|
|
1551 |
{
|
|
1552 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::OpenSharedChunk(DThread* aThread,const TAny* aAddress, TBool aWrite, TInt& aOffset)");
|
|
1553 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::OpenSharedChunk aThread=%08x, aAddress=%08x, aWrite=%d", aThread, aAddress, aWrite));
|
|
1554 |
if(!aThread)
|
|
1555 |
aThread = &Kern::CurrentThread();
|
|
1556 |
DChunk* chunk = aThread->OpenSharedChunk(aAddress,aWrite,aOffset);
|
|
1557 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::OpenSharedChunk returns %08x aOffset=%08x",chunk,aOffset));
|
|
1558 |
return chunk;
|
|
1559 |
}
|
|
1560 |
|
|
1561 |
|
|
1562 |
/**
|
|
1563 |
Open a shared chunk using a given handle.
|
|
1564 |
|
|
1565 |
Typically, this handle would be a value supplied by a user application which
|
|
1566 |
obtained the value by using RChunk::Handle().
|
|
1567 |
|
|
1568 |
@param aThread The thread in which the given handle is valid.
|
|
1569 |
|
|
1570 |
@param aChunkHandle The handle value.
|
|
1571 |
|
|
1572 |
@param aWrite A flag which is true if the chunk memory is intended to be
|
|
1573 |
written to, false otherwise.
|
|
1574 |
|
|
1575 |
@return If the handle is a valid chunk handle, and it is of a shared chunk type,
|
|
1576 |
then the returned value is a pointer to this chunk.
|
|
1577 |
Otherwise zero is returned.
|
|
1578 |
|
|
1579 |
@pre Calling thread must be in a critical section.
|
|
1580 |
@pre No fast mutex can be held.
|
|
1581 |
|
|
1582 |
@post If a chunk pointer is returned, then the access count on this chunk has been
|
|
1583 |
incremented. I.e. Open() has been called on it.
|
|
1584 |
*/
|
|
1585 |
EXPORT_C DChunk* Kern::OpenSharedChunk(DThread* aThread, TInt aChunkHandle, TBool aWrite)
|
|
1586 |
{
|
|
1587 |
CHECK_PRECONDITIONS(MASK_CRITICAL|MASK_NO_FAST_MUTEX,"Kern::OpenSharedChunk(DThread* aThread, TInt aChunkHandle, TBool aWrite)");
|
|
1588 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::OpenSharedChunk aThread=%08x, aHandle=%08x, aWrite=%d", aThread, aChunkHandle, aWrite));
|
|
1589 |
if(!aThread)
|
|
1590 |
aThread = &Kern::CurrentThread();
|
|
1591 |
NKern::LockSystem();
|
|
1592 |
DChunk* chunk = aThread->OpenSharedChunk(aChunkHandle,aWrite);
|
|
1593 |
NKern::UnlockSystem();
|
|
1594 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::OpenSharedChunk returns %08x",chunk));
|
|
1595 |
return chunk;
|
|
1596 |
}
|
|
1597 |
|
|
1598 |
|
|
1599 |
/**
|
|
1600 |
@pre System lock must be held.
|
|
1601 |
*/
|
|
1602 |
DChunk* DThread::OpenSharedChunk(TInt aHandle, TBool /*aWrite*/)
|
|
1603 |
{
|
|
1604 |
DChunk* chunk = (DChunk*)ObjectFromHandle(aHandle,EChunk);
|
|
1605 |
if( chunk
|
|
1606 |
&& (chunk->iChunkType==ESharedKernelSingle || chunk->iChunkType==ESharedKernelMultiple)
|
|
1607 |
&& chunk->Open()==KErrNone)
|
|
1608 |
return chunk;
|
|
1609 |
return 0;
|
|
1610 |
}
|
|
1611 |
|
|
1612 |
|
|
1613 |
/**
|
|
1614 |
Get the linear address for a region in a shared chunk.
|
|
1615 |
|
|
1616 |
The chunk must be of a shared chunk type and the specified region must
|
|
1617 |
contain committed memory.
|
|
1618 |
|
|
1619 |
@param aChunk The chunk
|
|
1620 |
|
|
1621 |
@param aOffset The start of the region as an offset in bytes from the
|
|
1622 |
start of the chunk.
|
|
1623 |
|
|
1624 |
@param aSize The size of the region in bytes.
|
|
1625 |
|
|
1626 |
@param aKernelAddress On success, this value is set to the linear address in the
|
|
1627 |
kernel process which coresponds to first byte in the
|
|
1628 |
specified region.
|
|
1629 |
|
|
1630 |
@return KErrNone if successful.
|
|
1631 |
KErrAccessDenied if the chunk isn't a shared chunk type.
|
|
1632 |
KErrArgument if the region isn't within the chunk.
|
|
1633 |
KErrNotFound if the whole region doesn't contain comitted memory.
|
|
1634 |
|
|
1635 |
@pre No fast mutex can be held.
|
|
1636 |
*/
|
|
1637 |
EXPORT_C TInt Kern::ChunkAddress(DChunk* aChunk, TInt aOffset, TInt aSize, TLinAddr& aKernelAddress)
|
|
1638 |
{
|
|
1639 |
CHECK_PRECONDITIONS(MASK_NO_FAST_MUTEX,"Kern::ChunkAddress");
|
|
1640 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkAddress aChunk=%08x, aOffset=%08x, aSize=%d", aChunk, aOffset, aSize));
|
|
1641 |
TInt r = aChunk->Address(aOffset,aSize,aKernelAddress);
|
|
1642 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkAddress returns %d aKernelAddress=%08x",r,aKernelAddress));
|
|
1643 |
return r;
|
|
1644 |
}
|
|
1645 |
|
|
1646 |
|
|
1647 |
/**
|
|
1648 |
Get the linear address for the base of a shared chunk within a user process.
|
|
1649 |
Note, this address may become invalid if the process closes then re-opens the chunk.
|
|
1650 |
|
|
1651 |
@param aChunk The chunk
|
|
1652 |
|
|
1653 |
@param aThread The thread in whose process the returned address lies.
|
|
1654 |
|
|
1655 |
@return the base address of the shared chunk in the specified user process.
|
|
1656 |
|
|
1657 |
@pre No fast mutex can be held.
|
|
1658 |
*/
|
|
1659 |
EXPORT_C TUint8* Kern::ChunkUserBase(DChunk* aChunk, DThread* aThread)
|
|
1660 |
{
|
|
1661 |
CHECK_PRECONDITIONS(MASK_NO_FAST_MUTEX,"Kern::ChunkUserAddress");
|
|
1662 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkUserAddress aChunk=%08x, aThread=%08x", aChunk, aThread));
|
|
1663 |
NKern::LockSystem();
|
|
1664 |
TUint8* r = aChunk->Base(aThread->iOwningProcess);
|
|
1665 |
NKern::UnlockSystem();
|
|
1666 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkUserBase returns %08x", r));
|
|
1667 |
return r;
|
|
1668 |
}
|
|
1669 |
|
|
1670 |
|
|
1671 |
|
|
1672 |
/**
|
|
1673 |
Get the physical address for a region in a shared chunk.
|
|
1674 |
|
|
1675 |
The chunk must be of a shared chunk type and the specified region must
|
|
1676 |
contain committed memory.
|
|
1677 |
|
|
1678 |
@param aChunk The chunk
|
|
1679 |
|
|
1680 |
@param aOffset The start of the region as an offset in bytes from the
|
|
1681 |
start of the chunk.
|
|
1682 |
|
|
1683 |
@param aSize The size of the region in bytes.
|
|
1684 |
|
|
1685 |
@param aKernelAddress On success, this value is set to the linear address in the
|
|
1686 |
kernel process which coresponds to first byte in the
|
|
1687 |
specified region.
|
|
1688 |
|
|
1689 |
@param aMapAttr On success, this is set to the mmu mapping attributes used
|
|
1690 |
for the chunk. This is a value constructed from the bit
|
|
1691 |
masks in the enumeration TMappingAttributes.
|
|
1692 |
The typical use for this value is to use it as an argument
|
|
1693 |
to the Cache::SyncMemoryBeforeDmaWrite() and
|
|
1694 |
Cache::SyncMemoryBeforeDmaRead() methods.
|
|
1695 |
|
|
1696 |
@param aPhysicalAddress On success, this value is set to one of two values.
|
|
1697 |
If the specified region is physically contiguous, the value
|
|
1698 |
is the physical address of the first byte in the region.
|
|
1699 |
If the region is discontiguous, the value is set to KPhysAddrInvalid.
|
|
1700 |
|
|
1701 |
@param aPageList If not zero, this points to an array of TUint32
|
|
1702 |
(or TPhysAddr) objects. The length of the array must be at
|
|
1703 |
least (aSize + MMU_page_size-2)/MMU_page_size + 1,
|
|
1704 |
where MMU_page_size = Kern::RoundToPageSize(1).
|
|
1705 |
On success, this array will be filled with the addresses of
|
|
1706 |
the physical pages which contain the specified region.
|
|
1707 |
These addresses are the start of each page, (they are a
|
|
1708 |
multiple of the physical page size), therefore the byte
|
|
1709 |
corresponding to aOffset is at physical address
|
|
1710 |
aPageList[0]+aOffset%MMU_page_size.
|
|
1711 |
If aPageList is zero (the default), then the function will fail with
|
|
1712 |
KErrNotFound if the specified region is not physically contiguous.
|
|
1713 |
|
|
1714 |
@return 0 if successful and the whole region is physically contiguous.
|
|
1715 |
1 if successful but the region isn't physically contiguous.
|
|
1716 |
KErrAccessDenied if the chunk isn't a shared chunk type.
|
|
1717 |
KErrArgument if the region isn't within the chunk.
|
|
1718 |
KErrNotFound if the whole region doesn't contain comitted memory
|
|
1719 |
or aPageList==0 and the specified region is not physically contiguous.
|
|
1720 |
|
|
1721 |
@pre No fast mutex can be held.
|
|
1722 |
*/
|
|
1723 |
EXPORT_C TInt Kern::ChunkPhysicalAddress(DChunk* aChunk, TInt aOffset, TInt aSize, TLinAddr& aKernelAddress, TUint32& aMapAttr, TUint32& aPhysicalAddress, TUint32* aPageList)
|
|
1724 |
{
|
|
1725 |
CHECK_PRECONDITIONS(MASK_NO_FAST_MUTEX,"Kern::ChunkPhysicalAddress");
|
|
1726 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkPhysicalAddress aChunk=%08x, aOffset=%08x, aSize=%d", aChunk, aOffset, aSize));
|
|
1727 |
TInt r = aChunk->PhysicalAddress(aOffset,aSize,aKernelAddress,aPhysicalAddress,aPageList);
|
|
1728 |
if(r >= 0) /* KErrNone or 1 (i.e. not phys contig) are both successful returns */
|
|
1729 |
aMapAttr = aChunk->iMapAttr;
|
|
1730 |
__KTRACE_OPT(KMMU,Kern::Printf("Kern::ChunkPhysicalAddress returns %d aKernelAddress=%08x aPhysicalAddress=%08x",r,aKernelAddress,aPhysicalAddress));
|
|
1731 |
return r;
|
|
1732 |
}
|
|
1733 |
|
|
1734 |
/**
|
|
1735 |
Returns the list of physical addresses of the specified virtual memory region - if the whole region is safe
|
|
1736 |
to DMA to/from. A region of virtual space is considered safe if it belongs to a chunk which is marked by
|
|
1737 |
FileServer as being trusted to perform DMA to/from. File system must ensure physical pages are not
|
|
1738 |
decomitted or unlocked for demand paging until DMA transfer is completed.
|
|
1739 |
This will also lock the pages to prevent them of being moved by ram defrag.
|
|
1740 |
|
|
1741 |
@see UserSvr::RegisterTrustedChunk
|
|
1742 |
@see Kern::ReleaseMemoryFromDMA
|
|
1743 |
|
|
1744 |
@param aThread The thread in whose process the given address lies. If zero, the current thread is used.
|
|
1745 |
@param aAddress An address in the given threads process.
|
|
1746 |
@param aSize The size of the region.
|
|
1747 |
@param aPageList Points to an array of TUint32 (or TPhysAddr) objects. The length of the array must
|
|
1748 |
be at least aSize/MMU_page_size+1, where MMU_page_size = Kern::RoundToPageSize(1).
|
|
1749 |
On success, this array will be filled with the addresses of the physical pages
|
|
1750 |
which contain the specified region. These addresses are the start of each page,
|
|
1751 |
(they are a multiple of the physical page size), therefore the byte corresponding
|
|
1752 |
to aOffset is at physical address aPageList[0]+aOffset%MMU_page_size.
|
|
1753 |
|
|
1754 |
@return 0 if successful.
|
|
1755 |
KErrAccessDenied if any part of region doesn't belong to "trusted" chunk.
|
|
1756 |
Other if memory region is invalid, or mapped in 1MB sections or large pages.
|
|
1757 |
|
|
1758 |
@pre Calling thread must be in critical section.
|
|
1759 |
@pre No fast mutex held.
|
|
1760 |
|
|
1761 |
@internalComponent
|
|
1762 |
*/
|
|
1763 |
EXPORT_C TInt Kern::PrepareMemoryForDMA(DThread* aThread, TAny* aAddress, TInt aSize, TPhysAddr* aPageList)
|
|
1764 |
{
|
|
1765 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::PrepareMemoryForDMA");
|
|
1766 |
__KTRACE_OPT(KMMU2,Kern::Printf("Kern::PrepareMemoryForDMA T:%x, A:%x, S:%x, Prt:%x",aThread, aAddress, aSize, aPageList));
|
|
1767 |
if(!aThread)
|
|
1768 |
aThread = &Kern::CurrentThread();
|
|
1769 |
return aThread->PrepareMemoryForDMA(aAddress, aSize, aPageList);
|
|
1770 |
}
|
|
1771 |
|
|
1772 |
/**
|
|
1773 |
Unlocks the physical pages that have been locked by PrepareMemoryForDMA.
|
|
1774 |
All input paramemers are the same as those in PrepareMemoryForDMA.
|
|
1775 |
|
|
1776 |
@see Kern::PrepareMemoryForDMA
|
|
1777 |
|
|
1778 |
@param aThread The thread in whose process the given address lies. If zero, the current thread is used.
|
|
1779 |
@param aAddress An address in the given threads process.
|
|
1780 |
@param aSize The size of the region.
|
|
1781 |
@param aPageList Points to the list of pages returned by PrepareMemoryForDMA.
|
|
1782 |
|
|
1783 |
@return 0 if successful.
|
|
1784 |
KErrArgument if the list of physical pages is invalid.
|
|
1785 |
|
|
1786 |
@pre Calling thread must be in critical section.
|
|
1787 |
@pre No fast mutex held.
|
|
1788 |
|
|
1789 |
@internalComponent
|
|
1790 |
*/
|
|
1791 |
EXPORT_C TInt Kern::ReleaseMemoryFromDMA(DThread* aThread, TAny* aAddress, TInt aSize, TPhysAddr* aPageList)
|
|
1792 |
{
|
|
1793 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Kern::ReleaseMemoryFromDMA");
|
|
1794 |
__KTRACE_OPT(KMMU2,Kern::Printf("Kern::ReleaseMemoryFromDMA T:%x, A:%x, S:%x, Prt:%x",aThread, aAddress, aSize, aPageList));
|
|
1795 |
if(!aThread)
|
|
1796 |
aThread = &Kern::CurrentThread();
|
|
1797 |
return aThread->ReleaseMemoryFromDMA(aAddress, aSize, aPageList);
|
|
1798 |
}
|
|
1799 |
|
|
1800 |
/**
|
|
1801 |
Installs Trace Handler Hook.
|
|
1802 |
@param aHandler Trace Handler Hook. Will be called on any debug log .It includes user-side
|
|
1803 |
(@see RDebug::Print), kernel (@see Kern::Printf) and PlatSec logging.
|
|
1804 |
Set to NULL to uninstall the hook.
|
|
1805 |
@see TTraceHandler
|
|
1806 |
@return Previous hook or NULL.
|
|
1807 |
*/
|
|
1808 |
EXPORT_C TTraceHandler Kern::SetTraceHandler(TTraceHandler aHandler)
|
|
1809 |
{
|
|
1810 |
return (TTraceHandler) SetHook(EHookTrace, (TKernelHookFn)aHandler, ETrue);
|
|
1811 |
}
|
|
1812 |
|
|
1813 |
/********************************************
|
|
1814 |
* Kernel event dispatcher
|
|
1815 |
********************************************/
|
|
1816 |
|
|
1817 |
/** Returns whether the kernel has been built with __DEBUGGER_SUPPORT__ defined. */
|
|
1818 |
|
|
1819 |
EXPORT_C TBool DKernelEventHandler::DebugSupportEnabled()
|
|
1820 |
{
|
|
1821 |
#ifdef __DEBUGGER_SUPPORT__
|
|
1822 |
return ETrue;
|
|
1823 |
#else
|
|
1824 |
return EFalse;
|
|
1825 |
#endif
|
|
1826 |
}
|
|
1827 |
|
|
1828 |
|
|
1829 |
/** Constructs an event handler.
|
|
1830 |
The handler is not queued.
|
|
1831 |
@param aCb Pointer to C callback function called when an event occurs.
|
|
1832 |
@param aPrivateData Data to be passed to the callback function.
|
|
1833 |
|
|
1834 |
@pre Calling thread must be in a critical section.
|
|
1835 |
@pre No fast mutex can be held.
|
|
1836 |
@pre Call in a thread context.
|
|
1837 |
@pre Kernel must be unlocked
|
|
1838 |
@pre interrupts enabled
|
|
1839 |
*/
|
|
1840 |
|
|
1841 |
EXPORT_C DKernelEventHandler::DKernelEventHandler(TCallback aCb, TAny* aPrivateData)
|
|
1842 |
: iAccessCount(1),
|
|
1843 |
iCb(aCb),
|
|
1844 |
iPrivateData(aPrivateData)
|
|
1845 |
{
|
|
1846 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"DKernelEventHandler::DKernelEventHandler");
|
|
1847 |
__ASSERT_DEBUG(aCb != NULL, K::Fault(K::EDebugEventHandlerBadCallBack));
|
|
1848 |
}
|
|
1849 |
|
|
1850 |
/** Adds handler in handler queue.
|
|
1851 |
@param aPolicy Selects where the handler should be inserted.
|
|
1852 |
@return standard error code
|
|
1853 |
|
|
1854 |
@pre No fast mutex can be held.
|
|
1855 |
@pre Call in a thread context.
|
|
1856 |
@pre Kernel must be unlocked
|
|
1857 |
@pre interrupts enabled
|
|
1858 |
*/
|
|
1859 |
|
|
1860 |
EXPORT_C TInt DKernelEventHandler::Add(TAddPolicy /*aPolicy*/)
|
|
1861 |
{
|
|
1862 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"DKernelEventHandler::Add");
|
|
1863 |
NKern::LockSystem();
|
|
1864 |
if (!iLink.iNext)
|
|
1865 |
{
|
|
1866 |
HandlersQ.Add(&iLink);
|
|
1867 |
}
|
|
1868 |
NKern::UnlockSystem();
|
|
1869 |
return KErrNone;
|
|
1870 |
}
|
|
1871 |
|
|
1872 |
/** Decrements access count.
|
|
1873 |
Removes from queue and asynchronously destruct it if access count reaches zero.
|
|
1874 |
@return original access count.
|
|
1875 |
|
|
1876 |
@pre Calling thread must be in a critical section.
|
|
1877 |
@pre No fast mutex can be held.
|
|
1878 |
@pre Call in a thread context.
|
|
1879 |
@pre Kernel must be unlocked
|
|
1880 |
@pre interrupts enabled
|
|
1881 |
*/
|
|
1882 |
|
|
1883 |
EXPORT_C TInt DKernelEventHandler::Close()
|
|
1884 |
{
|
|
1885 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"DKernelEventHandler::Close");
|
|
1886 |
NKern::LockSystem();
|
|
1887 |
TInt r=iAccessCount;
|
|
1888 |
if (r>0 && --iAccessCount==0)
|
|
1889 |
{
|
|
1890 |
if (iLink.iNext)
|
|
1891 |
{
|
|
1892 |
iLink.Deque();
|
|
1893 |
iLink.iNext=NULL;
|
|
1894 |
}
|
|
1895 |
}
|
|
1896 |
NKern::UnlockSystem();
|
|
1897 |
if (r==1)
|
|
1898 |
AsyncDelete();
|
|
1899 |
return r;
|
|
1900 |
}
|
|
1901 |
|
|
1902 |
/** Sends event to all handlers in queue.
|
|
1903 |
@internalTechnology
|
|
1904 |
*/
|
|
1905 |
|
|
1906 |
TUint DKernelEventHandler::Dispatch(TKernelEvent aType, TAny* a1, TAny* a2)
|
|
1907 |
{
|
|
1908 |
TUint action = ERunNext;
|
|
1909 |
NKern::ThreadEnterCS();
|
|
1910 |
NKern::LockSystem();
|
|
1911 |
SDblQueLink* pE=&HandlersQ.iA;
|
|
1912 |
SDblQueLink* pL=pE->iNext;
|
|
1913 |
DKernelEventHandler* pD=NULL;
|
|
1914 |
while (pL!=pE)
|
|
1915 |
{
|
|
1916 |
DKernelEventHandler* pH=_LOFF(pL,DKernelEventHandler,iLink);
|
|
1917 |
++pH->iAccessCount;
|
|
1918 |
NKern::UnlockSystem();
|
|
1919 |
if (pD)
|
|
1920 |
{
|
|
1921 |
pD->AsyncDelete();
|
|
1922 |
pD=NULL;
|
|
1923 |
}
|
|
1924 |
action=pH->iCb(aType, a1, a2, pH->iPrivateData);
|
|
1925 |
NKern::LockSystem();
|
|
1926 |
SDblQueLink* pN=pL->iNext;
|
|
1927 |
if (--pH->iAccessCount==0)
|
|
1928 |
{
|
|
1929 |
pL->Deque();
|
|
1930 |
pL->iNext=NULL;
|
|
1931 |
pD=pH;
|
|
1932 |
}
|
|
1933 |
if (!(action & ERunNext))
|
|
1934 |
break;
|
|
1935 |
pL=pN;
|
|
1936 |
}
|
|
1937 |
NKern::UnlockSystem();
|
|
1938 |
if (pD)
|
|
1939 |
pD->AsyncDelete();
|
|
1940 |
NKern::ThreadLeaveCS();
|
|
1941 |
return action;
|
|
1942 |
}
|
|
1943 |
|
|
1944 |
|
|
1945 |
/******************************************************************************
|
|
1946 |
* Memory saving fast deterministic thread wait queue
|
|
1947 |
******************************************************************************/
|
|
1948 |
TThreadWaitList::TList* TThreadWaitList::FirstFree;
|
|
1949 |
TInt TThreadWaitList::NLists;
|
|
1950 |
TInt TThreadWaitList::NWaitObj;
|
|
1951 |
TInt TThreadWaitList::NThrd;
|
|
1952 |
|
|
1953 |
TThreadWaitList::~TThreadWaitList()
|
|
1954 |
{
|
|
1955 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"~TThreadWaitList");
|
|
1956 |
__ASSERT_ALWAYS((iWaitPtr==EEmpty || iWaitPtr==EInitValue), K::Fault(K::EThreadWaitListDestroy));
|
|
1957 |
if (iWaitPtr==EEmpty)
|
|
1958 |
Down(EFalse);
|
|
1959 |
}
|
|
1960 |
|
|
1961 |
TInt TThreadWaitList::Construct()
|
|
1962 |
{
|
|
1963 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"TThreadWaitList::Construct");
|
|
1964 |
TInt r = Up(EFalse);
|
|
1965 |
if (r==KErrNone)
|
|
1966 |
iWaitPtr = EEmpty;
|
|
1967 |
return r;
|
|
1968 |
}
|
|
1969 |
|
|
1970 |
TInt TThreadWaitList::ThreadCreated()
|
|
1971 |
{
|
|
1972 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"TThreadWaitList::ThreadCreated");
|
|
1973 |
return Up(ETrue);
|
|
1974 |
}
|
|
1975 |
|
|
1976 |
void TThreadWaitList::ThreadDestroyed()
|
|
1977 |
{
|
|
1978 |
CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"TThreadWaitList::ThreadDestroyed");
|
|
1979 |
Down(ETrue);
|
|
1980 |
}
|
|
1981 |
|
|
1982 |
TInt TThreadWaitList::Up(TBool aThread)
|
|
1983 |
{
|
|
1984 |
TList* l = 0;
|
|
1985 |
TInt r = 1;
|
|
1986 |
do {
|
|
1987 |
NKern::LockSystem();
|
|
1988 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf(">TThreadWaitList::Up W=%d T=%d L=%d l=%08x", NWaitObj, NThrd, NLists, l));
|
|
1989 |
TInt nw=NWaitObj, nt=NThrd;
|
|
1990 |
aThread ? ++nt : ++nw;
|
|
1991 |
TInt needed = Min(nt/2, nw);
|
|
1992 |
if (needed<=NLists)
|
|
1993 |
goto done;
|
|
1994 |
else if (l)
|
|
1995 |
{
|
|
1996 |
++NLists;
|
|
1997 |
l->Next() = FirstFree;
|
|
1998 |
FirstFree = l;
|
|
1999 |
l = 0;
|
|
2000 |
done:
|
|
2001 |
NThrd=nt, NWaitObj=nw;
|
|
2002 |
r = KErrNone;
|
|
2003 |
}
|
|
2004 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("<TThreadWaitList::Up W=%d T=%d L=%d l=%08x", NWaitObj, NThrd, NLists, l));
|
|
2005 |
NKern::UnlockSystem();
|
|
2006 |
if (r!=KErrNone)
|
|
2007 |
{
|
|
2008 |
__ASSERT_ALWAYS(!l, K::Fault(K::EThreadWaitListUp));
|
|
2009 |
l = new TList;
|
|
2010 |
if (!l)
|
|
2011 |
r = KErrNoMemory;
|
|
2012 |
}
|
|
2013 |
} while (r>0);
|
|
2014 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("<TThreadWaitList::Up l=%08x r=%d", l, r));
|
|
2015 |
delete l;
|
|
2016 |
return r;
|
|
2017 |
}
|
|
2018 |
|
|
2019 |
void TThreadWaitList::Down(TBool aThread)
|
|
2020 |
{
|
|
2021 |
TList* l = 0;
|
|
2022 |
NKern::LockSystem();
|
|
2023 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf(">TThreadWaitList::Down W=%d T=%d L=%d", NWaitObj, NThrd, NLists));
|
|
2024 |
aThread ? --NThrd : --NWaitObj;
|
|
2025 |
TInt needed = Min(NThrd/2, NWaitObj);
|
|
2026 |
if (needed < NLists)
|
|
2027 |
{
|
|
2028 |
--NLists;
|
|
2029 |
l = FirstFree;
|
|
2030 |
FirstFree = l->Next();
|
|
2031 |
}
|
|
2032 |
__KTRACE_OPT(KSEMAPHORE,Kern::Printf("<TThreadWaitList::Down W=%d T=%d L=%d l=%08x", NWaitObj, NThrd, NLists, l));
|
|
2033 |
NKern::UnlockSystem();
|
|
2034 |
delete l;
|
|
2035 |
}
|
|
2036 |
|
|
2037 |
#ifndef __PRI_LIST_MACHINE_CODED__
|
|
2038 |
DThread* TThreadWaitList::First() const
|
|
2039 |
{
|
|
2040 |
__DEBUG_ONLY(Check());
|
|
2041 |
if (iWaitPtr == EEmpty)
|
|
2042 |
return 0;
|
|
2043 |
if (!(iWaitPtr & EFlagList))
|
|
2044 |
return (DThread*)iWaitPtr;
|
|
2045 |
TList* l = (TList*)(iWaitPtr&~EFlagList);
|
|
2046 |
return _LOFF(l->First(),DThread,iWaitLink);
|
|
2047 |
}
|
|
2048 |
|
|
2049 |
TInt TThreadWaitList::HighestPriority() const
|
|
2050 |
{
|
|
2051 |
__DEBUG_ONLY(Check());
|
|
2052 |
if (iWaitPtr==EEmpty)
|
|
2053 |
return -1;
|
|
2054 |
if (!(iWaitPtr & EFlagList))
|
|
2055 |
return ((DThread*)iWaitPtr)->iWaitLink.iPriority;
|
|
2056 |
TList* l = (TList*)(iWaitPtr&~EFlagList);
|
|
2057 |
return l->HighestPriority();
|
|
2058 |
}
|
|
2059 |
|
|
2060 |
void TThreadWaitList::Add(DThread* aThread)
|
|
2061 |
{
|
|
2062 |
__DEBUG_ONLY(Check());
|
|
2063 |
if (iWaitPtr==EEmpty)
|
|
2064 |
{
|
|
2065 |
iWaitPtr = (TLinAddr)aThread;
|
|
2066 |
return;
|
|
2067 |
}
|
|
2068 |
TList* l = 0;
|
|
2069 |
if (iWaitPtr&EFlagList)
|
|
2070 |
l = (TList*)(iWaitPtr&~EFlagList);
|
|
2071 |
else
|
|
2072 |
{
|
|
2073 |
DThread* t0 = (DThread*)iWaitPtr;
|
|
2074 |
l = FirstFree;
|
|
2075 |
FirstFree = l->Next();
|
|
2076 |
l->Next() = 0;
|
|
2077 |
iWaitPtr = TLinAddr(l)|EFlagList;
|
|
2078 |
l->Add(&t0->iWaitLink);
|
|
2079 |
}
|
|
2080 |
l->Add(&aThread->iWaitLink);
|
|
2081 |
}
|
|
2082 |
|
|
2083 |
void TThreadWaitList::Remove(DThread* aThread)
|
|
2084 |
{
|
|
2085 |
__DEBUG_ONLY(Check());
|
|
2086 |
__ASSERT_DEBUG(iWaitPtr!=EEmpty && ((iWaitPtr&EFlagList)||(iWaitPtr==(TLinAddr)aThread)), K::Fault(K::EThreadWaitListRemove));
|
|
2087 |
if (!(iWaitPtr&EFlagList))
|
|
2088 |
{
|
|
2089 |
iWaitPtr = EEmpty;
|
|
2090 |
return;
|
|
2091 |
}
|
|
2092 |
TList* l = (TList*)(iWaitPtr&~EFlagList);
|
|
2093 |
l->Remove(&aThread->iWaitLink);
|
|
2094 |
TUint p0 = l->iPresent[0];
|
|
2095 |
TUint p1 = l->iPresent[1];
|
|
2096 |
if ((p0&&p1) || (p0&(p0-1)) || (p1&(p1-1)))
|
|
2097 |
return;
|
|
2098 |
TPriListLink* wl = l->First();
|
|
2099 |
__ASSERT_DEBUG(wl, K::Fault(K::EThreadWaitListRemove2));
|
|
2100 |
if (wl->iNext != wl)
|
|
2101 |
return;
|
|
2102 |
DThread* t = _LOFF(wl,DThread,iWaitLink);
|
|
2103 |
l->Remove(&t->iWaitLink);
|
|
2104 |
iWaitPtr = (TLinAddr)t;
|
|
2105 |
l->Next() = FirstFree;
|
|
2106 |
FirstFree = l;
|
|
2107 |
}
|
|
2108 |
|
|
2109 |
void TThreadWaitList::ChangePriority(DThread* aThread, TInt aNewPriority)
|
|
2110 |
{
|
|
2111 |
__DEBUG_ONLY(Check());
|
|
2112 |
__ASSERT_DEBUG(iWaitPtr!=EEmpty && ((iWaitPtr&EFlagList)||(iWaitPtr==(TLinAddr)aThread)), K::Fault(K::EThreadWaitListChangePriority));
|
|
2113 |
if (!(iWaitPtr & EFlagList))
|
|
2114 |
aThread->iWaitLink.iPriority = (TUint8)aNewPriority;
|
|
2115 |
else
|
|
2116 |
{
|
|
2117 |
TList* l = (TList*)(iWaitPtr&~EFlagList);
|
|
2118 |
l->ChangePriority(&aThread->iWaitLink, aNewPriority);
|
|
2119 |
}
|
|
2120 |
}
|
|
2121 |
#endif
|
|
2122 |
|
|
2123 |
#ifdef _DEBUG
|
|
2124 |
// Check the system lock is held and second phase construction has completed
|
|
2125 |
// successfully
|
|
2126 |
void TThreadWaitList::Check() const
|
|
2127 |
{
|
|
2128 |
__ASSERT_SYSTEM_LOCK;
|
|
2129 |
TUint32 mask = RHeap::ECellAlignment-1;
|
|
2130 |
TUint32 lowbits = iWaitPtr & mask;
|
|
2131 |
__ASSERT_ALWAYS(lowbits<=1, K::Fault(K::EThreadWaitListCheck));
|
|
2132 |
}
|
|
2133 |
#endif
|