Update contrib.
1 // Copyright (c) 2002-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
13 // e32test\smpsoak\d_smpsoak.cpp
16 // LDD for smpsoak - setting Thread CPU Affinity
19 #include "d_smpsoak.h"
21 #include <kernel/kern_priv.h>
23 const TInt KMajorVersionNumber=0;
24 const TInt KMinorVersionNumber=1;
25 const TInt KBuildVersionNumber=1;
27 class DSmpSoakFactory : public DLogicalDevice
29 // IPC copy LDD factory
34 virtual TInt Install(); //overriding pure virtual
35 virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
36 virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
39 class DSmpSoak : public DLogicalChannelBase
45 virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
46 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
48 static void IDfcFn(TAny* aPtr);
53 DECLARE_STANDARD_LDD()
55 Kern::Printf("DSmpSoak called");
56 return new DSmpSoakFactory;
59 DSmpSoakFactory::DSmpSoakFactory()
64 Kern::Printf("DSmpSoakFactory::DSmpSoakFactory called");
65 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
68 TInt DSmpSoakFactory::Create(DLogicalChannelBase*& aChannel)
70 // Create a new DSmpSoak on this logical device
73 Kern::Printf("DSmpSoakFactory::Create called");
74 aChannel=new DSmpSoak;
75 return aChannel?KErrNone:KErrNoMemory;
78 TInt DSmpSoakFactory::Install()
80 // Install the LDD - overriding pure virtual
83 Kern::Printf("DSmpSoakFactory::Install called");
84 return SetName(&KSmpSoakLddName);
87 void DSmpSoakFactory::GetCaps(TDes8& aDes) const
89 // Get capabilities - overriding pure virtual
92 Kern::Printf("DSmpSoakFactory::GetCaps called");
100 Kern::Printf("DSmpSoak::DSmpSoak called");
103 DSmpSoak::~DSmpSoak()
105 Kern::Printf("DSmpSoak::~DSmpSoak called");
108 TInt DSmpSoak::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
113 Kern::Printf("DSmpSoak::DoCreate called");
115 if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
116 return KErrNotSupported;
122 TInt DSmpSoak::Request(TInt aFunction, TAny* a1, TAny* a2)
125 NThread *pMyNThread = NULL;
126 TInt handle = (TInt)a1;
127 TInt priority = (TInt)a2;
129 TInt r = KErrNotSupported;
130 Kern::Printf("DSmpSoak::Request called aFunction = %d, a1 = %d, a2 = %d", aFunction, a1, a2);
134 case RSMPSoak::KGETPROCESSORCOUNT:
135 r = NKern::NumberOfCpus();
136 Kern::Printf("DSmpSoak::Request Processor count = %d", r);
138 case RSMPSoak::KGETCURRENTCPU:
139 r = NKern::CurrentCpu();
140 Kern::Printf("DSmpSoak::Request Current CPU = %d", r);
142 case RSMPSoak::KGETCURRENTTHREAD:
143 r = (TInt)NKern::CurrentThread();
144 Kern::Printf("DSmpSoak::Request Current Thread %02x", r);
146 case RSMPSoak::KTHREADSETCPUAFFINITY:
147 r = NKern::ThreadSetCpuAffinity(NKern::CurrentThread(), (TInt)a1);
148 r = (TInt)NKern::CurrentCpu();
149 Kern::Printf("DSmpSoak::Request Current Cpu = %d", r);
151 case RSMPSoak::KOCCUPYCPUS:
152 Kern::Printf("DSmpSoak::Request OCCUPYCPUS: called");
155 case RSMPSoak::KCHANGEAFFINITY:
156 Kern::Printf("DSmpSoak::Request CHANGEAFFINITY");
158 pT=(DThread*)Kern::CurrentThread().ObjectFromHandle(handle);
159 pMyNThread=(NThread*)&pT->iNThread;
160 NKern::ThreadSetCpuAffinity((NThread*)pMyNThread, (TInt)a2);
161 NKern::UnlockSystem();
163 case RSMPSoak::KCHANGETHREADPRIORITY:
164 Kern::Printf("DSmpSoak::Request CHANGETHREADPRIORITY");
166 pT=(DThread*)Kern::CurrentThread().ObjectFromHandle(handle);
167 Kern::Printf("DSmpSoak::Request Current Thread %d", pT);
168 pT->SetThreadPriority(priority);
169 Kern::Printf("DSmpSoak::CHANGETHREADPRIORITY now %d", pT->iThreadPriority);
170 NKern::UnlockSystem();
173 Kern::Printf("DSmpSoak::Request default: called");
179 void DSmpSoak::OccupyCpus()
181 Kern::Printf(">>>DSmpSoak::OccupyCpus()");