CVS update: /common/system/pub/platform/symbian/
gwright at helixcommunity.org gwright at helixcommunity.orgUser: gwright Date: 03/01/13 10:44:17 Added /common/system/pub/platform/symbian/ symbianthreads.h Log First checkin of symbian threads lib. File Changes: Directory: /common/system/pub/platform/symbian/ =============================================== File [added]: symbianthreads.h Url: https://common.helixcommunity.org/source/browse/common/system/pub/platform/symbian/symbianthreads.h?rev=1.1&content-type=text/vnd.viewcvs-markup Added lines: 258 ---------------- /* ***** BEGIN LICENSE BLOCK ***** * Version: RCSL 1.0/RPSL 1.0 * * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, are * subject to the current version of the RealNetworks Public Source License * Version 1.0 (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the RealNetworks Community Source License Version 1.0 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, * in which case the RCSL will apply. You may also obtain the license terms * directly from RealNetworks. You may not use this file except in * compliance with the RPSL or, if you have a valid RCSL with RealNetworks * applicable to this file, the RCSL. Please see the applicable RPSL or * RCSL for the rights, obligations and limitations governing use of the * contents of the file. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the portions * it created. * * This file, and the files included with this file, is distributed and made * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ #ifndef _SYMBIANTHREADSH #define _SYMBIANTHREADSH #include "hxthread.h" #include <e32std.h> #include <e32base.h> //======================================================================= // // HXSymbianMutex // ------------------ // // NOTE: Mutexs must be recursive. //======================================================================= class HXSymbianMutex : public HXMutex { public: //Ctors and dtors. HXSymbianMutex(); virtual ~HXSymbianMutex(); //inherited methods. virtual HX_RESULT Lock(); virtual HX_RESULT Unlock(); virtual HX_RESULT Trylock(); protected: HX_RESULT _Init(); private: RCriticalSection* m_pCritSec; BOOL m_bInited; //Symbian mutexes, if that is what you want to call them, are //not recursive. We need them to be so we roll our own. RCriticalSection* m_pCritSecLck; ULONG32 m_ulOwnerThread; ULONG32 m_ulLockCount; //Prevent unintentional ctors HXSymbianMutex( const HXSymbianMutex& ); //copy ctor HXSymbianMutex& operator=(const HXSymbianMutex& ); //assignment operator. }; //======================================================================= // // HXSymbianEvent // ------------------ // //======================================================================= class HXSymbianEvent : public HXEvent { public: HXSymbianEvent(const char* pEventName = NULL, BOOL bManualReset=TRUE); virtual ~HXSymbianEvent(); virtual HX_RESULT SignalEvent(); virtual HX_RESULT ResetEvent(); virtual void* GetEventHandle(); virtual HX_RESULT Wait( UINT32 uTimeoutPeriod = ALLFS ); protected: private: BOOL m_bIsManualReset; BOOL m_bEventIsSet; HXSymbianMutex* m_pCondLock; RSemaphore* m_pCond; //Protect unintentional ctors HXSymbianEvent( const HXSymbianEvent& ); //copy ctor. HXSymbianEvent& operator=(const HXSymbianEvent& ); //assignment oper. }; //======================================================================= // // HXSymbsymbianisymbiananThread // ------------------ // //======================================================================= class HXSymbianThread : public HXThread { public: HXSymbianThread(); virtual ~HXSymbianThread(); virtual HX_RESULT CreateThread( void*(pExecAddr(void*)), void* pArg, ULONG32 ulCreationFlags=0); virtual HX_RESULT Suspend(); virtual HX_RESULT Resume(); virtual HX_RESULT SetPriority( UINT32 ulPriority); virtual HX_RESULT GetPriority( UINT32& ulPriority); virtual HX_RESULT YieldTimeSlice(); virtual HX_RESULT Exit(UINT32 unExitCode); //This call returns the CREATED THREAD's ID, not the calling thread's. virtual HX_RESULT GetThreadId(UINT32& ulThreadId); //This call returns the *CALLING THREAD's ID* not the one that was created. virtual ULONG32 GetCurrentThreadID(); virtual HX_RESULT PostMessage(HXThreadMessage* pMsg, void* pWindowHandle=NULL); virtual HX_RESULT GetMessage( HXThreadMessage* pMsg, UINT32 ulMsgFilterMin = 0, //Not used for now. UINT32 ulMsgFilterMax = 0 //Not used for now. ); virtual HX_RESULT PeekMessageMatching( HXThreadMessage* pMsg, HXThreadMessage* pMatch, BOOL bRemoveMessage = 1 ); virtual HX_RESULT PeekMessage( HXThreadMessage* pMsg, UINT32 ulMsgFilterMin = 0, //Not used for now. UINT32 ulMsgFilterMax = 0, //Not used for now. BOOL bRemoveMessage = 1 ); virtual HX_RESULT DispatchMessage(HXThreadMessage* pMsg); protected: private: RThread* m_pThread; CHXSimpleList m_messageQue; //Our Message Que. //Used to make GetMessage blocking and to protect access to the que. RSemaphore* m_pSemMessageCount; //our message counting semaphore HXMutex* m_pmtxQue; //Request status used to join the thread. TRequestStatus m_reqStat; //Prevent unintentional ctors HXSymbianThread( const HXSymbianThread& ); //copy ctor HXSymbianThread& operator=(const HXSymbianThread&); //assignment operator. }; //XXXgfw I fist coded this to use RTimers for RunL callbacks to get //the work of the async timer done. But, if the thread that creates //the timer blocks at all we stop getting callbacks. I think now that //this may cause problems with the way Helix uses the timers. So, I am //going to code a version that uses real threads to get the work //done. You can use the below defines to build either one you want. #undef USE_SYMBIAN_RTIMERS_FOR_ASYNCTIMERS #define USE_SYMBIAN_THREADS_FOR_ASYNCTIMERS #ifdef USE_SYMBIAN_RTIMERS_FOR_ASYNCTIMERS class HXSymbianAsyncTimer : public CActive #else class HXSymbianAsyncTimer #endif // USE_SYMBIAN_RTIMERS_FOR_ASYNCTIMERS { public: // These two methods are the main interface into this class. It // make it work just like the windows ::SetTimer and ::KillTimer // functions. static UINT32 SetTimer(ULONG32 ulTimeOut, HXThread* pReceivingThread ); static UINT32 SetTimer(ULONG32 ulTimeOut, TIMERPROC pfExecFunc ); static BOOL KillTimer(UINT32 ulTimerID ); #ifdef USE_SYMBIAN_RTIMERS_FOR_ASYNCTIMERS //For active object stuff. void RunL(); void DoCancel(); #endif // USE_SYMBIAN_RTIMERS_FOR_ASYNCTIMERS protected: void _Init(); //This starts the message pump sending HXMSG_ASYNC_TIMER messages //to pReceivingThread's queue every ulThreadId milliseconds. HXSymbianAsyncTimer( ULONG32 ulTimeOut, HXThread* pReceivingThread ); //This starts the timer and calls pfExecFunc every ulTimeOut milliseconds. HXSymbianAsyncTimer( ULONG32 ulTimeOut, TIMERPROC pfExecFunc ); //this kills the timer and stops pumping messages/func calls. ~HXSymbianAsyncTimer(); //This returns the ID of this timer (threadID). inline ULONG32 GetID(); #ifdef USE_SYMBIAN_THREADS_FOR_ASYNCTIMERS //This is the actual message pump. static void* _ActualMessagePump(void* pArg); #endif private: ULONG32 m_ulTimeOut; HXThread* m_pReceivingThread; HXThreadMessage* m_pMsg; HXThreadMessage m_msgTmp; TIMERPROC m_pfExecFunc; #ifdef USE_SYMBIAN_THREADS_FOR_ASYNCTIMERS HXSymbianThread* m_pMessagePump; #endif //Support for setting/killing timers by ID. static HXMutex* m_pmtxMapLock; static CHXMapLongToObj m_mapTimers; //Don't allow default/copy ctors or assignment oper. You can't dup this class. HXSymbianAsyncTimer(); HXSymbianAsyncTimer( const HXSymbianAsyncTimer& it ); HXSymbianAsyncTimer& operator=( const HXSymbianAsyncTimer& it ); #ifdef USE_SYMBIAN_RTIMERS_FOR_ASYNCTIMERS //Active object and timer stuff. RTimer m_iTimer; #endif }; #endif //_SYMBIANTHREADSH --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe at common.helixcommunity.org For additional commands, e-mail: cvs-help at common.helixcommunity.org