|
List Info
Thread: CR: Make HXAsyncTimer::SetTimer usable outside of core, and backwards compatible
|
|
| CR: Make HXAsyncTimer::SetTimer usable
outside of core, and backwards
compatible |

|
2006-07-14 20:09:58 |
Christina Dunn wrote:
> Synopsis: Add back version of HXAsyncTimer::SetTimer,
so a context is
> not required. For backwards compatibility and to enable
use outside of
> the core lib.
>
> Overview: The thread library was updated to use
interfaces and a
> context, for creation by the class factory. The async
timer
> was modified to use IHXThread, IHXMutex and a context.
This broke the
> automation server, which does not load the core,
> or contain a context. The server just uses the
threading lib, and uses
> SOAP to talk to the client.
> I added back the old interfaces that do not require
IHXThread or a context.
> NOTE: CHXAsyncTimer/IHXAsyncTimer was not implemented
due to the static
> interface, just SetTimer & KillTimer.
Well, one option here would have been to add a member var to
hold
the async timer object and call Set/Kill off of that....
> I also did not add back the old Symbian SetTimer, so
Symbian is not
> backwards compatible.
We can tackle that later if needed...
One problem with this fix:
//Start the thread. We have to do this weird casting
because
//the HXThread::MakeThread takes HXThread*&....
if (pContext != NULL)
{
CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump, pContext);
}
else
{
m_pMessagePump = new CHXThread();
}
is that the context was added so that only the common class
factory
had to link in the thread library, every other DLL only had
to call
the CCF to create thread objects, thus reducing the size of
all other
DLLs. With the above change, everyone who calls Set/Kill
timer will
now have to link in the thread libs again, since the
compiler only
knows at runtime if you will be using the CCF or the native
CHXThread().
However, I only know of the core (threded engine and
timeline objects)
that uses these async timers right now.
Can you check on the size of the clntcore.so (and possibly a
quick
check of other DLLs) and see what hit we take for this
change? I have
a feeling that it is going to be very small, but we should
make sure.
I still think the correct fix is to make a new
CHXAsyncTimer/IHXAsyncTimer.
The only reason Set/Kill timer was static was because that
is the way
win32 does it. We are free to change that if we want. How
much work is
it to add a member var and just 'new' a async timer and
call Set/Kill
on that?
--greg.
>
> Files:
> common/system/hxthread.cpp
> common/system/pub/hxthread.h
> - Add back old SetTimer method, with HXThread,
no context
>
> common/system/platform/unix/UnixThreads.cpp
> common/system/pub/platform/unix/UnixThreads.h
> - Add old SetTimer methods back
> - add private SetTimer that all the public
SetTimers call, for
> single point of entry and no code dup
>
> Branches: HEAD
>
> Diff: (a little hard to read, so view the attached
file, UnixThreads.cpp
> , for clarity)
>
>> Index: hxthread.cpp
>>
============================================================
=======
>> RCS file: /cvsroot/common/system/hxthread.cpp,v
>> retrieving revision 1.12
>> diff -w -u -5 -r1.12 hxthread.cpp
>> --- hxthread.cpp 23 Feb 2006 22:31:02 -0000
1.12
>> +++ hxthread.cpp 12 Jul 2006 22:02:19 -0000
>>  -254,10 +254,24 
>>
>>
>> //
>> // HXAsyncTimer mehtods.
>> //
>> +UINT32 HXAsyncTimer::SetTimer(ULONG32 ulTimeOut,
HXThread*
>> pReceivingThread )
>> +{
>> +#ifdef _WIN32
>> + return ::SetTimer( NULL, NULL, ulTimeOut, NULL
);
>> +#elif defined( _UNIX_THREADS_SUPPORTED )
>> + return HXUnixAsyncTimer::SetTimer(ulTimeOut,
pReceivingThread);
>> +#elif defined _SYMBIAN
>> + return 0; // TODO:
HXSymbianAsyncTimer::SetTimer(ulTimeOut,
>> pReceivingThread);
>> +#else
>> + return 0;
>> +//# error HXAsyncTimer::SetTimer not defined on
this platform.
>> +#endif
>> +}
>> +
>> UINT32 HXAsyncTimer::SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> IHXThread* pReceivingThread )
>> {
>> #ifdef _WIN32
>> return ::SetTimer( NULL, NULL, ulTimeOut, NULL
);
>> #elif defined( _UNIX_THREADS_SUPPORTED )
>>  -268,10 +282,15 
>> return 0;
>> //# error HXAsyncTimer::SetTimer not defined on
this platform.
>> #endif
>> }
>>
>> +UINT32 HXAsyncTimer::SetTimer(ULONG32 ulTimeOut,
TIMERPROC pfExecFunc )
>> +{
>> + return SetTimer(NULL, ulTimeOut, pfExecFunc);
>> +}
>> +
>> UINT32 HXAsyncTimer::SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> TIMERPROC pfExecFunc )
>> {
>> #ifdef _WIN32
>> return ::SetTimer( NULL, NULL, ulTimeOut,
pfExecFunc );
>> #elif defined( _UNIX_THREADS_SUPPORTED )
>> Index: platform/unix/UnixThreads.cpp
>>
============================================================
=======
>> RCS file:
/cvsroot/common/system/platform/unix/UnixThreads.cpp,v
>> retrieving revision 1.17
>> diff -w -u -5 -r1.17 UnixThreads.cpp
>> --- platform/unix/UnixThreads.cpp 24 Feb 2006
01:53:35
>> -0000 1.17
>> +++ platform/unix/UnixThreads.cpp 12 Jul 2006
22:02:19 -0000
>>  -60,10 +60,12 
>> #include "hxassert.h" //for HX_ASSERT
>> #include "microsleep.h"
>> #include "hxmsgs.h" //for
HXMSG_ASYNC_TIMER message.
>> #include "hxtick.h" //for
GetTickCount()
>> #include "pckunpck.h"
>> +#include "chxthread.h"
>> +#include "hxmutex.h"
>>
>>
>>
//==========================================================
=======
>> // In this section here include the OS specific
headerfiles for
>> // each implementation.
>>  -817,39 +819,35 
>> //Static data initializers
>> IHXMutex* HXUnixAsyncTimer::m_pmtxMapLock =
NULL;
>> CHXMapLongToObj HXUnixAsyncTimer::m_mapTimers;
>>
>> //Timeouts are in miliseconds.
>> -HXUnixAsyncTimer::HXUnixAsyncTimer( IUnknown*
pContext, ULONG32
>> ulTimeOut, IHXThread* pReceivingThread )
>> +// Single protected constructor, used in SetTimer
>> +HXUnixAsyncTimer::HXUnixAsyncTimer( IUnknown*
pContext, ULONG32
>> ulTimeOut,
>> + TIMERPROC
pfExecFunc,
>> + HXThread*
pReceivingThread,
>> + IHXThread*
pReceivingIThread )
>> : m_ulTimeOut( ulTimeOut ),
>> + m_pfExecFunc(pfExecFunc),
>> m_pReceivingThread( pReceivingThread ),
>> + m_pReceivingIThread( pReceivingIThread ),
>> m_pMessagePump( NULL ),
>> - m_pMsg(NULL),
>> - m_pfExecFunc(NULL)
>> + m_pMsg(NULL)
>> {
>> //Make the message to pump.
>> m_pMsg = new HXThreadMessage(
HXMSG_ASYNC_TIMER,
>> (void*)m_ulTimeOut, NULL, NULL );
>>
>> //Start the thread. We have to do this weird
casting because
>> //the HXThread::MakeThread takes
HXThread*&....
>> + if (pContext != NULL)
>> + {
>> CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>> pContext);
>> - HX_ASSERT( m_pMessagePump );
>> - m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>> }
>> -
>> -HXUnixAsyncTimer::HXUnixAsyncTimer( IUnknown*
pContext, ULONG32
>> ulTimeOut, TIMERPROC pfExecFunc )
>> - : m_ulTimeOut( ulTimeOut ),
>> - m_pReceivingThread(NULL),
>> - m_pMessagePump(NULL),
>> - m_pMsg(NULL),
>> - m_pfExecFunc( pfExecFunc )
>> + else
>> {
>> - //we need non-null pfExecFunc
>> - HX_ASSERT( m_pfExecFunc != NULL );
>> -
>> - //Start the thread.
>> - CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>> pContext);
>> + m_pMessagePump = new CHXThread();
>> + }
>> HX_ASSERT( m_pMessagePump );
>> m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>> }
>>
>> HXUnixAsyncTimer::~HXUnixAsyncTimer()
>>  -888,66 +886,75 
>> }
>>
>> microsleep( PARG->m_ulTimeOut*1000 );
>>
>> if( PARG->m_pMsg != NULL )
>> -
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, NULL );
>> + {
>> + if (PARG->m_pReceivingThread !=
NULL)
>> + {
>> +
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, 0);
>> + }
>> + else if (PARG->m_pReceivingIThread
!= NULL)
>> + {
>> +
PARG->m_pReceivingIThread->PostMessage(
PARG->m_pMsg,
>> 0);
>> + }
>> + }
>> else
>> + {
>> PARG->m_pfExecFunc( 0, 0,
PARG->GetID(), GetTickCount() );
>> }
>> + }
>> return NULL;
>> }
>> #undef PARG
>>
>> -UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>> ulTimeOut, IHXThread* pReceivingThread )
>> -{
>> - if( m_pmtxMapLock == NULL )
>> +UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>> ulTimeOut, IHXThread* pReceivingIThread )
>> {
>> - CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>> pContext);
>> - HX_ASSERT( m_pmtxMapLock );
>> + HX_ASSERT(pReceivingIThread);
>> + return SetTimer(pContext, ulTimeOut, NULL,
NULL, pReceivingIThread);
>> }
>>
>> - //lock it.
>> - HX_LOCK(m_pmtxMapLock);
>> -
>> - ULONG32 ulTimerID = 0;
>> -
>> - HX_ASSERT( ulTimeOut != 0 );
>> - HX_ASSERT( pReceivingThread != NULL );
>> -
>> - HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>> ulTimeOut, pReceivingThread );
>> - HX_ASSERT( pTimer != NULL );
>> - if( pTimer != NULL )
>> +UINT32 HXUnixAsyncTimer::SetTimer(ULONG32
ulTimeOut, HXThread*
>> pReceivingThread )
>> {
>> - //Add new timer to map.
>> - ulTimerID = pTimer->GetID();
>> - m_mapTimers.SetAt( ulTimerID,
(void*)pTimer );
>> + HX_ASSERT(pReceivingThread);
>> + return SetTimer(NULL, ulTimeOut, NULL,
pReceivingThread, NULL);
>> }
>>
>> - //unlock the map.
>> - HX_UNLOCK(m_pmtxMapLock);
>> -
>> - return ulTimerID;
>> +UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>> ulTimeOut, TIMERPROC pfExecFunc )
>> +{
>> + HX_ASSERT( pfExecFunc != NULL );
>> + return SetTimer(pContext, ulTimeOut,
pfExecFunc, NULL, NULL);
>> }
>>
>> -UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>> ulTimeOut, TIMERPROC pfExecFunc )
>> +UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>> + TIMERPROC pfExecFunc,
>> + HXThread* pReceivingThread,
>> + IHXThread* pReceivingIThread )
>> +{
>> + // Create the IHXMutex
>> + if (pContext)
>> {
>> if( m_pmtxMapLock == NULL )
>> {
>> CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>> pContext);
>> HX_ASSERT( m_pmtxMapLock );
>> }
>> + }
>> + else if ( m_pmtxMapLock == NULL )
>> + {
>> + m_pmtxMapLock = new CHXMutex();
>> + HX_ASSERT( m_pmtxMapLock );
>> + }
>>
>> //lock it.
>> HX_LOCK(m_pmtxMapLock);
>>
>> ULONG32 ulTimerID = 0;
>> -
>> HX_ASSERT( ulTimeOut != 0 );
>> - HX_ASSERT( pfExecFunc != NULL );
>>
>> - HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>> ulTimeOut, pfExecFunc );
>> + HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext, ulTimeOut,
>> + pfExecFunc,
pReceivingThread,
>> pReceivingIThread );
>> HX_ASSERT( pTimer != NULL );
>> if( pTimer != NULL )
>> {
>> //Add new timer to map.
>> ulTimerID = pTimer->GetID();
>>  -984,8 +991,6 
>> HX_UNLOCK(m_pmtxMapLock);
>>
>> return bRetVal;
>> }
>>
>> -
>> -
>> #endif //_UNIX_THREADS_SUPPORTED
>> Index: pub/hxthread.h
>>
============================================================
=======
>> RCS file: /cvsroot/common/system/pub/hxthread.h,v
>> retrieving revision 1.13
>> diff -w -u -5 -r1.13 hxthread.h
>> --- pub/hxthread.h 24 Feb 2006 01:12:55 -0000
1.13
>> +++ pub/hxthread.h 12 Jul 2006 22:02:19 -0000
>>  -179,13 +179,15 
>> // HXMSG_ASYNC_TIMER messages will be posted
to
>> // pReceivingThread's message queue every
ulTimeOut milliseconds.
>> // until KillTimer is called.
>> // NOTE: under _WIN32 pReceivingThread is
IGNORED and the calling
>> // thread is the one to recieve the timer
messages (WM_TIMER).
>> - static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> IHXThread* pReceivingThread );
>> + static UINT32 SetTimer(ULONG32 ulTimeOut,
HXThread*
>> pReceivingThread );
>> + static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> IHXThread* pReceivingIThread );
>>
>> // pfExecFunc will be called every ulTimeOut
milliseconds.
>> + static UINT32 SetTimer(ULONG32 ulTimeOut,
TIMERPROC pfExecFunc );
>> static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> TIMERPROC pfExecFunc );
>>
>> // ulTimeOut timer is killed/removed.
>> static HXBOOL KillTimer(UINT32 ulTimerID );
>> };
>> Index: pub/platform/unix/UnixThreads.h
>>
============================================================
=======
>> RCS file:
/cvsroot/common/system/pub/platform/unix/UnixThreads.h,v
>> retrieving revision 1.9
>> diff -w -u -5 -r1.9 UnixThreads.h
>> --- pub/platform/unix/UnixThreads.h 24 Feb 2006
01:12:56
>> -0000 1.9
>> +++ pub/platform/unix/UnixThreads.h 12 Jul 2006
22:02:19 -0000
>>  -294,43 +294,48 
>> class HXUnixAsyncTimer
>> {
>> 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(IUnknown* pContext,
ULONG32 ulTimeOut,
>> IHXThread* pReceivingThread );
>> + // These three methods are the main interface
into this class.
>> + // Works just like the windows ::SetTimer and
::KillTimer functions.
>> + //
>> + //This starts the message pump sending
HXMSG_ASYNC_TIMER messages
>> + //to pReceivingThread's queue every
ulThreadId milliseconds.
>> + static UINT32 SetTimer(ULONG32 ulTimeOut,
HXThread*
>> pReceivingThread );
>> + static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> IHXThread* pReceivingIThread );
>> + // This starts the timer and calls pfExecFunc
every ulTimeOut
>> milliseconds.
>> static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> TIMERPROC pfExecFunc );
>> + //this kills the timer and stops pumping
messages/func calls.
>> static HXBOOL KillTimer(UINT32 ulTimerID );
>>
>> protected:
>>
>> - //This starts the message pump sending
HXMSG_ASYNC_TIMER messages
>> - //to pReceivingThread's queue every
ulThreadId milliseconds.
>> - HXUnixAsyncTimer( IUnknown* pContext, ULONG32
ulTimeOut,
>> IHXThread* pReceivingThread );
>> + HXUnixAsyncTimer( IUnknown* pContext, ULONG32
ulTimeOut,
>> + TIMERPROC pExecFunc,
>> + HXThread* pReceivingThread,
>> + IHXThread* pReceivingIThread );
>>
>> - //This starts the timer and calls pfExecFunc
every ulTimeOut
>> milliseconds.
>> - HXUnixAsyncTimer( IUnknown* pContext, ULONG32
ulTimeOut,
>> TIMERPROC pfExecFunc );
>> -
>> - //this kills the timer and stops pumping
messages/func calls.
>> ~HXUnixAsyncTimer();
>>
>> //This returns that ID of this timer
(threadID).
>> inline ULONG32 GetID();
>>
>> //This is the actual message pump.
>> static void* _ActualMessagePump(void* pArg);
>>
>> private:
>> + static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>> TIMERPROC pfExecFunc,
>> + HXThread* pReceivingThread,
IHXThread*
>> pReceivingIThread );
>>
>> ULONG32 m_ulTimeOut;
>> - IHXThread* m_pReceivingThread;
>> + TIMERPROC m_pfExecFunc;
>> + HXThread* m_pReceivingThread;
>> + IHXThread* m_pReceivingIThread;
>> IHXThread* m_pMessagePump;
>> HXThreadMessage* m_pMsg;
>> HXThreadMessage m_msgTmp; //This is a
per-class msg to be used
>> by the message pump.
>> - TIMERPROC m_pfExecFunc;
>>
>> //Support for setting/killing timers by ID.
>> static IHXMutex* m_pmtxMapLock;
>> static CHXMapLongToObj m_mapTimers;
>>
>
>
>
------------------------------------------------------------
------------
>
> _______________________________________________
> Common-dev mailing list
> Common-dev helixcommunity.org
> http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
_______________________________________________
Common-dev mailing list
Common-dev helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
|
|
| CR: Make HXAsyncTimer::SetTimer usable
outside of core, and backwards
compatible |

|
2006-07-14 20:52:08 |
At 01:09 PM 7/14/2006, Greg Wright wrote:
>Christina Dunn wrote:
>>Synopsis: Add back version of
HXAsyncTimer::SetTimer, so a context is not
>>required. For backwards compatibility and to enable
use outside of the
>>core lib.
>>Overview: The thread library was updated to use
interfaces and a context,
>>for creation by the class factory. The async timer
>>was modified to use IHXThread, IHXMutex and a
context. This broke the
>>automation server, which does not load the core,
>>or contain a context. The server just uses the
threading lib, and uses
>>SOAP to talk to the client.
>>I added back the old interfaces that do not require
IHXThread or a context.
>>NOTE: CHXAsyncTimer/IHXAsyncTimer was not
implemented due to the static
>>interface, just SetTimer & KillTimer.
>
>Well, one option here would have been to add a member
var to hold
>the async timer object and call Set/Kill off of that....
>
>>I also did not add back the old Symbian SetTimer, so
Symbian is not
>>backwards compatible.
>
>We can tackle that later if needed...
>
>One problem with this fix:
>
> //Start the thread. We have to do this weird
casting because
> //the HXThread::MakeThread takes HXThread*&....
> if (pContext != NULL)
> {
> CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
> pContext);
> }
> else
> {
> m_pMessagePump = new CHXThread();
> }
>
>is that the context was added so that only the common
class factory
>had to link in the thread library, every other DLL only
had to call
>the CCF to create thread objects, thus reducing the size
of all other
>DLLs. With the above change, everyone who calls Set/Kill
timer will
>now have to link in the thread libs again, since the
compiler only
>knows at runtime if you will be using the CCF or the
native CHXThread().
>
>However, I only know of the core (threded engine and
timeline objects)
>that uses these async timers right now.
>
>Can you check on the size of the clntcore.so (and
possibly a quick
>check of other DLLs) and see what hit we take for this
change? I have
>a feeling that it is going to be very small, but we
should make sure.
The difference is ~300K in the debug build for
hxmedplyeng.so
I wanted to create the message pump as an IHXThread, so that
I would not
have to duplicate all of the methods, one set for IHXThread
and one for
HXThread.
It's trivial to just add back the original code that
handles HXThread and might
be less of a size change.
>I still think the correct fix is to make a new
CHXAsyncTimer/IHXAsyncTimer.
>The only reason Set/Kill timer was static was because
that is the way
>win32 does it. We are free to change that if we want.
How much work is
>it to add a member var and just 'new' a async timer
and call Set/Kill
>on that?
This won't be any work really, since I already added most
of the code for this.
--christina
>--greg.
>
>
>
>>Files:
>>common/system/hxthread.cpp
>>common/system/pub/hxthread.h
>> - Add back old SetTimer method, with
HXThread, no context
>>common/system/platform/unix/UnixThreads.cpp
>>common/system/pub/platform/unix/UnixThreads.h
>> - Add old SetTimer methods back
>> - add private SetTimer that all the public
SetTimers call, for
>> single point of entry and no code dup
>>Branches: HEAD
>>Diff: (a little hard to read, so view the attached
file, UnixThreads.cpp
>>, for clarity)
>>
>>>Index: hxthread.cpp
>>>================================================
===================
>>>RCS file: /cvsroot/common/system/hxthread.cpp,v
>>>retrieving revision 1.12
>>>diff -w -u -5 -r1.12 hxthread.cpp
>>>--- hxthread.cpp 23 Feb 2006 22:31:02
-0000 1.12
>>>+++ hxthread.cpp 12 Jul 2006 22:02:19
-0000
>>> -254,10 +254,24 
>>>
>>>
>>> //
>>> // HXAsyncTimer mehtods.
>>> //
>>>+UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, HXThread*
>>>pReceivingThread )
>>>+{
>>>+#ifdef _WIN32
>>>+ return ::SetTimer( NULL, NULL, ulTimeOut,
NULL );
>>>+#elif defined( _UNIX_THREADS_SUPPORTED )
>>>+ return
HXUnixAsyncTimer::SetTimer(ulTimeOut, pReceivingThread);
>>>+#elif defined _SYMBIAN
>>>+ return 0; // TODO:
HXSymbianAsyncTimer::SetTimer(ulTimeOut,
>>>pReceivingThread);
>>>+#else
>>>+ return 0;
>>>+//# error HXAsyncTimer::SetTimer not defined
on this platform.
>>>+#endif
>>>+}
>>>+
>>> UINT32 HXAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>> IHXThread* pReceivingThread )
>>> {
>>> #ifdef _WIN32
>>> return ::SetTimer( NULL, NULL, ulTimeOut,
NULL );
>>> #elif defined( _UNIX_THREADS_SUPPORTED )
>>> -268,10 +282,15 
>>> return 0;
>>> //# error HXAsyncTimer::SetTimer not defined
on this platform.
>>> #endif
>>> }
>>>
>>>+UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, TIMERPROC pfExecFunc )
>>>+{
>>>+ return SetTimer(NULL, ulTimeOut,
pfExecFunc);
>>>+}
>>>+
>>> UINT32 HXAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>> TIMERPROC pfExecFunc )
>>> {
>>> #ifdef _WIN32
>>> return ::SetTimer( NULL, NULL, ulTimeOut,
pfExecFunc );
>>> #elif defined( _UNIX_THREADS_SUPPORTED )
>>>Index: platform/unix/UnixThreads.cpp
>>>================================================
===================
>>>RCS file:
/cvsroot/common/system/platform/unix/UnixThreads.cpp,v
>>>retrieving revision 1.17
>>>diff -w -u -5 -r1.17 UnixThreads.cpp
>>>--- platform/unix/UnixThreads.cpp 24 Feb
2006 01:53:35 -0000 1.17
>>>+++ platform/unix/UnixThreads.cpp 12 Jul
2006 22:02:19 -0000
>>> -60,10 +60,12 
>>> #include "hxassert.h" //for
HX_ASSERT
>>> #include "microsleep.h"
>>> #include "hxmsgs.h" //for
HXMSG_ASYNC_TIMER message.
>>> #include "hxtick.h" //for
GetTickCount()
>>> #include "pckunpck.h"
>>>+#include "chxthread.h"
>>>+#include "hxmutex.h"
>>>
>>>
>>>
//==========================================================
=======
>>> // In this section here include the OS
specific headerfiles for
>>> // each implementation.
>>> -817,39 +819,35 
>>> //Static data initializers
>>> IHXMutex*
HXUnixAsyncTimer::m_pmtxMapLock = NULL;
>>> CHXMapLongToObj HXUnixAsyncTimer::m_mapTimers;
>>>
>>> //Timeouts are in miliseconds.
>>>-HXUnixAsyncTimer::HXUnixAsyncTimer( IUnknown*
pContext, ULONG32
>>>ulTimeOut, IHXThread* pReceivingThread )
>>>+// Single protected constructor, used in
SetTimer
>>>+HXUnixAsyncTimer::HXUnixAsyncTimer( IUnknown*
pContext, ULONG32 ulTimeOut,
>>>+ TIMERPROC
pfExecFunc,
>>>+ HXThread*
pReceivingThread,
>>>+ IHXThread*
pReceivingIThread )
>>> : m_ulTimeOut( ulTimeOut ),
>>>+ m_pfExecFunc(pfExecFunc),
>>> m_pReceivingThread( pReceivingThread ),
>>>+ m_pReceivingIThread( pReceivingIThread ),
>>> m_pMessagePump( NULL ),
>>>- m_pMsg(NULL),
>>>- m_pfExecFunc(NULL)
>>>+ m_pMsg(NULL)
>>> {
>>> //Make the message to pump.
>>> m_pMsg = new HXThreadMessage(
HXMSG_ASYNC_TIMER,
>>> (void*)m_ulTimeOut, NULL, NULL );
>>>
>>> //Start the thread. We have to do this
weird casting because
>>> //the HXThread::MakeThread takes
HXThread*&....
>>>+ if (pContext != NULL)
>>>+ {
>>> CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump, pContext);
>>>- HX_ASSERT( m_pMessagePump );
>>>- m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>>> }
>>>-
>>>-HXUnixAsyncTimer::HXUnixAsyncTimer( IUnknown*
pContext, ULONG32
>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>- : m_ulTimeOut( ulTimeOut ),
>>>- m_pReceivingThread(NULL),
>>>- m_pMessagePump(NULL),
>>>- m_pMsg(NULL),
>>>- m_pfExecFunc( pfExecFunc )
>>>+ else
>>> {
>>>- //we need non-null pfExecFunc
>>>- HX_ASSERT( m_pfExecFunc != NULL );
>>>-
>>>- //Start the thread.
>>>- CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump, pContext);
>>>+ m_pMessagePump = new CHXThread();
>>>+ }
>>> HX_ASSERT( m_pMessagePump );
>>> m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>>> }
>>>
>>> HXUnixAsyncTimer::~HXUnixAsyncTimer()
>>> -888,66 +886,75 
>>> }
>>>
>>> microsleep( PARG->m_ulTimeOut*1000
);
>>>
>>> if( PARG->m_pMsg != NULL )
>>>-
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, NULL );
>>>+ {
>>>+ if (PARG->m_pReceivingThread !=
NULL)
>>>+ {
>>>+
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, 0);
>>>+ }
>>>+ else if
(PARG->m_pReceivingIThread != NULL)
>>>+ {
>>>+
PARG->m_pReceivingIThread->PostMessage(
PARG->m_pMsg, 0);
>>>+ }
>>>+ }
>>> else
>>>+ {
>>> PARG->m_pfExecFunc( 0, 0,
PARG->GetID(), GetTickCount() );
>>> }
>>>+ }
>>> return NULL;
>>> }
>>> #undef PARG
>>>
>>>-UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>>>ulTimeOut, IHXThread* pReceivingThread )
>>>-{
>>>- if( m_pmtxMapLock == NULL )
>>>+UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>>>ulTimeOut, IHXThread* pReceivingIThread )
>>> {
>>>- CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock, pContext);
>>>- HX_ASSERT( m_pmtxMapLock );
>>>+ HX_ASSERT(pReceivingIThread);
>>>+ return SetTimer(pContext, ulTimeOut, NULL,
NULL, pReceivingIThread);
>>> }
>>>
>>>- //lock it.
>>>- HX_LOCK(m_pmtxMapLock);
>>>-
>>>- ULONG32 ulTimerID = 0;
>>>-
>>>- HX_ASSERT( ulTimeOut != 0 );
>>>- HX_ASSERT( pReceivingThread != NULL );
>>>-
>>>- HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>ulTimeOut, pReceivingThread );
>>>- HX_ASSERT( pTimer != NULL );
>>>- if( pTimer != NULL )
>>>+UINT32 HXUnixAsyncTimer::SetTimer(ULONG32
ulTimeOut, HXThread*
>>>pReceivingThread )
>>> {
>>>- //Add new timer to map.
>>>- ulTimerID = pTimer->GetID();
>>>- m_mapTimers.SetAt( ulTimerID,
(void*)pTimer );
>>>+ HX_ASSERT(pReceivingThread);
>>>+ return SetTimer(NULL, ulTimeOut, NULL,
pReceivingThread, NULL);
>>> }
>>>
>>>- //unlock the map.
>>>- HX_UNLOCK(m_pmtxMapLock);
>>>-
>>>- return ulTimerID;
>>>+UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>+{
>>>+ HX_ASSERT( pfExecFunc != NULL );
>>>+ return SetTimer(pContext, ulTimeOut,
pfExecFunc, NULL, NULL);
>>> }
>>>
>>>-UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>+UINT32 HXUnixAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>+ TIMERPROC pfExecFunc,
>>>+ HXThread* pReceivingThread,
>>>+ IHXThread* pReceivingIThread )
>>>+{
>>>+ // Create the IHXMutex
>>>+ if (pContext)
>>> {
>>> if( m_pmtxMapLock == NULL )
>>> {
>>> CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>>> pContext);
>>> HX_ASSERT( m_pmtxMapLock );
>>> }
>>>+ }
>>>+ else if ( m_pmtxMapLock == NULL )
>>>+ {
>>>+ m_pmtxMapLock = new CHXMutex();
>>>+ HX_ASSERT( m_pmtxMapLock );
>>>+ }
>>>
>>> //lock it.
>>> HX_LOCK(m_pmtxMapLock);
>>>
>>> ULONG32 ulTimerID = 0;
>>>-
>>> HX_ASSERT( ulTimeOut != 0 );
>>>- HX_ASSERT( pfExecFunc != NULL );
>>>
>>>- HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>ulTimeOut, pfExecFunc );
>>>+ HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext, ulTimeOut,
>>>+ pfExecFunc,
pReceivingThread,
>>>pReceivingIThread );
>>> HX_ASSERT( pTimer != NULL );
>>> if( pTimer != NULL )
>>> {
>>> //Add new timer to map.
>>> ulTimerID = pTimer->GetID();
>>> -984,8 +991,6 
>>> HX_UNLOCK(m_pmtxMapLock);
>>>
>>> return bRetVal;
>>> }
>>>
>>>-
>>>-
>>> #endif //_UNIX_THREADS_SUPPORTED
>>>Index: pub/hxthread.h
>>>================================================
===================
>>>RCS file:
/cvsroot/common/system/pub/hxthread.h,v
>>>retrieving revision 1.13
>>>diff -w -u -5 -r1.13 hxthread.h
>>>--- pub/hxthread.h 24 Feb 2006 01:12:55
-0000 1.13
>>>+++ pub/hxthread.h 12 Jul 2006 22:02:19
-0000
>>> -179,13 +179,15 
>>> // HXMSG_ASYNC_TIMER messages will be
posted to
>>> // pReceivingThread's message queue every
ulTimeOut milliseconds.
>>> // until KillTimer is called.
>>> // NOTE: under _WIN32 pReceivingThread is
IGNORED and the calling
>>> // thread is the one to recieve the timer
messages (WM_TIMER).
>>>- static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>>>IHXThread* pReceivingThread );
>>>+ static UINT32 SetTimer(ULONG32 ulTimeOut,
HXThread* pReceivingThread );
>>>+ static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>>>IHXThread* pReceivingIThread );
>>>
>>> // pfExecFunc will be called every
ulTimeOut milliseconds.
>>>+ static UINT32 SetTimer(ULONG32 ulTimeOut,
TIMERPROC pfExecFunc );
>>> static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>>> TIMERPROC pfExecFunc );
>>>
>>> // ulTimeOut timer is killed/removed.
>>> static HXBOOL KillTimer(UINT32 ulTimerID
);
>>> };
>>>Index: pub/platform/unix/UnixThreads.h
>>>================================================
===================
>>>RCS file:
/cvsroot/common/system/pub/platform/unix/UnixThreads.h,v
>>>retrieving revision 1.9
>>>diff -w -u -5 -r1.9 UnixThreads.h
>>>--- pub/platform/unix/UnixThreads.h 24 Feb
2006 01:12:56 -0000 1.9
>>>+++ pub/platform/unix/UnixThreads.h 12 Jul
2006 22:02:19 -0000
>>> -294,43 +294,48 
>>> class HXUnixAsyncTimer
>>> {
>>> 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(IUnknown* pContext,
ULONG32 ulTimeOut,
>>>IHXThread* pReceivingThread );
>>>+ // These three methods are the main
interface into this class.
>>>+ // Works just like the windows ::SetTimer
and ::KillTimer functions.
>>>+ //
>>>+ //This starts the message pump sending
HXMSG_ASYNC_TIMER messages
>>>+ //to pReceivingThread's queue every
ulThreadId milliseconds.
>>>+ static UINT32 SetTimer(ULONG32 ulTimeOut,
HXThread* pReceivingThread );
>>>+ static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>>>IHXThread* pReceivingIThread );
>>>+ // This starts the timer and calls
pfExecFunc every ulTimeOut
>>>milliseconds.
>>> static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>>> TIMERPROC pfExecFunc );
>>>+ //this kills the timer and stops pumping
messages/func calls.
>>> static HXBOOL KillTimer(UINT32 ulTimerID
);
>>>
>>> protected:
>>>
>>>- //This starts the message pump sending
HXMSG_ASYNC_TIMER messages
>>>- //to pReceivingThread's queue every
ulThreadId milliseconds.
>>>- HXUnixAsyncTimer( IUnknown* pContext,
ULONG32 ulTimeOut, IHXThread*
>>>pReceivingThread );
>>>+ HXUnixAsyncTimer( IUnknown* pContext,
ULONG32 ulTimeOut,
>>>+ TIMERPROC pExecFunc,
>>>+ HXThread* pReceivingThread,
>>>+ IHXThread* pReceivingIThread
);
>>>
>>>- //This starts the timer and calls
pfExecFunc every ulTimeOut
>>>milliseconds.
>>>- HXUnixAsyncTimer( IUnknown* pContext,
ULONG32 ulTimeOut, TIMERPROC
>>>pfExecFunc );
>>>-
>>>- //this kills the timer and stops pumping
messages/func calls.
>>> ~HXUnixAsyncTimer();
>>>
>>> //This returns that ID of this timer
(threadID).
>>> inline ULONG32 GetID();
>>>
>>> //This is the actual message pump.
>>> static void* _ActualMessagePump(void*
pArg);
>>>
>>> private:
>>>+ static UINT32 SetTimer(IUnknown* pContext,
ULONG32 ulTimeOut,
>>>TIMERPROC pfExecFunc,
>>>+ HXThread* pReceivingThread,
IHXThread*
>>>pReceivingIThread );
>>>
>>> ULONG32 m_ulTimeOut;
>>>- IHXThread* m_pReceivingThread;
>>>+ TIMERPROC m_pfExecFunc;
>>>+ HXThread* m_pReceivingThread;
>>>+ IHXThread* m_pReceivingIThread;
>>> IHXThread* m_pMessagePump;
>>> HXThreadMessage* m_pMsg;
>>> HXThreadMessage m_msgTmp; //This is a
per-class msg to be used
>>> by the message pump.
>>>- TIMERPROC m_pfExecFunc;
>>>
>>> //Support for setting/killing timers by
ID.
>>> static IHXMutex* m_pmtxMapLock;
>>> static CHXMapLongToObj m_mapTimers;
>>
>>----------------------------------------------------
--------------------
>>_______________________________________________
>>Common-dev mailing list
>>Common-dev helixcommunity.org
>>http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
_______________________________________________
Common-dev mailing list
Common-dev helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
|
|
| CR: Make HXAsyncTimer::SetTimer usable
outside of core, and backwards
compatible |

|
2006-07-14 21:01:29 |
>> However, I only know of the core (threded engine
and timeline objects)
>> that uses these async timers right now.
>>
>> Can you check on the size of the clntcore.so (and
possibly a quick
>> check of other DLLs) and see what hit we take for
this change? I have
>> a feeling that it is going to be very small, but we
should make sure.
>
> The difference is ~300K in the debug build for
hxmedplyeng.so
I don't think I would trust a debug build for sizes. The
compile may
not do any work to remove unused code. Can you do a release
build of
the two and see what that size diff is? I am sure it will be
a LOT
less then 300K.
> I wanted to create the message pump as an IHXThread, so
that I would not
> have to duplicate all of the methods, one set for
IHXThread and one for
> HXThread.
> It's trivial to just add back the original code that
handles HXThread
> and might
> be less of a size change.
>
>
>> I still think the correct fix is to make a new
>> CHXAsyncTimer/IHXAsyncTimer.
>> The only reason Set/Kill timer was static was
because that is the way
>> win32 does it. We are free to change that if we
want. How much work is
>> it to add a member var and just 'new' a async
timer and call Set/Kill
>> on that?
>
> This won't be any work really, since I already added
most of the code
> for this.
If we can do that, then would we not have this situation:
o HXAsyncTime goes back to the original version, no context
at all.
o A new CHXAsyncTimer is created that interfaces with the
original
version of the async timers.
o The core is changed to use the the CHXAsyncTimer (by
new'ing it or
something). It would no longer be static.
o Your code can just use the old original version.
How does that sound?
> --christina
>
>
>> --greg.
>>
>>
>>
>>> Files:
>>> common/system/hxthread.cpp
>>> common/system/pub/hxthread.h
>>> - Add back old SetTimer method, with
HXThread, no context
>>> common/system/platform/unix/UnixThreads.cpp
>>> common/system/pub/platform/unix/UnixThreads.h
>>> - Add old SetTimer methods back
>>> - add private SetTimer that all the
public SetTimers call,
>>> for single point of entry and no code dup
>>> Branches: HEAD
>>> Diff: (a little hard to read, so view the
attached file,
>>> UnixThreads.cpp , for clarity)
>>>
>>>> Index: hxthread.cpp
>>>>
============================================================
=======
>>>> RCS file:
/cvsroot/common/system/hxthread.cpp,v
>>>> retrieving revision 1.12
>>>> diff -w -u -5 -r1.12 hxthread.cpp
>>>> --- hxthread.cpp 23 Feb 2006
22:31:02 -0000 1.12
>>>> +++ hxthread.cpp 12 Jul 2006
22:02:19 -0000
>>>>  -254,10 +254,24 
>>>>
>>>>
>>>> //
>>>> // HXAsyncTimer mehtods.
>>>> //
>>>> +UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, HXThread*
>>>> pReceivingThread )
>>>> +{
>>>> +#ifdef _WIN32
>>>> + return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>> +#elif defined( _UNIX_THREADS_SUPPORTED )
>>>> + return
HXUnixAsyncTimer::SetTimer(ulTimeOut, pReceivingThread);
>>>> +#elif defined _SYMBIAN
>>>> + return 0; // TODO:
HXSymbianAsyncTimer::SetTimer(ulTimeOut,
>>>> pReceivingThread);
>>>> +#else
>>>> + return 0;
>>>> +//# error HXAsyncTimer::SetTimer not
defined on this platform.
>>>> +#endif
>>>> +}
>>>> +
>>>> UINT32 HXAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>>>> ulTimeOut, IHXThread* pReceivingThread )
>>>> {
>>>> #ifdef _WIN32
>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>> #elif defined( _UNIX_THREADS_SUPPORTED )
>>>>  -268,10 +282,15 
>>>> return 0;
>>>> //# error HXAsyncTimer::SetTimer not
defined on this platform.
>>>> #endif
>>>> }
>>>>
>>>> +UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, TIMERPROC
>>>> pfExecFunc )
>>>> +{
>>>> + return SetTimer(NULL, ulTimeOut,
pfExecFunc);
>>>> +}
>>>> +
>>>> UINT32 HXAsyncTimer::SetTimer(IUnknown*
pContext, ULONG32
>>>> ulTimeOut, TIMERPROC pfExecFunc )
>>>> {
>>>> #ifdef _WIN32
>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, pfExecFunc );
>>>> #elif defined( _UNIX_THREADS_SUPPORTED )
>>>> Index: platform/unix/UnixThreads.cpp
>>>>
============================================================
=======
>>>> RCS file:
/cvsroot/common/system/platform/unix/UnixThreads.cpp,v
>>>> retrieving revision 1.17
>>>> diff -w -u -5 -r1.17 UnixThreads.cpp
>>>> --- platform/unix/UnixThreads.cpp 24
Feb 2006 01:53:35
>>>> -0000 1.17
>>>> +++ platform/unix/UnixThreads.cpp 12
Jul 2006 22:02:19 -0000
>>>>  -60,10 +60,12 
>>>> #include "hxassert.h" //for
HX_ASSERT
>>>> #include "microsleep.h"
>>>> #include "hxmsgs.h" //for
HXMSG_ASYNC_TIMER message.
>>>> #include "hxtick.h" //for
GetTickCount()
>>>> #include "pckunpck.h"
>>>> +#include "chxthread.h"
>>>> +#include "hxmutex.h"
>>>>
>>>>
>>>>
//==========================================================
=======
>>>> // In this section here include the OS
specific headerfiles for
>>>> // each implementation.
>>>>  -817,39 +819,35 
>>>> //Static data initializers
>>>> IHXMutex*
HXUnixAsyncTimer::m_pmtxMapLock = NULL;
>>>> CHXMapLongToObj
HXUnixAsyncTimer::m_mapTimers;
>>>>
>>>> //Timeouts are in miliseconds.
>>>> -HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>> ulTimeOut, IHXThread* pReceivingThread )
>>>> +// Single protected constructor, used in
SetTimer
>>>> +HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>> ulTimeOut,
>>>> + TIMERPROC
pfExecFunc,
>>>> + HXThread*
pReceivingThread,
>>>> + IHXThread*
pReceivingIThread )
>>>> : m_ulTimeOut( ulTimeOut ),
>>>> + m_pfExecFunc(pfExecFunc),
>>>> m_pReceivingThread( pReceivingThread
),
>>>> + m_pReceivingIThread(
pReceivingIThread ),
>>>> m_pMessagePump( NULL ),
>>>> - m_pMsg(NULL),
>>>> - m_pfExecFunc(NULL)
>>>> + m_pMsg(NULL)
>>>> {
>>>> //Make the message to pump.
>>>> m_pMsg = new HXThreadMessage(
HXMSG_ASYNC_TIMER,
>>>> (void*)m_ulTimeOut, NULL, NULL );
>>>>
>>>> //Start the thread. We have to do this
weird casting because
>>>> //the HXThread::MakeThread takes
HXThread*&....
>>>> + if (pContext != NULL)
>>>> + {
>>>> CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>>>> pContext);
>>>> - HX_ASSERT( m_pMessagePump );
>>>> - m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this,
>>>> 0 );
>>>> }
>>>> -
>>>> -HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>> ulTimeOut, TIMERPROC pfExecFunc )
>>>> - : m_ulTimeOut( ulTimeOut ),
>>>> - m_pReceivingThread(NULL),
>>>> - m_pMessagePump(NULL),
>>>> - m_pMsg(NULL),
>>>> - m_pfExecFunc( pfExecFunc )
>>>> + else
>>>> {
>>>> - //we need non-null pfExecFunc
>>>> - HX_ASSERT( m_pfExecFunc != NULL );
>>>> -
>>>> - //Start the thread.
>>>> - CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>>>> pContext);
>>>> + m_pMessagePump = new CHXThread();
>>>> + }
>>>> HX_ASSERT( m_pMessagePump );
>>>> m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this,
>>>> 0 );
>>>> }
>>>>
>>>> HXUnixAsyncTimer::~HXUnixAsyncTimer()
>>>>  -888,66 +886,75 
>>>> }
>>>>
>>>> microsleep(
PARG->m_ulTimeOut*1000 );
>>>>
>>>> if( PARG->m_pMsg != NULL )
>>>> -
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg,
>>>> NULL );
>>>> + {
>>>> + if (PARG->m_pReceivingThread
!= NULL)
>>>> + {
>>>> +
PARG->m_pReceivingThread->PostMessage(
>>>> PARG->m_pMsg, 0);
>>>> + }
>>>> + else if
(PARG->m_pReceivingIThread != NULL)
>>>> + {
>>>> +
PARG->m_pReceivingIThread->PostMessage(
>>>> PARG->m_pMsg, 0);
>>>> + }
>>>> + }
>>>> else
>>>> + {
>>>> PARG->m_pfExecFunc( 0, 0,
PARG->GetID(), GetTickCount() );
>>>> }
>>>> + }
>>>> return NULL;
>>>> }
>>>> #undef PARG
>>>>
>>>> -UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>> ulTimeOut, IHXThread* pReceivingThread )
>>>> -{
>>>> - if( m_pmtxMapLock == NULL )
>>>> +UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>> ulTimeOut, IHXThread* pReceivingIThread )
>>>> {
>>>> - CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>>>> pContext);
>>>> - HX_ASSERT( m_pmtxMapLock );
>>>> + HX_ASSERT(pReceivingIThread);
>>>> + return SetTimer(pContext, ulTimeOut,
NULL, NULL,
>>>> pReceivingIThread);
>>>> }
>>>>
>>>> - //lock it.
>>>> - HX_LOCK(m_pmtxMapLock);
>>>> -
>>>> - ULONG32 ulTimerID = 0;
>>>> -
>>>> - HX_ASSERT( ulTimeOut != 0 );
>>>> - HX_ASSERT( pReceivingThread != NULL );
>>>> -
>>>> - HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>> ulTimeOut, pReceivingThread );
>>>> - HX_ASSERT( pTimer != NULL );
>>>> - if( pTimer != NULL )
>>>> +UINT32 HXUnixAsyncTimer::SetTimer(ULONG32
ulTimeOut, HXThread*
>>>> pReceivingThread )
>>>> {
>>>> - //Add new timer to map.
>>>> - ulTimerID = pTimer->GetID();
>>>> - m_mapTimers.SetAt( ulTimerID,
(void*)pTimer );
>>>> + HX_ASSERT(pReceivingThread);
>>>> + return SetTimer(NULL, ulTimeOut, NULL,
pReceivingThread, NULL);
>>>> }
>>>>
>>>> - //unlock the map.
>>>> - HX_UNLOCK(m_pmtxMapLock);
>>>> -
>>>> - return ulTimerID;
>>>> +UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>> ulTimeOut, TIMERPROC pfExecFunc )
>>>> +{
>>>> + HX_ASSERT( pfExecFunc != NULL );
>>>> + return SetTimer(pContext, ulTimeOut,
pfExecFunc, NULL, NULL);
>>>> }
>>>>
>>>> -UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>> ulTimeOut, TIMERPROC pfExecFunc )
>>>> +UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>> ulTimeOut,
>>>> + TIMERPROC pfExecFunc,
>>>> + HXThread* pReceivingThread,
>>>> + IHXThread*
pReceivingIThread )
>>>> +{
>>>> + // Create the IHXMutex
>>>> + if (pContext)
>>>> {
>>>> if( m_pmtxMapLock == NULL )
>>>> {
>>>> CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>>>> pContext);
>>>> HX_ASSERT( m_pmtxMapLock );
>>>> }
>>>> + }
>>>> + else if ( m_pmtxMapLock == NULL )
>>>> + {
>>>> + m_pmtxMapLock = new CHXMutex();
>>>> + HX_ASSERT( m_pmtxMapLock );
>>>> + }
>>>>
>>>> //lock it.
>>>> HX_LOCK(m_pmtxMapLock);
>>>>
>>>> ULONG32 ulTimerID = 0;
>>>> -
>>>> HX_ASSERT( ulTimeOut != 0 );
>>>> - HX_ASSERT( pfExecFunc != NULL );
>>>>
>>>> - HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>> ulTimeOut, pfExecFunc );
>>>> + HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>> ulTimeOut,
>>>> + pfExecFunc,
pReceivingThread,
>>>> pReceivingIThread );
>>>> HX_ASSERT( pTimer != NULL );
>>>> if( pTimer != NULL )
>>>> {
>>>> //Add new timer to map.
>>>> ulTimerID = pTimer->GetID();
>>>>  -984,8 +991,6 
>>>> HX_UNLOCK(m_pmtxMapLock);
>>>>
>>>> return bRetVal;
>>>> }
>>>>
>>>> -
>>>> -
>>>> #endif //_UNIX_THREADS_SUPPORTED
>>>> Index: pub/hxthread.h
>>>>
============================================================
=======
>>>> RCS file:
/cvsroot/common/system/pub/hxthread.h,v
>>>> retrieving revision 1.13
>>>> diff -w -u -5 -r1.13 hxthread.h
>>>> --- pub/hxthread.h 24 Feb 2006
01:12:55 -0000 1.13
>>>> +++ pub/hxthread.h 12 Jul 2006
22:02:19 -0000
>>>>  -179,13 +179,15 
>>>> // HXMSG_ASYNC_TIMER messages will be
posted to
>>>> // pReceivingThread's message queue
every ulTimeOut milliseconds.
>>>> // until KillTimer is called.
>>>> // NOTE: under _WIN32 pReceivingThread
is IGNORED and the calling
>>>> // thread is the one to recieve the
timer messages (WM_TIMER).
>>>> - static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>> IHXThread* pReceivingThread );
>>>> + static UINT32 SetTimer(ULONG32
ulTimeOut, HXThread*
>>>> pReceivingThread );
>>>> + static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>> IHXThread* pReceivingIThread );
>>>>
>>>> // pfExecFunc will be called every
ulTimeOut milliseconds.
>>>> + static UINT32 SetTimer(ULONG32
ulTimeOut, TIMERPROC pfExecFunc );
>>>> static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>> TIMERPROC pfExecFunc );
>>>>
>>>> // ulTimeOut timer is killed/removed.
>>>> static HXBOOL KillTimer(UINT32
ulTimerID );
>>>> };
>>>> Index: pub/platform/unix/UnixThreads.h
>>>>
============================================================
=======
>>>> RCS file:
/cvsroot/common/system/pub/platform/unix/UnixThreads.h,v
>>>> retrieving revision 1.9
>>>> diff -w -u -5 -r1.9 UnixThreads.h
>>>> --- pub/platform/unix/UnixThreads.h 24
Feb 2006 01:12:56
>>>> -0000 1.9
>>>> +++ pub/platform/unix/UnixThreads.h 12
Jul 2006 22:02:19 -0000
>>>>  -294,43 +294,48 
>>>> class HXUnixAsyncTimer
>>>> {
>>>> 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(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>> IHXThread* pReceivingThread );
>>>> + // These three methods are the main
interface into this class.
>>>> + // Works just like the windows
::SetTimer and ::KillTimer
>>>> functions.
>>>> + //
>>>> + //This starts the message pump sending
HXMSG_ASYNC_TIMER messages
>>>> + //to pReceivingThread's queue every
ulThreadId milliseconds.
>>>> + static UINT32 SetTimer(ULONG32
ulTimeOut, HXThread*
>>>> pReceivingThread );
>>>> + static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>> IHXThread* pReceivingIThread );
>>>> + // This starts the timer and calls
pfExecFunc every ulTimeOut
>>>> milliseconds.
>>>> static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>> TIMERPROC pfExecFunc );
>>>> + //this kills the timer and stops
pumping messages/func calls.
>>>> static HXBOOL KillTimer(UINT32
ulTimerID );
>>>>
>>>> protected:
>>>>
>>>> - //This starts the message pump sending
HXMSG_ASYNC_TIMER messages
>>>> - //to pReceivingThread's queue every
ulThreadId milliseconds.
>>>> - HXUnixAsyncTimer( IUnknown* pContext,
ULONG32 ulTimeOut,
>>>> IHXThread* pReceivingThread );
>>>> + HXUnixAsyncTimer( IUnknown* pContext,
ULONG32 ulTimeOut,
>>>> + TIMERPROC pExecFunc,
>>>> + HXThread*
pReceivingThread,
>>>> + IHXThread*
pReceivingIThread );
>>>>
>>>> - //This starts the timer and calls
pfExecFunc every ulTimeOut
>>>> milliseconds.
>>>> - HXUnixAsyncTimer( IUnknown* pContext,
ULONG32 ulTimeOut,
>>>> TIMERPROC pfExecFunc );
>>>> -
>>>> - //this kills the timer and stops
pumping messages/func calls.
>>>> ~HXUnixAsyncTimer();
>>>>
>>>> //This returns that ID of this timer
(threadID).
>>>> inline ULONG32 GetID();
>>>>
>>>> //This is the actual message pump.
>>>> static void* _ActualMessagePump(void*
pArg);
>>>>
>>>> private:
>>>> + static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>> TIMERPROC pfExecFunc,
>>>> + HXThread*
pReceivingThread, IHXThread*
>>>> pReceivingIThread );
>>>>
>>>> ULONG32 m_ulTimeOut;
>>>> - IHXThread* m_pReceivingThread;
>>>> + TIMERPROC m_pfExecFunc;
>>>> + HXThread* m_pReceivingThread;
>>>> + IHXThread* m_pReceivingIThread;
>>>> IHXThread* m_pMessagePump;
>>>> HXThreadMessage* m_pMsg;
>>>> HXThreadMessage m_msgTmp; //This is
a per-class msg to be
>>>> used by the message pump.
>>>> - TIMERPROC m_pfExecFunc;
>>>>
>>>> //Support for setting/killing timers
by ID.
>>>> static IHXMutex* m_pmtxMapLock;
>>>> static CHXMapLongToObj m_mapTimers;
>>>
>>>
------------------------------------------------------------
------------
>>> _______________________________________________
>>> Common-dev mailing list
>>> Common-dev helixcommunity.org
>>> http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
>
>
>
_______________________________________________
Common-dev mailing list
Common-dev helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
|
|
| CR: Make HXAsyncTimer::SetTimer usable
outside of core, and backwards
compatible |

|
2006-07-14 21:23:37 |
At 02:01 PM 7/14/2006, Greg Wright wrote:
>>>However, I only know of the core (threded engine
and timeline objects)
>>>that uses these async timers right now.
>>>
>>>Can you check on the size of the clntcore.so
(and possibly a quick
>>>check of other DLLs) and see what hit we take
for this change? I have
>>>a feeling that it is going to be very small, but
we should make sure.
>>The difference is ~300K in the debug build for
hxmedplyeng.so
>
>I don't think I would trust a debug build for sizes.
The compile may
>not do any work to remove unused code. Can you do a
release build of
>the two and see what that size diff is? I am sure it
will be a LOT
>less then 300K.
>
>>I wanted to create the message pump as an IHXThread,
so that I would not
>>have to duplicate all of the methods, one set for
IHXThread and one for
>>HXThread.
>>It's trivial to just add back the original code
that handles HXThread and
>>might
>>be less of a size change.
>>
>>>I still think the correct fix is to make a new
CHXAsyncTimer/IHXAsyncTimer.
>>>The only reason Set/Kill timer was static was
because that is the way
>>>win32 does it. We are free to change that if we
want. How much work is
>>>it to add a member var and just 'new' a async
timer and call Set/Kill
>>>on that?
>>This won't be any work really, since I already
added most of the code for
>>this.
>
>If we can do that, then would we not have this
situation:
>
>o HXAsyncTime goes back to the original version, no
context at all.
>o A new CHXAsyncTimer is created that interfaces with
the original
> version of the async timers.
>o The core is changed to use the the CHXAsyncTimer (by
new'ing it or
> something). It would no longer be static.
>o Your code can just use the old original version.
>
>How does that sound?
Sounds good. I'll send out a new diff after I make the new
changes.
thanks,
christina
>>--christina
>>
>>>--greg.
>>>
>>>
>>>
>>>>Files:
>>>>common/system/hxthread.cpp
>>>>common/system/pub/hxthread.h
>>>> - Add back old SetTimer method,
with HXThread, no context
>>>>common/system/platform/unix/UnixThreads.cpp
>>>>common/system/pub/platform/unix/UnixThreads.
h
>>>> - Add old SetTimer methods back
>>>> - add private SetTimer that all the
public SetTimers call, for
>>>> single point of entry and no code dup
>>>>Branches: HEAD
>>>>Diff: (a little hard to read, so view the
attached file,
>>>>UnixThreads.cpp , for clarity)
>>>>
>>>>>Index: hxthread.cpp
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/hxthread.cpp,v
>>>>>retrieving revision 1.12
>>>>>diff -w -u -5 -r1.12 hxthread.cpp
>>>>>--- hxthread.cpp 23 Feb 2006
22:31:02 -0000 1.12
>>>>>+++ hxthread.cpp 12 Jul 2006
22:02:19 -0000
>>>>> -254,10 +254,24 
>>>>>
>>>>>
>>>>> //
>>>>> // HXAsyncTimer mehtods.
>>>>> //
>>>>>+UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, HXThread*
>>>>>pReceivingThread )
>>>>>+{
>>>>>+#ifdef _WIN32
>>>>>+ return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>>>+#elif defined( _UNIX_THREADS_SUPPORTED
)
>>>>>+ return
HXUnixAsyncTimer::SetTimer(ulTimeOut, pReceivingThread);
>>>>>+#elif defined _SYMBIAN
>>>>>+ return 0; // TODO:
HXSymbianAsyncTimer::SetTimer(ulTimeOut,
>>>>>pReceivingThread);
>>>>>+#else
>>>>>+ return 0;
>>>>>+//# error HXAsyncTimer::SetTimer not
defined on this platform.
>>>>>+#endif
>>>>>+}
>>>>>+
>>>>> UINT32
HXAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
ulTimeOut,
>>>>> IHXThread* pReceivingThread )
>>>>> {
>>>>> #ifdef _WIN32
>>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>>> #elif defined( _UNIX_THREADS_SUPPORTED
)
>>>>> -268,10 +282,15 
>>>>> return 0;
>>>>> //# error HXAsyncTimer::SetTimer not
defined on this platform.
>>>>> #endif
>>>>> }
>>>>>
>>>>>+UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, TIMERPROC pfExecFunc )
>>>>>+{
>>>>>+ return SetTimer(NULL, ulTimeOut,
pfExecFunc);
>>>>>+}
>>>>>+
>>>>> UINT32
HXAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
ulTimeOut,
>>>>> TIMERPROC pfExecFunc )
>>>>> {
>>>>> #ifdef _WIN32
>>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, pfExecFunc );
>>>>> #elif defined( _UNIX_THREADS_SUPPORTED
)
>>>>>Index: platform/unix/UnixThreads.cpp
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/platform/unix/UnixThreads.cpp,v
>>>>>retrieving revision 1.17
>>>>>diff -w -u -5 -r1.17 UnixThreads.cpp
>>>>>--- platform/unix/UnixThreads.cpp
24 Feb 2006 01:53:35
>>>>>-0000 1.17
>>>>>+++ platform/unix/UnixThreads.cpp
12 Jul 2006 22:02:19 -0000
>>>>> -60,10 +60,12 
>>>>> #include "hxassert.h"
//for HX_ASSERT
>>>>> #include "microsleep.h"
>>>>> #include "hxmsgs.h" //for
HXMSG_ASYNC_TIMER message.
>>>>> #include "hxtick.h" //for
GetTickCount()
>>>>> #include "pckunpck.h"
>>>>>+#include "chxthread.h"
>>>>>+#include "hxmutex.h"
>>>>>
>>>>>
>>>>>
//==========================================================
=======
>>>>> // In this section here include the OS
specific headerfiles for
>>>>> // each implementation.
>>>>> -817,39 +819,35 
>>>>> //Static data initializers
>>>>> IHXMutex*
HXUnixAsyncTimer::m_pmtxMapLock = NULL;
>>>>> CHXMapLongToObj
HXUnixAsyncTimer::m_mapTimers;
>>>>>
>>>>> //Timeouts are in miliseconds.
>>>>>-HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>>>ulTimeOut, IHXThread* pReceivingThread )
>>>>>+// Single protected constructor, used
in SetTimer
>>>>>+HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>>>ulTimeOut,
>>>>>+
TIMERPROC pfExecFunc,
>>>>>+
HXThread* pReceivingThread,
>>>>>+
IHXThread* pReceivingIThread )
>>>>> : m_ulTimeOut( ulTimeOut ),
>>>>>+ m_pfExecFunc(pfExecFunc),
>>>>> m_pReceivingThread(
pReceivingThread ),
>>>>>+ m_pReceivingIThread(
pReceivingIThread ),
>>>>> m_pMessagePump( NULL ),
>>>>>- m_pMsg(NULL),
>>>>>- m_pfExecFunc(NULL)
>>>>>+ m_pMsg(NULL)
>>>>> {
>>>>> //Make the message to pump.
>>>>> m_pMsg = new HXThreadMessage(
HXMSG_ASYNC_TIMER,
>>>>> (void*)m_ulTimeOut, NULL, NULL );
>>>>>
>>>>> //Start the thread. We have to do
this weird casting because
>>>>> //the HXThread::MakeThread takes
HXThread*&....
>>>>>+ if (pContext != NULL)
>>>>>+ {
>>>>> CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>>>>> pContext);
>>>>>- HX_ASSERT( m_pMessagePump );
>>>>>- m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>>>>> }
>>>>>-
>>>>>-HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>>>- : m_ulTimeOut( ulTimeOut ),
>>>>>- m_pReceivingThread(NULL),
>>>>>- m_pMessagePump(NULL),
>>>>>- m_pMsg(NULL),
>>>>>- m_pfExecFunc( pfExecFunc )
>>>>>+ else
>>>>> {
>>>>>- //we need non-null pfExecFunc
>>>>>- HX_ASSERT( m_pfExecFunc != NULL );
>>>>>-
>>>>>- //Start the thread.
>>>>>- CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>>>>>pContext);
>>>>>+ m_pMessagePump = new
CHXThread();
>>>>>+ }
>>>>> HX_ASSERT( m_pMessagePump );
>>>>> m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>>>>> }
>>>>>
>>>>> HXUnixAsyncTimer::~HXUnixAsyncTimer()
>>>>> -888,66 +886,75 
>>>>> }
>>>>>
>>>>> microsleep(
PARG->m_ulTimeOut*1000 );
>>>>>
>>>>> if( PARG->m_pMsg != NULL )
>>>>>-
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, NULL );
>>>>>+ {
>>>>>+ if
(PARG->m_pReceivingThread != NULL)
>>>>>+ {
>>>>>+
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, 0);
>>>>>+ }
>>>>>+ else if
(PARG->m_pReceivingIThread != NULL)
>>>>>+ {
>>>>>+
PARG->m_pReceivingIThread->PostMessage(
PARG->m_pMsg, 0);
>>>>>+ }
>>>>>+ }
>>>>> else
>>>>>+ {
>>>>> PARG->m_pfExecFunc( 0,
0, PARG->GetID(), GetTickCount() );
>>>>> }
>>>>>+ }
>>>>> return NULL;
>>>>> }
>>>>> #undef PARG
>>>>>
>>>>>-UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, IHXThread* pReceivingThread )
>>>>>-{
>>>>>- if( m_pmtxMapLock == NULL )
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, IHXThread* pReceivingIThread
)
>>>>> {
>>>>>-
CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>>>>>pContext);
>>>>>- HX_ASSERT( m_pmtxMapLock );
>>>>>+ HX_ASSERT(pReceivingIThread);
>>>>>+ return SetTimer(pContext,
ulTimeOut, NULL, NULL, pReceivingIThread);
>>>>> }
>>>>>
>>>>>- //lock it.
>>>>>- HX_LOCK(m_pmtxMapLock);
>>>>>-
>>>>>- ULONG32 ulTimerID = 0;
>>>>>-
>>>>>- HX_ASSERT( ulTimeOut != 0 );
>>>>>- HX_ASSERT( pReceivingThread != NULL
);
>>>>>-
>>>>>- HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>>>ulTimeOut, pReceivingThread );
>>>>>- HX_ASSERT( pTimer != NULL );
>>>>>- if( pTimer != NULL )
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(ULONG32 ulTimeOut, HXThread*
>>>>>pReceivingThread )
>>>>> {
>>>>>- //Add new timer to map.
>>>>>- ulTimerID = pTimer->GetID();
>>>>>- m_mapTimers.SetAt( ulTimerID,
(void*)pTimer );
>>>>>+ HX_ASSERT(pReceivingThread);
>>>>>+ return SetTimer(NULL, ulTimeOut,
NULL, pReceivingThread, NULL);
>>>>> }
>>>>>
>>>>>- //unlock the map.
>>>>>- HX_UNLOCK(m_pmtxMapLock);
>>>>>-
>>>>>- return ulTimerID;
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>>>+{
>>>>>+ HX_ASSERT( pfExecFunc != NULL );
>>>>>+ return SetTimer(pContext,
ulTimeOut, pfExecFunc, NULL, NULL);
>>>>> }
>>>>>
>>>>>-UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
ulTimeOut,
>>>>>+ TIMERPROC pfExecFunc,
>>>>>+ HXThread*
pReceivingThread,
>>>>>+ IHXThread*
pReceivingIThread )
>>>>>+{
>>>>>+ // Create the IHXMutex
>>>>>+ if (pContext)
>>>>> {
>>>>> if( m_pmtxMapLock == NULL )
>>>>> {
>>>>>
CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>>>>> pContext);
>>>>> HX_ASSERT( m_pmtxMapLock );
>>>>> }
>>>>>+ }
>>>>>+ else if ( m_pmtxMapLock == NULL )
>>>>>+ {
>>>>>+ m_pmtxMapLock = new CHXMutex();
>>>>>+ HX_ASSERT( m_pmtxMapLock );
>>>>>+ }
>>>>>
>>>>> //lock it.
>>>>> HX_LOCK(m_pmtxMapLock);
>>>>>
>>>>> ULONG32 ulTimerID = 0;
>>>>>-
>>>>> HX_ASSERT( ulTimeOut != 0 );
>>>>>- HX_ASSERT( pfExecFunc != NULL );
>>>>>
>>>>>- HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>>>ulTimeOut, pfExecFunc );
>>>>>+ HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext, ulTimeOut,
>>>>>+
pfExecFunc, pReceivingThread,
>>>>>pReceivingIThread );
>>>>> HX_ASSERT( pTimer != NULL );
>>>>> if( pTimer != NULL )
>>>>> {
>>>>> //Add new timer to map.
>>>>> ulTimerID =
pTimer->GetID();
>>>>> -984,8 +991,6 
>>>>> HX_UNLOCK(m_pmtxMapLock);
>>>>>
>>>>> return bRetVal;
>>>>> }
>>>>>
>>>>>-
>>>>>-
>>>>> #endif //_UNIX_THREADS_SUPPORTED
>>>>>Index: pub/hxthread.h
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/pub/hxthread.h,v
>>>>>retrieving revision 1.13
>>>>>diff -w -u -5 -r1.13 hxthread.h
>>>>>--- pub/hxthread.h 24 Feb 2006
01:12:55 -0000 1.13
>>>>>+++ pub/hxthread.h 12 Jul 2006
22:02:19 -0000
>>>>> -179,13 +179,15 
>>>>> // HXMSG_ASYNC_TIMER messages will
be posted to
>>>>> // pReceivingThread's message
queue every ulTimeOut milliseconds.
>>>>> // until KillTimer is called.
>>>>> // NOTE: under _WIN32
pReceivingThread is IGNORED and the calling
>>>>> // thread is the one to recieve
the timer messages (WM_TIMER).
>>>>>- static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingThread );
>>>>>+ static UINT32 SetTimer(ULONG32
ulTimeOut, HXThread*
>>>>>pReceivingThread );
>>>>>+ static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingIThread );
>>>>>
>>>>> // pfExecFunc will be called every
ulTimeOut milliseconds.
>>>>>+ static UINT32 SetTimer(ULONG32
ulTimeOut, TIMERPROC pfExecFunc );
>>>>> static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>> TIMERPROC pfExecFunc );
>>>>>
>>>>> // ulTimeOut timer is
killed/removed.
>>>>> static HXBOOL KillTimer(UINT32
ulTimerID );
>>>>> };
>>>>>Index: pub/platform/unix/UnixThreads.h
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/pub/platform/unix/UnixThreads.h,v
>>>>>retrieving revision 1.9
>>>>>diff -w -u -5 -r1.9 UnixThreads.h
>>>>>--- pub/platform/unix/UnixThreads.h
24 Feb 2006 01:12:56
>>>>>-0000 1.9
>>>>>+++ pub/platform/unix/UnixThreads.h
12 Jul 2006 22:02:19 -0000
>>>>> -294,43 +294,48 
>>>>> class HXUnixAsyncTimer
>>>>> {
>>>>> 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(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingThread );
>>>>>+ // These three methods are the main
interface into this class.
>>>>>+ // Works just like the windows
::SetTimer and ::KillTimer functions.
>>>>>+ //
>>>>>+ //This starts the message pump
sending HXMSG_ASYNC_TIMER messages
>>>>>+ //to pReceivingThread's queue
every ulThreadId milliseconds.
>>>>>+ static UINT32 SetTimer(ULONG32
ulTimeOut, HXThread*
>>>>>pReceivingThread );
>>>>>+ static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingIThread );
>>>>>+ // This starts the timer and calls
pfExecFunc every ulTimeOut
>>>>>milliseconds.
>>>>> static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>> TIMERPROC pfExecFunc );
>>>>>+ //this kills the timer and stops
pumping messages/func calls.
>>>>> static HXBOOL KillTimer(UINT32
ulTimerID );
>>>>>
>>>>> protected:
>>>>>
>>>>>- //This starts the message pump
sending HXMSG_ASYNC_TIMER messages
>>>>>- //to pReceivingThread's queue
every ulThreadId milliseconds.
>>>>>- HXUnixAsyncTimer( IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingThread );
>>>>>+ HXUnixAsyncTimer( IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>+ TIMERPROC pExecFunc,
>>>>>+ HXThread*
pReceivingThread,
>>>>>+ IHXThread*
pReceivingIThread );
>>>>>
>>>>>- //This starts the timer and calls
pfExecFunc every ulTimeOut
>>>>>milliseconds.
>>>>>- HXUnixAsyncTimer( IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>TIMERPROC pfExecFunc );
>>>>>-
>>>>>- //this kills the timer and stops
pumping messages/func calls.
>>>>> ~HXUnixAsyncTimer();
>>>>>
>>>>> //This returns that ID of this
timer (threadID).
>>>>> inline ULONG32 GetID();
>>>>>
>>>>> //This is the actual message pump.
>>>>> static void*
_ActualMessagePump(void* pArg);
>>>>>
>>>>> private:
>>>>>+ static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>TIMERPROC pfExecFunc,
>>>>>+ HXThread*
pReceivingThread, IHXThread*
>>>>>pReceivingIThread );
>>>>>
>>>>> ULONG32 m_ulTimeOut;
>>>>>- IHXThread*
m_pReceivingThread;
>>>>>+ TIMERPROC m_pfExecFunc;
>>>>>+ HXThread*
m_pReceivingThread;
>>>>>+ IHXThread*
m_pReceivingIThread;
>>>>> IHXThread* m_pMessagePump;
>>>>> HXThreadMessage* m_pMsg;
>>>>> HXThreadMessage m_msgTmp;
//This is a per-class msg to be
>>>>> used by the message pump.
>>>>>- TIMERPROC m_pfExecFunc;
>>>>>
>>>>> //Support for setting/killing
timers by ID.
>>>>> static IHXMutex*
m_pmtxMapLock;
>>>>> static CHXMapLongToObj
m_mapTimers;
>>>>
>>>>--------------------------------------------
----------------------------
>>>>____________________________________________
___
>>>>Common-dev mailing list
>>>>Common-dev helixcommunity.org
>>>>http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
>>
_______________________________________________
Common-dev mailing list
Common-dev helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
|
|
| CR: Make HXAsyncTimer::SetTimer usable
outside of core, and backwards
compatible |

|
2006-07-14 23:18:24 |
At 02:01 PM 7/14/2006, Greg Wright wrote:
>>>However, I only know of the core (threded engine
and timeline objects)
>>>that uses these async timers right now.
>>>
>>>Can you check on the size of the clntcore.so
(and possibly a quick
>>>check of other DLLs) and see what hit we take
for this change? I have
>>>a feeling that it is going to be very small, but
we should make sure.
>>The difference is ~300K in the debug build for
hxmedplyeng.so
>
>I don't think I would trust a debug build for sizes.
The compile may
>not do any work to remove unused code. Can you do a
release build of
>the two and see what that size diff is? I am sure it
will be a LOT
>less then 300K.
The release build diff is less than 6K. Not bad.
If I change the code back to the original HXUnixAsyncTimer
code, which uses
HXThread::MakeThread and HXMutex::MakeMutex, won't that be
the same linkage
result as 'new CHXThread' and 'new CHXMutex' ?
>>I wanted to create the message pump as an IHXThread,
so that I would not
>>have to duplicate all of the methods, one set for
IHXThread and one for
>>HXThread.
>>It's trivial to just add back the original code
that handles HXThread and
>>might
>>be less of a size change.
>>
>>>I still think the correct fix is to make a new
CHXAsyncTimer/IHXAsyncTimer.
>>>The only reason Set/Kill timer was static was
because that is the way
>>>win32 does it. We are free to change that if we
want. How much work is
>>>it to add a member var and just 'new' a async
timer and call Set/Kill
>>>on that?
>>This won't be any work really, since I already
added most of the code for
>>this.
>
>If we can do that, then would we not have this
situation:
>
>o HXAsyncTime goes back to the original version, no
context at all.
>o A new CHXAsyncTimer is created that interfaces with
the original
> version of the async timers.
>o The core is changed to use the the CHXAsyncTimer (by
new'ing it or
> something). It would no longer be static.
>o Your code can just use the old original version.
>
>How does that sound?
>
>>--christina
>>
>>>--greg.
>>>
>>>
>>>
>>>>Files:
>>>>common/system/hxthread.cpp
>>>>common/system/pub/hxthread.h
>>>> - Add back old SetTimer method,
with HXThread, no context
>>>>common/system/platform/unix/UnixThreads.cpp
>>>>common/system/pub/platform/unix/UnixThreads.
h
>>>> - Add old SetTimer methods back
>>>> - add private SetTimer that all the
public SetTimers call, for
>>>> single point of entry and no code dup
>>>>Branches: HEAD
>>>>Diff: (a little hard to read, so view the
attached file,
>>>>UnixThreads.cpp , for clarity)
>>>>
>>>>>Index: hxthread.cpp
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/hxthread.cpp,v
>>>>>retrieving revision 1.12
>>>>>diff -w -u -5 -r1.12 hxthread.cpp
>>>>>--- hxthread.cpp 23 Feb 2006
22:31:02 -0000 1.12
>>>>>+++ hxthread.cpp 12 Jul 2006
22:02:19 -0000
>>>>> -254,10 +254,24 
>>>>>
>>>>>
>>>>> //
>>>>> // HXAsyncTimer mehtods.
>>>>> //
>>>>>+UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, HXThread*
>>>>>pReceivingThread )
>>>>>+{
>>>>>+#ifdef _WIN32
>>>>>+ return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>>>+#elif defined( _UNIX_THREADS_SUPPORTED
)
>>>>>+ return
HXUnixAsyncTimer::SetTimer(ulTimeOut, pReceivingThread);
>>>>>+#elif defined _SYMBIAN
>>>>>+ return 0; // TODO:
HXSymbianAsyncTimer::SetTimer(ulTimeOut,
>>>>>pReceivingThread);
>>>>>+#else
>>>>>+ return 0;
>>>>>+//# error HXAsyncTimer::SetTimer not
defined on this platform.
>>>>>+#endif
>>>>>+}
>>>>>+
>>>>> UINT32
HXAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
ulTimeOut,
>>>>> IHXThread* pReceivingThread )
>>>>> {
>>>>> #ifdef _WIN32
>>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>>> #elif defined( _UNIX_THREADS_SUPPORTED
)
>>>>> -268,10 +282,15 
>>>>> return 0;
>>>>> //# error HXAsyncTimer::SetTimer not
defined on this platform.
>>>>> #endif
>>>>> }
>>>>>
>>>>>+UINT32 HXAsyncTimer::SetTimer(ULONG32
ulTimeOut, TIMERPROC pfExecFunc )
>>>>>+{
>>>>>+ return SetTimer(NULL, ulTimeOut,
pfExecFunc);
>>>>>+}
>>>>>+
>>>>> UINT32
HXAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
ulTimeOut,
>>>>> TIMERPROC pfExecFunc )
>>>>> {
>>>>> #ifdef _WIN32
>>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, pfExecFunc );
>>>>> #elif defined( _UNIX_THREADS_SUPPORTED
)
>>>>>Index: platform/unix/UnixThreads.cpp
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/platform/unix/UnixThreads.cpp,v
>>>>>retrieving revision 1.17
>>>>>diff -w -u -5 -r1.17 UnixThreads.cpp
>>>>>--- platform/unix/UnixThreads.cpp
24 Feb 2006 01:53:35
>>>>>-0000 1.17
>>>>>+++ platform/unix/UnixThreads.cpp
12 Jul 2006 22:02:19 -0000
>>>>> -60,10 +60,12 
>>>>> #include "hxassert.h"
//for HX_ASSERT
>>>>> #include "microsleep.h"
>>>>> #include "hxmsgs.h" //for
HXMSG_ASYNC_TIMER message.
>>>>> #include "hxtick.h" //for
GetTickCount()
>>>>> #include "pckunpck.h"
>>>>>+#include "chxthread.h"
>>>>>+#include "hxmutex.h"
>>>>>
>>>>>
>>>>>
//==========================================================
=======
>>>>> // In this section here include the OS
specific headerfiles for
>>>>> // each implementation.
>>>>> -817,39 +819,35 
>>>>> //Static data initializers
>>>>> IHXMutex*
HXUnixAsyncTimer::m_pmtxMapLock = NULL;
>>>>> CHXMapLongToObj
HXUnixAsyncTimer::m_mapTimers;
>>>>>
>>>>> //Timeouts are in miliseconds.
>>>>>-HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>>>ulTimeOut, IHXThread* pReceivingThread )
>>>>>+// Single protected constructor, used
in SetTimer
>>>>>+HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>>>ulTimeOut,
>>>>>+
TIMERPROC pfExecFunc,
>>>>>+
HXThread* pReceivingThread,
>>>>>+
IHXThread* pReceivingIThread )
>>>>> : m_ulTimeOut( ulTimeOut ),
>>>>>+ m_pfExecFunc(pfExecFunc),
>>>>> m_pReceivingThread(
pReceivingThread ),
>>>>>+ m_pReceivingIThread(
pReceivingIThread ),
>>>>> m_pMessagePump( NULL ),
>>>>>- m_pMsg(NULL),
>>>>>- m_pfExecFunc(NULL)
>>>>>+ m_pMsg(NULL)
>>>>> {
>>>>> //Make the message to pump.
>>>>> m_pMsg = new HXThreadMessage(
HXMSG_ASYNC_TIMER,
>>>>> (void*)m_ulTimeOut, NULL, NULL );
>>>>>
>>>>> //Start the thread. We have to do
this weird casting because
>>>>> //the HXThread::MakeThread takes
HXThread*&....
>>>>>+ if (pContext != NULL)
>>>>>+ {
>>>>> CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>>>>> pContext);
>>>>>- HX_ASSERT( m_pMessagePump );
>>>>>- m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>>>>> }
>>>>>-
>>>>>-HXUnixAsyncTimer::HXUnixAsyncTimer(
IUnknown* pContext, ULONG32
>>>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>>>- : m_ulTimeOut( ulTimeOut ),
>>>>>- m_pReceivingThread(NULL),
>>>>>- m_pMessagePump(NULL),
>>>>>- m_pMsg(NULL),
>>>>>- m_pfExecFunc( pfExecFunc )
>>>>>+ else
>>>>> {
>>>>>- //we need non-null pfExecFunc
>>>>>- HX_ASSERT( m_pfExecFunc != NULL );
>>>>>-
>>>>>- //Start the thread.
>>>>>- CreateInstanceCCF(CLSID_IHXThread,
(void**)&m_pMessagePump,
>>>>>pContext);
>>>>>+ m_pMessagePump = new
CHXThread();
>>>>>+ }
>>>>> HX_ASSERT( m_pMessagePump );
>>>>> m_pMessagePump->CreateThread(
_ActualMessagePump, (void*)this, 0 );
>>>>> }
>>>>>
>>>>> HXUnixAsyncTimer::~HXUnixAsyncTimer()
>>>>> -888,66 +886,75 
>>>>> }
>>>>>
>>>>> microsleep(
PARG->m_ulTimeOut*1000 );
>>>>>
>>>>> if( PARG->m_pMsg != NULL )
>>>>>-
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, NULL );
>>>>>+ {
>>>>>+ if
(PARG->m_pReceivingThread != NULL)
>>>>>+ {
>>>>>+
PARG->m_pReceivingThread->PostMessage(
PARG->m_pMsg, 0);
>>>>>+ }
>>>>>+ else if
(PARG->m_pReceivingIThread != NULL)
>>>>>+ {
>>>>>+
PARG->m_pReceivingIThread->PostMessage(
PARG->m_pMsg, 0);
>>>>>+ }
>>>>>+ }
>>>>> else
>>>>>+ {
>>>>> PARG->m_pfExecFunc( 0,
0, PARG->GetID(), GetTickCount() );
>>>>> }
>>>>>+ }
>>>>> return NULL;
>>>>> }
>>>>> #undef PARG
>>>>>
>>>>>-UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, IHXThread* pReceivingThread )
>>>>>-{
>>>>>- if( m_pmtxMapLock == NULL )
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, IHXThread* pReceivingIThread
)
>>>>> {
>>>>>-
CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>>>>>pContext);
>>>>>- HX_ASSERT( m_pmtxMapLock );
>>>>>+ HX_ASSERT(pReceivingIThread);
>>>>>+ return SetTimer(pContext,
ulTimeOut, NULL, NULL, pReceivingIThread);
>>>>> }
>>>>>
>>>>>- //lock it.
>>>>>- HX_LOCK(m_pmtxMapLock);
>>>>>-
>>>>>- ULONG32 ulTimerID = 0;
>>>>>-
>>>>>- HX_ASSERT( ulTimeOut != 0 );
>>>>>- HX_ASSERT( pReceivingThread != NULL
);
>>>>>-
>>>>>- HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>>>ulTimeOut, pReceivingThread );
>>>>>- HX_ASSERT( pTimer != NULL );
>>>>>- if( pTimer != NULL )
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(ULONG32 ulTimeOut, HXThread*
>>>>>pReceivingThread )
>>>>> {
>>>>>- //Add new timer to map.
>>>>>- ulTimerID = pTimer->GetID();
>>>>>- m_mapTimers.SetAt( ulTimerID,
(void*)pTimer );
>>>>>+ HX_ASSERT(pReceivingThread);
>>>>>+ return SetTimer(NULL, ulTimeOut,
NULL, pReceivingThread, NULL);
>>>>> }
>>>>>
>>>>>- //unlock the map.
>>>>>- HX_UNLOCK(m_pmtxMapLock);
>>>>>-
>>>>>- return ulTimerID;
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>>>+{
>>>>>+ HX_ASSERT( pfExecFunc != NULL );
>>>>>+ return SetTimer(pContext,
ulTimeOut, pfExecFunc, NULL, NULL);
>>>>> }
>>>>>
>>>>>-UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>ulTimeOut, TIMERPROC pfExecFunc )
>>>>>+UINT32
HXUnixAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
ulTimeOut,
>>>>>+ TIMERPROC pfExecFunc,
>>>>>+ HXThread*
pReceivingThread,
>>>>>+ IHXThread*
pReceivingIThread )
>>>>>+{
>>>>>+ // Create the IHXMutex
>>>>>+ if (pContext)
>>>>> {
>>>>> if( m_pmtxMapLock == NULL )
>>>>> {
>>>>>
CreateInstanceCCF(CLSID_IHXMutex,
(void**)&m_pmtxMapLock,
>>>>> pContext);
>>>>> HX_ASSERT( m_pmtxMapLock );
>>>>> }
>>>>>+ }
>>>>>+ else if ( m_pmtxMapLock == NULL )
>>>>>+ {
>>>>>+ m_pmtxMapLock = new CHXMutex();
>>>>>+ HX_ASSERT( m_pmtxMapLock );
>>>>>+ }
>>>>>
>>>>> //lock it.
>>>>> HX_LOCK(m_pmtxMapLock);
>>>>>
>>>>> ULONG32 ulTimerID = 0;
>>>>>-
>>>>> HX_ASSERT( ulTimeOut != 0 );
>>>>>- HX_ASSERT( pfExecFunc != NULL );
>>>>>
>>>>>- HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext,
>>>>>ulTimeOut, pfExecFunc );
>>>>>+ HXUnixAsyncTimer* pTimer = new
HXUnixAsyncTimer(pContext, ulTimeOut,
>>>>>+
pfExecFunc, pReceivingThread,
>>>>>pReceivingIThread );
>>>>> HX_ASSERT( pTimer != NULL );
>>>>> if( pTimer != NULL )
>>>>> {
>>>>> //Add new timer to map.
>>>>> ulTimerID =
pTimer->GetID();
>>>>> -984,8 +991,6 
>>>>> HX_UNLOCK(m_pmtxMapLock);
>>>>>
>>>>> return bRetVal;
>>>>> }
>>>>>
>>>>>-
>>>>>-
>>>>> #endif //_UNIX_THREADS_SUPPORTED
>>>>>Index: pub/hxthread.h
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/pub/hxthread.h,v
>>>>>retrieving revision 1.13
>>>>>diff -w -u -5 -r1.13 hxthread.h
>>>>>--- pub/hxthread.h 24 Feb 2006
01:12:55 -0000 1.13
>>>>>+++ pub/hxthread.h 12 Jul 2006
22:02:19 -0000
>>>>> -179,13 +179,15 
>>>>> // HXMSG_ASYNC_TIMER messages will
be posted to
>>>>> // pReceivingThread's message
queue every ulTimeOut milliseconds.
>>>>> // until KillTimer is called.
>>>>> // NOTE: under _WIN32
pReceivingThread is IGNORED and the calling
>>>>> // thread is the one to recieve
the timer messages (WM_TIMER).
>>>>>- static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingThread );
>>>>>+ static UINT32 SetTimer(ULONG32
ulTimeOut, HXThread*
>>>>>pReceivingThread );
>>>>>+ static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingIThread );
>>>>>
>>>>> // pfExecFunc will be called every
ulTimeOut milliseconds.
>>>>>+ static UINT32 SetTimer(ULONG32
ulTimeOut, TIMERPROC pfExecFunc );
>>>>> static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>> TIMERPROC pfExecFunc );
>>>>>
>>>>> // ulTimeOut timer is
killed/removed.
>>>>> static HXBOOL KillTimer(UINT32
ulTimerID );
>>>>> };
>>>>>Index: pub/platform/unix/UnixThreads.h
>>>>>========================================
===========================
>>>>>RCS file:
/cvsroot/common/system/pub/platform/unix/UnixThreads.h,v
>>>>>retrieving revision 1.9
>>>>>diff -w -u -5 -r1.9 UnixThreads.h
>>>>>--- pub/platform/unix/UnixThreads.h
24 Feb 2006 01:12:56
>>>>>-0000 1.9
>>>>>+++ pub/platform/unix/UnixThreads.h
12 Jul 2006 22:02:19 -0000
>>>>> -294,43 +294,48 
>>>>> class HXUnixAsyncTimer
>>>>> {
>>>>> 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(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingThread );
>>>>>+ // These three methods are the main
interface into this class.
>>>>>+ // Works just like the windows
::SetTimer and ::KillTimer functions.
>>>>>+ //
>>>>>+ //This starts the message pump
sending HXMSG_ASYNC_TIMER messages
>>>>>+ //to pReceivingThread's queue
every ulThreadId milliseconds.
>>>>>+ static UINT32 SetTimer(ULONG32
ulTimeOut, HXThread*
>>>>>pReceivingThread );
>>>>>+ static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingIThread );
>>>>>+ // This starts the timer and calls
pfExecFunc every ulTimeOut
>>>>>milliseconds.
>>>>> static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>> TIMERPROC pfExecFunc );
>>>>>+ //this kills the timer and stops
pumping messages/func calls.
>>>>> static HXBOOL KillTimer(UINT32
ulTimerID );
>>>>>
>>>>> protected:
>>>>>
>>>>>- //This starts the message pump
sending HXMSG_ASYNC_TIMER messages
>>>>>- //to pReceivingThread's queue
every ulThreadId milliseconds.
>>>>>- HXUnixAsyncTimer( IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>IHXThread* pReceivingThread );
>>>>>+ HXUnixAsyncTimer( IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>+ TIMERPROC pExecFunc,
>>>>>+ HXThread*
pReceivingThread,
>>>>>+ IHXThread*
pReceivingIThread );
>>>>>
>>>>>- //This starts the timer and calls
pfExecFunc every ulTimeOut
>>>>>milliseconds.
>>>>>- HXUnixAsyncTimer( IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>TIMERPROC pfExecFunc );
>>>>>-
>>>>>- //this kills the timer and stops
pumping messages/func calls.
>>>>> ~HXUnixAsyncTimer();
>>>>>
>>>>> //This returns that ID of this
timer (threadID).
>>>>> inline ULONG32 GetID();
>>>>>
>>>>> //This is the actual message pump.
>>>>> static void*
_ActualMessagePump(void* pArg);
>>>>>
>>>>> private:
>>>>>+ static UINT32 SetTimer(IUnknown*
pContext, ULONG32 ulTimeOut,
>>>>>TIMERPROC pfExecFunc,
>>>>>+ HXThread*
pReceivingThread, IHXThread*
>>>>>pReceivingIThread );
>>>>>
>>>>> ULONG32 m_ulTimeOut;
>>>>>- IHXThread*
m_pReceivingThread;
>>>>>+ TIMERPROC m_pfExecFunc;
>>>>>+ HXThread*
m_pReceivingThread;
>>>>>+ IHXThread*
m_pReceivingIThread;
>>>>> IHXThread* m_pMessagePump;
>>>>> HXThreadMessage* m_pMsg;
>>>>> HXThreadMessage m_msgTmp;
//This is a per-class msg to be
>>>>> used by the message pump.
>>>>>- TIMERPROC m_pfExecFunc;
>>>>>
>>>>> //Support for setting/killing
timers by ID.
>>>>> static IHXMutex*
m_pmtxMapLock;
>>>>> static CHXMapLongToObj
m_mapTimers;
>>>>
>>>>--------------------------------------------
----------------------------
>>>>____________________________________________
___
>>>>Common-dev mailing list
>>>>Common-dev helixcommunity.org
>>>>http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
>>
_______________________________________________
Common-dev mailing list
Common-dev helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/comm
on-dev
|
|
| CR: Make HXAsyncTimer::SetTimer usable
outside of core, and backwards
compatible |

|
2006-07-14 23:23:12 |
Christina Dunn wrote:
> At 02:01 PM 7/14/2006, Greg Wright wrote:
>
>>>> However, I only know of the core (threded
engine and timeline objects)
>>>> that uses these async timers right now.
>>>>
>>>> Can you check on the size of the
clntcore.so (and possibly a quick
>>>> check of other DLLs) and see what hit we
take for this change? I have
>>>> a feeling that it is going to be very
small, but we should make sure.
>>> The difference is ~300K in the debug build for
hxmedplyeng.so
>>
>> I don't think I would trust a debug build for
sizes. The compile may
>> not do any work to remove unused code. Can you do a
release build of
>> the two and see what that size diff is? I am sure
it will be a LOT
>> less then 300K.
>
> The release build diff is less than 6K. Not bad.
> If I change the code back to the original
HXUnixAsyncTimer code, which uses
> HXThread::MakeThread and HXMutex::MakeMutex, won't
that be the same linkage
> result as 'new CHXThread' and 'new CHXMutex' ?
It shouldn't.
Every user of async timers in Helix will use the CCF to get
a hold of one. So, they will never link with the thread lib.
timeline.cpp, for example, will will no longer make static
calls to the original (or recently modified) async timers,
instead
it will use the platforms CCF to create and instance of an
async timer.
The platform, who owns the CCF, will be the only one that
can
create a async timer, so it will be the only one that has to
link against the threading lib.
Your app, of course, will use the original timers directly
and
will link against the thread libs as well.
--greg.
>
>
>>> I wanted to create the message pump as an
IHXThread, so that I would not
>>> have to duplicate all of the methods, one set
for IHXThread and one
>>> for HXThread.
>>> It's trivial to just add back the original
code that handles HXThread
>>> and might
>>> be less of a size change.
>>>
>>>> I still think the correct fix is to make a
new
>>>> CHXAsyncTimer/IHXAsyncTimer.
>>>> The only reason Set/Kill timer was static
was because that is the way
>>>> win32 does it. We are free to change that
if we want. How much work is
>>>> it to add a member var and just 'new' a
async timer and call Set/Kill
>>>> on that?
>>> This won't be any work really, since I already
added most of the code
>>> for this.
>>
>> If we can do that, then would we not have this
situation:
>>
>> o HXAsyncTime goes back to the original version, no
context at all.
>> o A new CHXAsyncTimer is created that interfaces
with the original
>> version of the async timers.
>> o The core is changed to use the the CHXAsyncTimer
(by new'ing it or
>> something). It would no longer be static.
>> o Your code can just use the old original version.
>>
>> How does that sound?
>>
>>> --christina
>>>
>>>> --greg.
>>>>
>>>>
>>>>
>>>>> Files:
>>>>> common/system/hxthread.cpp
>>>>> common/system/pub/hxthread.h
>>>>> - Add back old SetTimer method,
with HXThread, no context
>>>>>
common/system/platform/unix/UnixThreads.cpp
>>>>>
common/system/pub/platform/unix/UnixThreads.h
>>>>> - Add old SetTimer methods back
>>>>> - add private SetTimer that all
the public SetTimers call,
>>>>> for single point of entry and no code
dup
>>>>> Branches: HEAD
>>>>> Diff: (a little hard to read, so view
the attached file,
>>>>> UnixThreads.cpp , for clarity)
>>>>>
>>>>>> Index: hxthread.cpp
>>>>>>
============================================================
=======
>>>>>> RCS file:
/cvsroot/common/system/hxthread.cpp,v
>>>>>> retrieving revision 1.12
>>>>>> diff -w -u -5 -r1.12 hxthread.cpp
>>>>>> --- hxthread.cpp 23 Feb 2006
22:31:02 -0000 1.12
>>>>>> +++ hxthread.cpp 12 Jul 2006
22:02:19 -0000
>>>>>>  -254,10 +254,24 
>>>>>>
>>>>>>
>>>>>> //
>>>>>> // HXAsyncTimer mehtods.
>>>>>> //
>>>>>> +UINT32
HXAsyncTimer::SetTimer(ULONG32 ulTimeOut, HXThread*
>>>>>> pReceivingThread )
>>>>>> +{
>>>>>> +#ifdef _WIN32
>>>>>> + return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>>>> +#elif defined(
_UNIX_THREADS_SUPPORTED )
>>>>>> + return
HXUnixAsyncTimer::SetTimer(ulTimeOut, pReceivingThread);
>>>>>> +#elif defined _SYMBIAN
>>>>>> + return 0; // TODO:
HXSymbianAsyncTimer::SetTimer(ulTimeOut,
>>>>>> pReceivingThread);
>>>>>> +#else
>>>>>> + return 0;
>>>>>> +//# error HXAsyncTimer::SetTimer
not defined on this platform.
>>>>>> +#endif
>>>>>> +}
>>>>>> +
>>>>>> UINT32
HXAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>> ulTimeOut, IHXThread*
pReceivingThread )
>>>>>> {
>>>>>> #ifdef _WIN32
>>>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, NULL );
>>>>>> #elif defined(
_UNIX_THREADS_SUPPORTED )
>>>>>>  -268,10 +282,15 
>>>>>> return 0;
>>>>>> //# error HXAsyncTimer::SetTimer
not defined on this platform.
>>>>>> #endif
>>>>>> }
>>>>>>
>>>>>> +UINT32
HXAsyncTimer::SetTimer(ULONG32 ulTimeOut, TIMERPROC
>>>>>> pfExecFunc )
>>>>>> +{
>>>>>> + return SetTimer(NULL,
ulTimeOut, pfExecFunc);
>>>>>> +}
>>>>>> +
>>>>>> UINT32
HXAsyncTimer::SetTimer(IUnknown* pContext, ULONG32
>>>>>> ulTimeOut, TIMERPROC pfExecFunc )
>>>>>> {
>>>>>> #ifdef _WIN32
>>>>>> return ::SetTimer( NULL, NULL,
ulTimeOut, pfExecFunc );
>>>>>> #elif defined(
_UNIX_THREADS_SUPPORTED )
>>>>>> Index:
platform/unix/UnixThreads.cpp
>>>>>>
============================================================
=======
>> | |