diff options
| author | Andreas Monzner <andreas.monzner@multimedia-labs.de> | 2008-10-29 22:44:53 +0000 |
|---|---|---|
| committer | Andreas Monzner <andreas.monzner@multimedia-labs.de> | 2008-10-29 22:44:53 +0000 |
| commit | 0c59a4279f93f08fe95fca5f2e55f3e025f0cceb (patch) | |
| tree | 71e8c11f2a5487afe84d637d388d3cb060bc9ad5 /lib/base | |
| parent | 4edb65fafb64b52007598e05a1e5b16b75ea752c (diff) | |
| download | enigma2-0c59a4279f93f08fe95fca5f2e55f3e025f0cceb.tar.gz enigma2-0c59a4279f93f08fe95fca5f2e55f3e025f0cceb.zip | |
also use refcounting for eTimers
its now no more possible directly to call new eTimer .. or to embedded
eTimer.
to create a eTimer now eTimer::create must be used... to delete you must
call ->AddRef() after timer creation and ->Release when the timer is no more
needed. Or use ePtr<eTimer> to store the timer reference.. then its enough
to set the ePtr<eTimer> object to 0 when the timer is no more needed
Diffstat (limited to 'lib/base')
| -rw-r--r-- | lib/base/ebase.cpp | 15 | ||||
| -rw-r--r-- | lib/base/ebase.h | 9 |
2 files changed, 18 insertions, 6 deletions
diff --git a/lib/base/ebase.cpp b/lib/base/ebase.cpp index a66d1958..bd2ec589 100644 --- a/lib/base/ebase.cpp +++ b/lib/base/ebase.cpp @@ -39,7 +39,8 @@ void eSocketNotifier::stop() } } - // timer +DEFINE_REF(eTimer); + void eTimer::start(long msek, bool singleShot) { if (bActive) @@ -160,7 +161,12 @@ int eMainloop::processOneEvent(unsigned int twisted_timeout, PyObject **res, ePy { /* process all timers which are ready. first remove them out of the list. */ while (!m_timer_list.empty() && (poll_timeout = timeout_usec( m_timer_list.begin()->getNextActivation() ) ) <= 0 ) - m_timer_list.begin()->activate(); + { + eTimer *tmr = m_timer_list.begin(); + tmr->AddRef(); + tmr->activate(); + tmr->Release(); + } if (poll_timeout < 0) poll_timeout = 0; else /* convert us to ms */ @@ -403,7 +409,7 @@ eTimerPy_dealloc(eTimerPy* self) if (self->in_weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *) self); eTimerPy_clear(self); - delete self->tm; + self->tm->Release(); self->ob_type->tp_free((PyObject*)self); } @@ -411,7 +417,8 @@ static PyObject * eTimerPy_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { eTimerPy *self = (eTimerPy *)type->tp_alloc(type, 0); - self->tm = new eTimer(eApp); + self->tm = eTimer::create(eApp); + self->tm->AddRef(); self->in_weakreflist = NULL; return (PyObject *)self; } diff --git a/lib/base/ebase.h b/lib/base/ebase.h index 9c524ae9..c86c177d 100644 --- a/lib/base/ebase.h +++ b/lib/base/ebase.h @@ -269,8 +269,9 @@ public: * * This class emits the signal \c eTimer::timeout after the specified timeout. */ -class eTimer +class eTimer: iObject { + DECLARE_REF(eTimer); friend class eMainloop; eMainloop &context; timespec nextActivation; @@ -278,6 +279,9 @@ class eTimer bool bSingleShot; bool bActive; void activate(); + + eTimer(eMainloop *context): context(*context), bActive(false) { } + void operator delete(void *pmem) { ::operator delete(pmem); } public: /** * \brief Constructs a timer. @@ -285,7 +289,7 @@ public: * The timer is not yet active, it has to be started with \c start. * \param context The thread from which the signal should be emitted. */ - eTimer(eMainloop *context=eApp): context(*context), bActive(false) { } + static eTimer *create(eMainloop *context=eApp) { return new eTimer(context); } ~eTimer() { if (bActive) stop(); } PSignal0<void> timeout; @@ -299,6 +303,7 @@ public: void changeInterval(long msek); void startLongTimer( int seconds ); bool operator<(const eTimer& t) const { return nextActivation < t.nextActivation; } + eSmartPtrList<iObject> m_clients; }; #endif // SWIG |
