summaryrefslogtreecommitdiff
path: root/ACE/ace/Proactor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/ace/Proactor.cpp')
-rw-r--r--ACE/ace/Proactor.cpp98
1 files changed, 45 insertions, 53 deletions
diff --git a/ACE/ace/Proactor.cpp b/ACE/ace/Proactor.cpp
index 883a567c1fb..b844dd1fe41 100644
--- a/ACE/ace/Proactor.cpp
+++ b/ACE/ace/Proactor.cpp
@@ -63,11 +63,6 @@ bool ACE_Proactor::delete_proactor_ = false;
*/
class ACE_Proactor_Timer_Handler : public ACE_Task<ACE_NULL_SYNCH>
{
-
- /// Proactor has special privileges
- /// Access needed to: timer_event_
- friend class ACE_Proactor;
-
public:
/// Constructor.
ACE_Proactor_Timer_Handler (ACE_Proactor &proactor);
@@ -80,6 +75,11 @@ public:
/// <destroy> does. <destroy> make sure the thread exits properly.
int destroy (void);
+ /// Proactor calls this to refresh the timer event thread, to wake
+ /// up the thread from a sleep. This is needed to make the thread
+ /// recompute its sleep time after changes to the timer queue.
+ int signal (void);
+
protected:
/// Run by a daemon thread to handle deferred processing. In other
/// words, this method will do the waiting on the earliest timer and
@@ -105,6 +105,12 @@ ACE_Proactor_Timer_Handler::ACE_Proactor_Timer_Handler (ACE_Proactor &proactor)
ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler (void)
{
+ this->destroy();
+}
+
+int
+ACE_Proactor_Timer_Handler::destroy (void)
+{
// Mark for closing down.
this->shutting_down_ = 1;
@@ -113,6 +119,13 @@ ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler (void)
// Wait for the Timer Handler thread to exit.
this->wait ();
+ return 0;
+}
+
+int
+ACE_Proactor_Timer_Handler::signal (void)
+{
+ return this->timer_event_.signal ();
}
int
@@ -132,7 +145,7 @@ ACE_Proactor_Timer_Handler::svc (void)
// Get current time from timer queue since we don't know
// which <gettimeofday> was used.
- ACE_Time_Value cur_time = this->proactor_.timer_queue ()->gettimeofday ();
+ ACE_Time_Value cur_time = this->proactor_.timer_queue ()->gettimeofday_abstract ();
// Compare absolute time with curent time received from the
// timer queue.
@@ -177,15 +190,16 @@ ACE_Proactor_Handle_Timeout_Upcall::ACE_Proactor_Handle_Timeout_Upcall (void)
}
int
-ACE_Proactor_Handle_Timeout_Upcall::registration (TIMER_QUEUE &,
- ACE_Handler *,
+ACE_Proactor_Handle_Timeout_Upcall::registration (ACE_Proactor_Timer_Queue &,
+ ACE_Handler * handler,
const void *)
{
+ handler->proactor(proactor_);
return 0;
}
int
-ACE_Proactor_Handle_Timeout_Upcall::preinvoke (TIMER_QUEUE &,
+ACE_Proactor_Handle_Timeout_Upcall::preinvoke (ACE_Proactor_Timer_Queue &,
ACE_Handler *,
const void *,
int,
@@ -196,7 +210,7 @@ ACE_Proactor_Handle_Timeout_Upcall::preinvoke (TIMER_QUEUE &,
}
int
-ACE_Proactor_Handle_Timeout_Upcall::postinvoke (TIMER_QUEUE &,
+ACE_Proactor_Handle_Timeout_Upcall::postinvoke (ACE_Proactor_Timer_Queue &,
ACE_Handler *,
const void *,
int,
@@ -207,7 +221,7 @@ ACE_Proactor_Handle_Timeout_Upcall::postinvoke (TIMER_QUEUE &,
}
int
-ACE_Proactor_Handle_Timeout_Upcall::timeout (TIMER_QUEUE &,
+ACE_Proactor_Handle_Timeout_Upcall::timeout (ACE_Proactor_Timer_Queue &,
ACE_Handler *handler,
const void *act,
int,
@@ -253,7 +267,7 @@ ACE_Proactor_Handle_Timeout_Upcall::timeout (TIMER_QUEUE &,
}
int
-ACE_Proactor_Handle_Timeout_Upcall::cancel_type (TIMER_QUEUE &,
+ACE_Proactor_Handle_Timeout_Upcall::cancel_type (ACE_Proactor_Timer_Queue &,
ACE_Handler *,
int,
int &)
@@ -263,7 +277,7 @@ ACE_Proactor_Handle_Timeout_Upcall::cancel_type (TIMER_QUEUE &,
}
int
-ACE_Proactor_Handle_Timeout_Upcall::cancel_timer (TIMER_QUEUE &,
+ACE_Proactor_Handle_Timeout_Upcall::cancel_timer (ACE_Proactor_Timer_Queue &,
ACE_Handler *,
int,
int)
@@ -273,7 +287,7 @@ ACE_Proactor_Handle_Timeout_Upcall::cancel_timer (TIMER_QUEUE &,
}
int
-ACE_Proactor_Handle_Timeout_Upcall::deletion (TIMER_QUEUE &,
+ACE_Proactor_Handle_Timeout_Upcall::deletion (ACE_Proactor_Timer_Queue &,
ACE_Handler *,
const void *)
{
@@ -300,7 +314,7 @@ ACE_Proactor_Handle_Timeout_Upcall::proactor (ACE_Proactor &proactor)
ACE_Proactor::ACE_Proactor (ACE_Proactor_Impl *implementation,
bool delete_implementation,
- TIMER_QUEUE *tq)
+ ACE_Proactor_Timer_Queue *tq)
: implementation_ (0),
delete_implementation_ (delete_implementation),
timer_handler_ (0),
@@ -670,43 +684,14 @@ ACE_Proactor::schedule_timer (ACE_Handler &handler,
{
// absolute time.
ACE_Time_Value absolute_time =
- this->timer_queue_->gettimeofday () + time;
-
- // Only one guy goes in here at a time
- ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX,
- ace_mon,
- this->timer_queue_->mutex (),
- -1));
-
- // Remember the old proactor.
- ACE_Proactor *old_proactor = handler.proactor ();
-
- // Assign *this* Proactor to the handler.
- handler.proactor (this);
-
- // Schedule the timer
- long result = this->timer_queue_->schedule (&handler,
- act,
- absolute_time,
- interval);
+ this->timer_queue_->gettimeofday_abstract () + time;
+ long result = this->timer_queue_->schedule(&handler, act,
+ absolute_time, interval);
if (result != -1)
{
- // no failures: check to see if we are the earliest time
- if (this->timer_queue_->earliest_time () == absolute_time)
-
- // wake up the timer thread
- if (this->timer_handler_->timer_event_.signal () == -1)
- {
- // Cancel timer
- this->timer_queue_->cancel (result);
- result = -1;
- }
- }
-
- if (result == -1)
- {
- // Reset the old proactor in case of failures.
- handler.proactor (old_proactor);
+ // Signal the timer thread to make sure that new events are
+ // dispatched and the sleep time is updated.
+ (void) this->timer_handler_->signal ();
}
return result;
@@ -770,14 +755,14 @@ ACE_Proactor::number_of_threads (size_t threads)
this->implementation ()->number_of_threads (threads);
}
-ACE_Proactor::TIMER_QUEUE *
+ACE_Proactor_Timer_Queue *
ACE_Proactor::timer_queue (void) const
{
return this->timer_queue_;
}
void
-ACE_Proactor::timer_queue (TIMER_QUEUE *tq)
+ACE_Proactor::timer_queue (ACE_Proactor_Timer_Queue *tq)
{
// Cleanup old timer queue.
if (this->delete_timer_queue_)
@@ -800,7 +785,14 @@ ACE_Proactor::timer_queue (TIMER_QUEUE *tq)
}
// Set the proactor in the timer queue's functor
- this->timer_queue_->upcall_functor ().proactor (*this);
+ typedef ACE_Timer_Queue_Upcall_Base<ACE_Handler*,ACE_Proactor_Handle_Timeout_Upcall> TQ_Base;
+
+ TQ_Base * tqb = ACE_dynamic_cast(TQ_Base*, this->timer_queue_);
+
+ if (tqb != 0)
+ {
+ tqb->upcall_functor ().proactor (*this);
+ }
}
ACE_HANDLE