Update contrib.
1 // Copyright (c) 2008-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.
14 // e32test\thread\smpsafe.cpp
19 #include <e32std_private.h>
20 #include <e32atomics.h>
22 IMPORT_C void DoNothingA();
23 IMPORT_C void DoNothingB();
24 IMPORT_C void DoNothingC();
25 IMPORT_C void DoNothingD();
26 IMPORT_C void DoNothingE();
31 EXPORT_C void DoNothingA() {}
35 EXPORT_C void DoNothingB() { DoNothingA(); }
39 EXPORT_C void DoNothingC() { DoNothingD(); DoNothingE(); }
43 EXPORT_C void DoNothingD() { DoNothingC(); }
47 EXPORT_C void DoNothingE() { DoNothingC(); }
52 volatile TInt Affinity;
56 const TInt KLoopTries = 100;
58 // This gets run in a low priority thread. Each time around the loop it waits to be told to go,
59 // then sets Affinity to 0, then tells the other thread it's done. If we're actually locked to
60 // the same processor as the main thread, however, then we won't get to run until the other thread
61 // waits for the Stop semaphore, and thus Affinity will not get set to 0 until the other thread
62 // checked it already.
63 TInt AffinitySlave(TAny*)
65 for (TInt i = KLoopTries; i>0; --i)
77 TInt r = t.Create(_L("AffinitySlave"), AffinitySlave, KDefaultStackSize, NULL, NULL);
86 t.SetPriority(EPriorityLess);
90 for (TInt i = KLoopTries; i>0; --i)
92 Affinity = 1; // assume we are locked to a single cpu
93 Start.Signal(); // tell the other thread to run
94 TUint32 target = User::NTickCount() + 10;
95 while (User::NTickCount() < target)
97 // spin, waiting to see if the other thread actually *does* run
102 Stop.Wait(); // We didn't see it this time, but try again in case of scheduling fluke
106 User::WaitForRequest(s);
113 GLDEF_C TInt E32Main()
121 return CheckAffinity();