author | Mark Wilcox <markw@symbian.org> |
Tue, 25 May 2010 13:20:47 +0100 | |
changeset 116 | 57eea1054f46 |
parent 90 | 947f0dc9f7a8 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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\nkern\sched.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
// TDfc member data |
|
19 |
#define __INCLUDE_TDFC_DEFINES__ |
|
20 |
#define __INCLUDE_NTHREADBASE_DEFINES__ |
|
21 |
||
22 |
#include "nk_priv.h" |
|
23 |
||
24 |
void ResumeDelayedThreads(TAny*) |
|
25 |
{ |
|
26 |
TScheduler& s=TheScheduler; |
|
27 |
while (!s.iDelayedQ.IsEmpty()) |
|
28 |
{ |
|
29 |
NThreadBase& t = *(NThreadBase*)s.iDelayedQ.First()->Deque(); |
|
30 |
t.i_ThrdAttr &= ~KThreadAttDelayed; |
|
31 |
if (t.iSuspendCount==0) |
|
32 |
t.DoReady(); |
|
33 |
else |
|
34 |
t.iNState=NThreadBase::ESuspended; |
|
35 |
} |
|
36 |
} |
|
37 |
||
38 |
// Don't need to zero initialise anything here since |
|
39 |
// TheScheduler resides in .bss |
|
40 |
TScheduler::TScheduler() |
|
41 |
: TPriListBase(KNumPriorities), iKernCSLocked(1), iDelayDfc(ResumeDelayedThreads, NULL) |
|
42 |
{ |
|
43 |
} |
|
44 |
||
45 |
||
46 |
/** Return a pointer to the scheduler |
|
47 |
Intended for use by the crash debugger, not for general device driver use. |
|
48 |
||
49 |
@return Pointer to the scheduler object |
|
50 |
@internalTechnology |
|
51 |
*/ |
|
52 |
EXPORT_C TScheduler* TScheduler::Ptr() |
|
53 |
{ |
|
54 |
return &TheScheduler; |
|
55 |
} |
|
56 |
||
57 |
||
58 |
#ifndef __MSTIM_MACHINE_CODED__ |
|
59 |
// Enter and leave with interrupts off |
|
60 |
void TScheduler::TimesliceTick() |
|
61 |
{ |
|
62 |
NThreadBase* pC=iCurrentThread; |
|
63 |
if (pC->iTime>0 && --pC->iTime==0) |
|
64 |
RescheduleNeeded(); |
|
65 |
} |
|
66 |
#endif |
|
67 |
||
68 |
#ifndef __SCHEDULER_MACHINE_CODED__ |
|
69 |
void TScheduler::Remove(NThreadBase* aThread) |
|
70 |
{ |
|
71 |
__NK_ASSERT_DEBUG(!aThread->iHeldFastMutex); // can't block while holding fast mutex |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
iMadeUnReadyCounter++; |
0 | 73 |
aThread->iTime=aThread->iTimeslice; // thread has blocked so it gets a fresh timeslice for next time |
74 |
TPriListBase::Remove(aThread); |
|
75 |
} |
|
76 |
#endif |
|
77 |
||
78 |
void TScheduler::RotateReadyList(TInt p) |
|
79 |
// |
|
80 |
// rotate the ready list for priority p |
|
81 |
// |
|
82 |
{ |
|
83 |
__NK_ASSERT_DEBUG(p>=0 && p<KNumPriorities); |
|
84 |
SDblQueLink* pQ=iQueue[p]; |
|
85 |
if (pQ) |
|
86 |
{ |
|
87 |
SDblQueLink* pN=pQ->iNext; |
|
88 |
if (pN!=pQ) |
|
89 |
{ |
|
90 |
NThread* pT=(NThread*)pQ; |
|
91 |
pT->iTime=pT->iTimeslice; |
|
92 |
iQueue[p]=pN; |
|
93 |
if (pQ==iCurrentThread) |
|
94 |
RescheduleNeeded(); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
/** Converts a time interval in microseconds to thread timeslice ticks |
|
100 |
||
101 |
@param aMicroseconds time interval in microseconds. |
|
102 |
@return Number of thread timeslice ticks. Non-integral results are rounded up. |
|
103 |
||
104 |
@pre aMicroseconds should be nonnegative |
|
105 |
@pre any context |
|
106 |
*/ |
|
107 |
EXPORT_C TInt NKern::TimesliceTicks(TUint32 aMicroseconds) |
|
108 |
{ |
|
109 |
TUint32 msp = TheTimerQ.iTickPeriod; |
|
110 |
TUint32 ticks = (TUint32(aMicroseconds) + msp - 1) / msp; |
|
111 |
return ticks; |
|
112 |
} |
|
113 |
||
114 |
||
115 |
/** Return the total CPU time so far used by the specified thread. |
|
116 |
||
117 |
@return The total CPU time in units of 1/NKern::CpuTimeMeasFreq(). |
|
118 |
*/ |
|
119 |
EXPORT_C TUint64 NKern::ThreadCpuTime(NThread* aThread) |
|
120 |
{ |
|
121 |
#ifdef MONITOR_THREAD_CPU_TIME |
|
122 |
NKern::Lock(); |
|
123 |
TUint64 t = aThread->iTotalCpuTime; |
|
124 |
if (aThread == TheScheduler.iCurrentThread) |
|
125 |
t += TUint64(NKern::FastCounter() - aThread->iLastStartTime); |
|
126 |
NKern::Unlock(); |
|
127 |
return t; |
|
128 |
#else |
|
129 |
return 0; |
|
130 |
#endif |
|
131 |
} |