diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2002-04-15 14:22:33 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2002-04-15 14:22:33 +0000 |
commit | 764685255923a2b7a10011f5be8794dbb920dc12 (patch) | |
tree | 4055746a03f351d0d8ff1ef6cafee64dc1a53a65 /ace | |
parent | 009461faeb99a6d6ca50f20381738fc9f989072e (diff) | |
download | ATCD-764685255923a2b7a10011f5be8794dbb920dc12.tar.gz |
ChangeLogTag: Mon Apr 15 16:19:12 2002 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Timer_Queue_Adapters.cpp | 32 | ||||
-rw-r--r-- | ace/Timer_Queue_Adapters.h | 26 | ||||
-rw-r--r-- | ace/Timer_Queue_Adapters.i | 18 |
3 files changed, 64 insertions, 12 deletions
diff --git a/ace/Timer_Queue_Adapters.cpp b/ace/Timer_Queue_Adapters.cpp index 709137bdb70..30e159d63e2 100644 --- a/ace/Timer_Queue_Adapters.cpp +++ b/ace/Timer_Queue_Adapters.cpp @@ -147,12 +147,32 @@ ACE_Async_Timer_Queue_Adapter<TQ>::handle_signal (int signum, } template<class TQ> -ACE_Thread_Timer_Queue_Adapter<TQ>::ACE_Thread_Timer_Queue_Adapter (ACE_Thread_Manager *tm) +ACE_Thread_Timer_Queue_Adapter<TQ>::ACE_Thread_Timer_Queue_Adapter (ACE_Thread_Manager *tm, + TQ* timer_queue) : ACE_Task_Base (tm), + timer_queue_(timer_queue), + delete_timer_queue_(0), condition_ (mutex_), active_ (1), // Assume that we start in active mode. thr_id_ (ACE_OS::NULL_thread) { + if (timer_queue_ == 0) + { + ACE_NEW (this->timer_queue_, + TQ); + this->delete_timer_queue_ = 1; + } +} + +template<class TQ> +ACE_Thread_Timer_Queue_Adapter<TQ>::~ACE_Thread_Timer_Queue_Adapter (void) +{ + if (this->delete_timer_queue_) + { + delete this->timer_queue_; + this->timer_queue_ = 0; + this->delete_timer_queue_ = 0; + } } template<class TQ> ACE_SYNCH_MUTEX & @@ -170,7 +190,7 @@ ACE_Thread_Timer_Queue_Adapter<TQ>::schedule { ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1); - long result = this->timer_queue_.schedule (handler, act, future_time, interval); + long result = this->timer_queue_->schedule (handler, act, future_time, interval); this->condition_.signal (); return result; } @@ -181,7 +201,7 @@ ACE_Thread_Timer_Queue_Adapter<TQ>::cancel (long timer_id, { ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1); - int result = this->timer_queue_.cancel (timer_id, act); + int result = this->timer_queue_->cancel (timer_id, act); condition_.signal (); return result; } @@ -229,13 +249,13 @@ ACE_Thread_Timer_Queue_Adapter<TQ>::svc (void) # endif /* ACE_HAS_DEFERRED_TIMER_COMMANDS */ // If the queue is empty, sleep until there is a change on it. - if (this->timer_queue_.is_empty ()) + if (this->timer_queue_->is_empty ()) this->condition_.wait (); else { // Compute the remaining time, being careful not to sleep // for "negative" amounts of time. - ACE_Time_Value tv = this->timer_queue_.earliest_time (); + ACE_Time_Value tv = this->timer_queue_->earliest_time (); // ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("waiting until %u.%3.3u secs\n"), // tv.sec(), tv.msec())); @@ -243,7 +263,7 @@ ACE_Thread_Timer_Queue_Adapter<TQ>::svc (void) } // Expire timers anyway, at worst this is a no-op. - this->timer_queue_.expire (); + this->timer_queue_->expire (); } // Thread cancellation point, if ACE supports it. diff --git a/ace/Timer_Queue_Adapters.h b/ace/Timer_Queue_Adapters.h index d5272731a07..74d9de810ce 100644 --- a/ace/Timer_Queue_Adapters.h +++ b/ace/Timer_Queue_Adapters.h @@ -117,8 +117,13 @@ public: # endif /* ACE_HAS_DEFERRED_TIMER_COMMANDS */ /// Creates the timer queue. Activation of the task is the user's - /// responsibility. - ACE_Thread_Timer_Queue_Adapter (ACE_Thread_Manager * = ACE_Thread_Manager::instance ()); + /// responsibility. Optionally a pointer to a timer queue can be passed, + /// when no pointer is passed, a TQ is dynamically created + ACE_Thread_Timer_Queue_Adapter (ACE_Thread_Manager * = ACE_Thread_Manager::instance (), + TQ* timer_queue = 0); + + /// Destructor. + virtual ~ACE_Thread_Timer_Queue_Adapter (void); /// Schedule the timer according to the semantics of the <TQ>; wakes /// up the dispatching thread. @@ -140,11 +145,18 @@ public: /// Access the locking mechanism, useful for iteration. ACE_SYNCH_MUTEX &mutex (void); - /// Access the implementation queue, useful for iteration. + /// @deprecated Access the implementation queue, useful for iteration. + /// Use the method that returns a pointer instead TQ &timer_queue (void); + /// Set a user-specified timer queue. + int timer_queue (TQ *tq); + + /// Return the current <TQ>. + TQ *timer_queue (void) const; + /// Return the thread id of our active object. - ACE_thread_t thr_id (void); + ACE_thread_t thr_id (void) const; /** * We override the default <activate> method so that we can ensure @@ -193,7 +205,11 @@ private: # endif /* ACE_HAS_DEFERRED_TIMER_COMMANDS */ /// The underlying Timer_Queue. - TQ timer_queue_; + TQ* timer_queue_; + + /// Keeps track of whether we should delete the timer queue (if we + /// didn't create it, then we don't delete it). + int delete_timer_queue_; /** * The dispatching thread sleeps on this condition while waiting to diff --git a/ace/Timer_Queue_Adapters.i b/ace/Timer_Queue_Adapters.i index 621c9c08ef8..b8c4c13840d 100644 --- a/ace/Timer_Queue_Adapters.i +++ b/ace/Timer_Queue_Adapters.i @@ -4,11 +4,27 @@ template<class TQ> ACE_INLINE TQ & ACE_Thread_Timer_Queue_Adapter<TQ>::timer_queue (void) { + return *(this->timer_queue_); +} + +template<class TQ> ACE_INLINE TQ * +ACE_Thread_Timer_Queue_Adapter<TQ>::timer_queue (void) const +{ return this->timer_queue_; } +template<class TQ> ACE_INLINE int +ACE_Thread_Timer_Queue_Adapter<TQ>::timer_queue (TQ *tq) +{ + if (this->delete_timer_queue_ != 0) + delete this->timer_queue_; + this->timer_queue_ = tq; + this->delete_timer_queue_ = 0; + return 0; +} + template<class TQ> ACE_INLINE ACE_thread_t -ACE_Thread_Timer_Queue_Adapter<TQ>::thr_id (void) +ACE_Thread_Timer_Queue_Adapter<TQ>::thr_id (void) const { return this->thr_id_; } |