Index: aqua/inc/saldata.hxx =================================================================== RCS file: /cvs/gsl/vcl/aqua/inc/saldata.hxx,v retrieving revision 1.12.112.6 diff -u -r1.12.112.6 saldata.hxx --- aqua/inc/saldata.hxx 23 May 2007 13:21:41 -0000 1.12.112.6 +++ aqua/inc/saldata.hxx 14 Jun 2007 13:09:38 -0000 @@ -37,6 +37,11 @@ #ifndef _SV_SALDATA_HXX #define _SV_SALDATA_HXX +#include +#include +#include + + #ifndef _SV_SV_H #include #endif @@ -92,6 +97,17 @@ SalPrinter *mpFirstPrinter; // first printing printer SystemFontList *mpFontList; + + /* + * SalTimer related members + */ + BOOL mbInTimerProc; // timer event is currently being dispatched + BOOL mbTimerInstalled; // timer is in the event loop + ULONG mnTimerMS; // Current Time (in MS) of the Timer + ULONG mnTimerOrgMS; // Current Original Time (in MS) + + EventLoopTimerRef mrTimerRef; + EventLoopTimerUPP mrTimerUPP; static FILE *s_pLog; SalData() : Index: aqua/inc/saltimer.h =================================================================== RCS file: /cvs/gsl/vcl/aqua/inc/Attic/saltimer.h,v retrieving revision 1.2.2.2 diff -u -r1.2.2.2 saltimer.h --- aqua/inc/saltimer.h 2 Mar 2006 00:31:02 -0000 1.2.2.2 +++ aqua/inc/saltimer.h 14 Jun 2007 13:09:38 -0000 @@ -38,6 +38,7 @@ #include #include +#include #include #ifndef _SV_SALTIMER_HXX @@ -46,23 +47,14 @@ class AquaSalTimer : public SalTimer { -private: - TMTask mTask; // the timer task - BOOL mbInstalled; // timer task is in queue - long mMS; // current timer interval in msec - BOOL InstallTask(); // installs timer task and returns status - -public: + public: + AquaSalTimer(); virtual ~AquaSalTimer(); - - // overload all pure virtual methods - void Start( ULONG nMS ); - void Stop(); - - // restarts active tasks using the current timeout - // optional with different timeout (when nMS is != 0) - void ReStart( ULONG nMS = 0 ); + + void Start( ULONG nMS ); + void Stop(); + }; #endif Index: aqua/source/app/saltimer.cxx =================================================================== RCS file: /cvs/gsl/vcl/aqua/source/app/saltimer.cxx,v retrieving revision 1.10.112.9 diff -u -r1.10.112.9 saltimer.cxx --- aqua/source/app/saltimer.cxx 23 May 2007 13:21:42 -0000 1.10.112.9 +++ aqua/source/app/saltimer.cxx 14 Jun 2007 13:09:38 -0000 @@ -51,105 +51,120 @@ #define USEMAINTHREAD 1 -void AquaSalTimerProc ( TMTaskPtr tmTaskPtr ) +void ImplSalStartTimer ( ULONG nMS, BOOL bMutex) { - ImplSVData* pSVData = ImplGetSVData(); - - AquaSalTimer *pSalTimer = (AquaSalTimer*) pSVData->mpSalTimer; - if( pSalTimer ) - { -#ifdef USEMAINTHREAD - // send event to main thread - SalData* pSalData = GetSalData(); + AquaLog( "ImplSalStartTimer\n"); + + SalData* pSalData = GetSalData(); + + // Store the new timeout + pSalData->mnTimerMS = nMS; + + if ( !bMutex ) + pSalData->mnTimerOrgMS = nMS; + + // Cancel current timer + if( pSalData->mbTimerInstalled ) + RemoveEventLoopTimer( pSalData->mrTimerRef ); + + // Install the timer task + if( InstallEventLoopTimer( GetMainEventLoop(), + kEventDurationMillisecond * nMS, + kEventDurationForever, + pSalData->mrTimerUPP, + NULL, + &pSalData->mrTimerRef) == noErr ) + { + pSalData->mbTimerInstalled = TRUE; + } + else + { + AquaLog( "Could not install timer task!\n"); + pSalData->mbTimerInstalled = FALSE; + } +} + +void AquaSalTimerProc ( EventLoopTimerRef theTimer, void * /* userData */) +{ + AquaLog( "...AquaSalTimerProc...\n"); + + SalData* pSalData = GetSalData(); + ImplSVData* pSVData = ImplGetSVData(); + AquaSalTimer *pSalTimer = (AquaSalTimer*) pSVData->mpSalTimer; + + if( pSalTimer && !pSalData->mbInTimerProc ) + { + #ifdef USEMAINTHREAD + // Send event to the main thread if( ! pSalData->maFrames.empty() ) pSalData->maFrames.front()->PostTimerEvent( pSalTimer ); + + // FIXME? // fire again using current timeout as this is a single shot timer - pSalTimer->ReStart(); -#else + ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE ); + #else // call back directly from timer thread - if( ImplSalYieldMutexTryToAcquire() ) - { - pSalTimer->CallCallback(); - ImplSalYieldMutexRelease(); - - // fire again using current timeout as this is a single shot timer - pSalTimer->ReStart(); - } - else - { - // could not acquire solar mutex, so - // fire again with a short delay (10ms) - //AquaLog( "TIMER: solar mutex not free\n"); - pSalTimer->ReStart( 10 ); - } - -#endif - } -} + if( ImplSalYieldMutexTryToAcquire() ) + { + pSalData->mbInTimerProc = TRUE; + pSalTimer->CallCallback(); + pSalData->mbInTimerProc = FALSE; + ImplSalYieldMutexRelease(); + + // FIXME? + // fire again using current timeout as this is a single shot timer + ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE ); + } + else + { + // could not acquire solar mutex, so + // fire again with a short delay (10ms) + AquaLog( "SHOULD NOT HAPPEN! TIMER: solar mutex not free\n"); + ImplSalStartTimer( 10, TRUE ); + } + #endif + } +} -// ----------------------------------------------------------------------- AquaSalTimer::AquaSalTimer( ) { - mbInstalled = FALSE; - mMS = 0; - mTask.tmAddr = NewTimerUPP( AquaSalTimerProc ); + AquaLog( "AquaSalTimer::AquaSalTimer\n"); + SalData* pSalData = GetSalData(); + + pSalData->mbTimerInstalled = FALSE; + pSalData->mnTimerMS = 0; + pSalData->mnTimerOrgMS = 0; + pSalData->mrTimerUPP = NewEventLoopTimerUPP( AquaSalTimerProc ); } AquaSalTimer::~AquaSalTimer() { - if( mbInstalled ) - RemoveTimeTask( (QElemPtr) &mTask ); - DisposeTimerUPP( mTask.tmAddr ); + AquaLog( "AquaSalTimer::~AquaSalTimer\n"); + + SalData* pSalData = GetSalData(); + if( pSalData->mbTimerInstalled ) + RemoveEventLoopTimer( pSalData->mrTimerRef ); + + DisposeEventLoopTimerUPP( pSalData->mrTimerUPP ); } -// ----------------------------------------------------------------------- - void AquaSalTimer::Start( ULONG nMS ) { - // cancel current timer - if( mbInstalled ) - RemoveTimeTask( (QElemPtr) &mTask ); - - // store new timeout - mMS = nMS; - - // install the timer task - mbInstalled = InstallTask(); - - // fire - if( mbInstalled ) - PrimeTimeTask( (QElemPtr) &mTask, mMS ); -} - -void AquaSalTimer::ReStart( ULONG nMS ) -{ - if( mbInstalled ) - // use current timeout if nMS == 0 - PrimeTimeTask( (QElemPtr) &mTask, nMS ? nMS : mMS ); + ImplSalStartTimer(nMS, FALSE); } void AquaSalTimer::Stop() { - if( mbInstalled ) - { - RemoveTimeTask( (QElemPtr) &mTask ); - mbInstalled = FALSE; - } + AquaLog( "AquaSalTimer::Stop\n"); + + SalData* pSalData = GetSalData(); + if( pSalData->mbTimerInstalled ) + { + // FIXME + RemoveEventLoopTimer( pSalData->mrTimerRef ); + pSalData->mbTimerInstalled = FALSE; + } } -BOOL AquaSalTimer::InstallTask() -{ - // install the timer task - mTask.tmWakeUp = 0; - mTask.tmCount = 0; - if( InstallTimeTask( (QElemPtr) &mTask ) == noErr ) - return TRUE; - else - { - AquaLog( "Could not install timer task!\n"); - return FALSE; - } -} -// -----------------------------------------------------------------------