0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\thread\smpsafe.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <e32std_private.h>
|
|
20 |
#include <e32atomics.h>
|
|
21 |
|
|
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();
|
|
27 |
|
|
28 |
#ifdef MAKE_DLL
|
|
29 |
|
|
30 |
#ifdef PROVIDE_A
|
|
31 |
EXPORT_C void DoNothingA() {}
|
|
32 |
#endif
|
|
33 |
|
|
34 |
#ifdef PROVIDE_B
|
|
35 |
EXPORT_C void DoNothingB() { DoNothingA(); }
|
|
36 |
#endif
|
|
37 |
|
|
38 |
#ifdef PROVIDE_C
|
|
39 |
EXPORT_C void DoNothingC() { DoNothingD(); DoNothingE(); }
|
|
40 |
#endif
|
|
41 |
|
|
42 |
#ifdef PROVIDE_D
|
|
43 |
EXPORT_C void DoNothingD() { DoNothingC(); }
|
|
44 |
#endif
|
|
45 |
|
|
46 |
#ifdef PROVIDE_E
|
|
47 |
EXPORT_C void DoNothingE() { DoNothingC(); }
|
|
48 |
#endif
|
|
49 |
|
|
50 |
#else // !MAKE_DLL
|
|
51 |
|
|
52 |
TInt Affinity;
|
|
53 |
|
|
54 |
TInt AffinitySlave(TAny*)
|
|
55 |
{
|
|
56 |
for (;;)
|
|
57 |
{
|
|
58 |
__e32_atomic_store_rel32(&Affinity, 0); // we can't be locked if this runs
|
|
59 |
User::AfterHighRes(1);
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
TInt CheckAffinity()
|
|
64 |
{
|
|
65 |
__e32_atomic_store_rel32(&Affinity, 1); // assume we are locked to a single cpu
|
|
66 |
|
|
67 |
RThread t;
|
|
68 |
TInt r = t.Create(_L("AffinitySlave"), AffinitySlave, KDefaultStackSize, NULL, NULL);
|
|
69 |
if (r != KErrNone)
|
|
70 |
return r;
|
|
71 |
|
|
72 |
TRequestStatus s;
|
|
73 |
t.Logon(s);
|
|
74 |
t.SetPriority(EPriorityLess);
|
|
75 |
t.Resume();
|
|
76 |
|
|
77 |
TUint32 target = User::NTickCount() + 10;
|
|
78 |
while (User::NTickCount() < target) {}
|
|
79 |
|
|
80 |
r = __e32_atomic_load_acq32(&Affinity);
|
|
81 |
|
|
82 |
t.Kill(0);
|
|
83 |
User::WaitForRequest(s);
|
|
84 |
t.Close();
|
|
85 |
|
|
86 |
return r;
|
|
87 |
}
|
|
88 |
|
|
89 |
#ifndef OMIT_MAIN
|
|
90 |
GLDEF_C TInt E32Main()
|
|
91 |
{
|
|
92 |
#ifdef USE_A
|
|
93 |
DoNothingA();
|
|
94 |
#endif
|
|
95 |
#ifdef USE_B
|
|
96 |
DoNothingB();
|
|
97 |
#endif
|
|
98 |
return CheckAffinity();
|
|
99 |
}
|
|
100 |
#endif // OMIT_MAIN
|
|
101 |
|
|
102 |
#endif
|