Commit 0a3fa2c8 authored by Cyril Deguet's avatar Cyril Deguet

* better implementation of timers for X11 skins

parent 9ca2bbfb
......@@ -2,7 +2,7 @@
* x11_run.cpp:
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_run.cpp,v 1.18 2003/06/08 00:32:07 asmax Exp $
* $Id: x11_run.cpp,v 1.19 2003/06/08 11:33:14 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -168,7 +168,7 @@ void OSRun( intf_thread_t *p_intf )
// Timer for SkinManage
X11Timer *refreshTimer = new X11Timer( p_intf, 100, RefreshCallback,
X11Timer *refreshTimer = new X11Timer( p_intf, 100000, RefreshCallback,
(void*)p_intf );
X11TimerManager *timerManager = X11TimerManager::Instance( p_intf );
timerManager->addTimer( refreshTimer );
......
......@@ -2,7 +2,7 @@
* x11_timer.cpp: helper class to implement timers
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_timer.cpp,v 1.2 2003/06/07 12:19:23 asmax Exp $
* $Id: x11_timer.cpp,v 1.3 2003/06/08 11:33:14 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -41,22 +41,32 @@ X11Timer::X11Timer( intf_thread_t *p_intf, mtime_t interval, callback_t func,
_interval = interval;
_callback = func;
_data = data;
_nextDate = 0;
vlc_mutex_init( p_intf, &_lock );
}
X11Timer::~X11Timer()
{
vlc_mutex_destroy( &_lock );
}
mtime_t X11Timer::getNextDate( mtime_t current )
void X11Timer::SetDate( mtime_t date )
{
return (current / _interval + 1) * _interval;
_nextDate = date + _interval;
}
mtime_t X11Timer::GetNextDate()
{
return _nextDate;
}
bool X11Timer::Execute()
{
_nextDate += _interval;
return (*_callback)( _data );
}
......@@ -70,6 +80,8 @@ X11TimerManager::X11TimerManager( intf_thread_t *p_intf )
{
_p_intf = p_intf;
vlc_mutex_init( p_intf, &_lock );
// Create the timer thread
_p_timer = (timer_thread_t*)vlc_object_create( _p_intf,
sizeof( timer_thread_t ) );
......@@ -81,6 +93,8 @@ X11TimerManager::~X11TimerManager()
{
_p_timer->die = 1;
vlc_thread_join( _p_timer );
vlc_mutex_destroy( &_lock );
}
......@@ -115,19 +129,67 @@ void *X11TimerManager::Thread( void *p_timer )
while( !((timer_thread_t*)p_timer)->die )
{
_instance->WaitNextTimer();
}
}
void X11TimerManager::WaitNextTimer()
{
mtime_t curDate = mdate();
mtime_t nextDate = LAST_MDATE;
X11Timer *nextTimer = NULL;
Lock();
// Find the next timer to execute
list<X11Timer*>::iterator timer;
// FIXME temporary
for( timer = _instance->_timers.begin();
timer != _instance->_timers.end(); timer++ )
for( timer = _timers.begin(); timer != _timers.end(); timer++ )
{
bool ret = (*timer)->Execute();
if( !ret )
{ _instance->_timers.remove( *timer );
break;
mtime_t timerDate = (*timer)->GetNextDate();
if( timerDate < nextDate )
{
nextTimer = *timer;
nextDate = timerDate;
}
}
msleep( 100000 );
Unlock();
if( nextTimer == NULL )
{
// FIXME: should wait on a cond instead
msleep( 10000 );
}
else
{
if( nextDate > curDate )
{
mwait( nextDate );
}
bool ret = nextTimer->Execute();
if( !ret )
{
_timers.remove( nextTimer );
}
}
}
void X11TimerManager::addTimer( X11Timer *timer )
{
timer->SetDate( mdate() );
_timers.push_back( timer );
}
void X11TimerManager::removeTimer( X11Timer *timer )
{
Lock();
timer->Lock();
_timers.remove( timer );
Unlock();
timer->Unlock();
}
#endif
......@@ -2,7 +2,7 @@
* x11_timer.h: helper class to implement timers
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_timer.h,v 1.2 2003/06/07 12:19:23 asmax Exp $
* $Id: x11_timer.h,v 1.3 2003/06/08 11:33:14 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -46,14 +46,20 @@ class X11Timer
mtime_t _interval;
callback_t _callback;
void *_data;
vlc_mutex_t _lock;
mtime_t _nextDate;
public:
X11Timer( intf_thread_t *p_intf, mtime_t interval, callback_t func,
void *data );
~X11Timer();
mtime_t getNextDate( mtime_t current );
void SetDate( mtime_t date );
mtime_t GetNextDate();
bool Execute();
inline void Lock() { vlc_mutex_lock( &_lock ); }
inline void Unlock() { vlc_mutex_unlock( &_lock ); }
};
//---------------------------------------------------------------------------
class X11TimerManager
......@@ -63,19 +69,23 @@ class X11TimerManager
intf_thread_t *_p_intf;
timer_thread_t *_p_timer;
list<X11Timer*> _timers;
vlc_mutex_t _lock;
X11TimerManager( intf_thread_t *p_intf );
~X11TimerManager();
static void *Thread( void *p_timer );
void WaitNextTimer();
public:
static X11TimerManager *Instance( intf_thread_t *p_intf );
void Destroy();
void addTimer( X11Timer *timer ) { _timers.push_back( timer ); }
void removeTimer( X11Timer *timer ) { _timers.remove( timer ); }
void addTimer( X11Timer *timer );
void removeTimer( X11Timer *timer );
inline void Lock() { vlc_mutex_lock( &_lock ); }
inline void Unlock() { vlc_mutex_unlock( &_lock ); }
};
//---------------------------------------------------------------------------
#endif
......@@ -2,7 +2,7 @@
* x11_window.cpp: X11 implementation of the Window class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_window.cpp,v 1.13 2003/06/08 00:32:07 asmax Exp $
* $Id: x11_window.cpp,v 1.14 2003/06/08 11:33:14 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -116,7 +116,7 @@ X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
XUNLOCK;
ToolTip.display = display;
X11Timer *timer = new X11Timer( p_intf, 100, ToolTipCallback, &ToolTip );
X11Timer *timer = new X11Timer( p_intf, 500000, ToolTipCallback, &ToolTip );
ToolTip.p_intf = p_intf;
ToolTip.timer = timer;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment