Update contrib.
1 // Copyright (c) 1995-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 "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.
16 #include "openwfcthreadmanager.h"
17 #include "openwfcjobmanager.h"
20 COpenWfcMonitorThread::COpenWfcMonitorThread(COpenWfcJobManger& aManager):
27 COpenWfcMonitorThread::~COpenWfcMonitorThread()
30 TRequestStatus threadDies = KErrNone;
32 iThread.Logon(threadDies);
33 if (iThread.ExitType() == EExitPending ||
34 threadDies != KRequestPending)
36 User::WaitForRequest(threadDies);
42 void COpenWfcMonitorThread::ConstructL(TInt aScreenNumber)
44 TBuf <255> threadManagerName;
46 * At a given instant in time, one screen can have at most one monitor
47 * thread. Test code will, for a given screen, destroy and re-create
50 * At appears that the thread, once killed off, still lingers in
51 * the OS for a short time. The newly created thread fails to create
52 * if it shares the same name as the one that was killed but still is
55 * A unique name is needed. This is guaranteed by using a thread name
56 * which includes a microsecond counter. This counter wraps every hour,
57 * roughly. This is comfortably outside the race condition above.
59 * To make debugging easier, we also include the screen number in
62 * Thus, the thread name is:
63 * WFCMonitorThread_<ScreenNumber>_<MicrosecondCounter>
65 _LIT(KThreadName, "WFCMonitorThread_%d_%d");
68 TInt microseconds = I64LOW(now.Int64());
69 threadManagerName.Format(KThreadName, aScreenNumber, microseconds);
71 User::LeaveIfError(iThread.Create(threadManagerName,
72 static_cast<TThreadFunction>(&COpenWfcMonitorThread::Main),
77 iThread.SetPriority(EPriorityNormal);
78 User::LeaveIfError(iSemaphore.CreateLocal(0));
82 COpenWfcMonitorThread* COpenWfcMonitorThread::NewLC(TInt aNumber, COpenWfcJobManger& aManager)
84 COpenWfcMonitorThread* self = new(ELeave) COpenWfcMonitorThread(aManager);
85 CleanupStack::PushL(self);
86 self->ConstructL(aNumber);
90 COpenWfcMonitorThread* COpenWfcMonitorThread::NewL(TInt aNumber, COpenWfcJobManger& aManager)
92 COpenWfcMonitorThread* self = COpenWfcMonitorThread::NewLC(aNumber, aManager);
93 CleanupStack::Pop(self);
97 TInt COpenWfcMonitorThread::Main(TAny *aSelf)
99 COpenWfcMonitorThread* self = static_cast<COpenWfcMonitorThread*>(aSelf);
103 void COpenWfcMonitorThread::Start()
105 iThread.Rendezvous(iThreadStatus);
107 User::WaitForRequest(iThreadStatus);
110 void COpenWfcMonitorThread::Resume()
115 void COpenWfcMonitorThread::EndThread()
121 void COpenWfcMonitorThread::Suspend()
126 void COpenWfcMonitorThread::Signal()
131 TInt COpenWfcMonitorThread::Run()
133 RThread::Rendezvous(KErrNone);
134 JQLOG(("** START * COpenWfcMonitorThread::Run()"));
137 JQLOG(("** WAIT FOR SIGNAL * CCOpenwfcMonitorThread::Run()"));
142 iManager.DoExecuteJob();
146 /* Release any use of EGL by this thread. */
149 JQLOG(("** EXIT * COpenWfcMonitorThread::Run()"));