summaryrefslogtreecommitdiff
path: root/ACE/tests
diff options
context:
space:
mode:
authormcorino <mcorino@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2011-12-15 11:09:41 +0000
committermcorino <mcorino@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2011-12-15 11:09:41 +0000
commit9d1004206324867a4287e99b9675d24e536fa090 (patch)
tree89d59383f294627917ee3cf054f347884a914f32 /ACE/tests
parentb8d69007a4e25977f11cc3de8eb3793c0c61161a (diff)
downloadATCD-9d1004206324867a4287e99b9675d24e536fa090.tar.gz
Thu Dec 15 11:00:00 UTC 2011 Martin Corino <mcorino@remedy.nl>
Merged timer_policy branch.
Diffstat (limited to 'ACE/tests')
-rw-r--r--ACE/tests/Network_Adapters_Test.cpp25
-rw-r--r--ACE/tests/Proactor_Timer_Test.cpp29
-rw-r--r--ACE/tests/Reactor_Timer_Test.cpp27
-rw-r--r--ACE/tests/Timer_Queue_Reference_Counting_Test.cpp34
-rw-r--r--ACE/tests/Timer_Queue_Test.cpp27
5 files changed, 102 insertions, 40 deletions
diff --git a/ACE/tests/Network_Adapters_Test.cpp b/ACE/tests/Network_Adapters_Test.cpp
index 4d5aea82d7b..e00f901078d 100644
--- a/ACE/tests/Network_Adapters_Test.cpp
+++ b/ACE/tests/Network_Adapters_Test.cpp
@@ -28,6 +28,8 @@
#include "ace/Timer_Queue.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_signal.h"
+#include "ace/Timer_Heap.h"
+#include "ace/Auto_Ptr.h"
#include "Network_Adapters_Test.h"
@@ -1035,8 +1037,27 @@ run_main (int argc, ACE_TCHAR *argv[])
ACE_NEW_RETURN (main_reactor, ACE_Reactor, -1);
(void) ACE_High_Res_Timer::global_scale_factor ();
- main_reactor->timer_queue ()->gettimeofday
- (&ACE_High_Res_Timer::gettimeofday_hr);
+
+ // Change the source of time in the reactor to the high-resolution
+ // timer. Why does this test require such precision for a 1 second
+ // timer is beyond me ... I think it is a cut&paste error.
+ //
+ // The use of auto_ptr<> is optional, ACE uses dangerous memory
+ // management idioms everywhere, I thought I could demonstrate how
+ // to do it right in at least one test. Notice the lack of
+ // ACE_NEW_RETURN, that monstrosity has no business in proper C++
+ // code ...
+ auto_ptr<ACE_Timer_Heap_Variable_Time_Source> tq(
+ new ACE_Timer_Heap_Variable_Time_Source);
+ // ... notice how the policy is in the derived timer queue type.
+ // The abstract timer queue does not have a time policy ...
+ tq->set_time_policy(&ACE_High_Res_Timer::gettimeofday_hr);
+ // ... and then the timer queue is replaced. Strangely, the reactor
+ // does *not* copy the timers, it just deletes the existing timer
+ // queue ....
+ main_reactor->timer_queue(tq.get());
+ // ... the reactor has assumed ownership, release the auto_ptr<> ...
+ tq.release();
/**
* Stop_Handler's is supposed to stop the activity of all
diff --git a/ACE/tests/Proactor_Timer_Test.cpp b/ACE/tests/Proactor_Timer_Test.cpp
index d27601bb3ce..86469c4dd40 100644
--- a/ACE/tests/Proactor_Timer_Test.cpp
+++ b/ACE/tests/Proactor_Timer_Test.cpp
@@ -25,10 +25,11 @@
// supporting POSIX aio calls.
#include "ace/OS_NS_unistd.h"
-#include "ace/Timer_Queue.h"
#include "ace/Proactor.h"
#include "ace/High_Res_Timer.h"
#include "ace/Asynch_IO.h"
+#include "ace/Timer_Heap.h"
+#include "ace/Auto_Ptr.h"
static int done = 0;
static size_t counter = 0;
@@ -297,8 +298,32 @@ run_main (int argc, ACE_TCHAR *[])
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Running with high-res timer queue\n")));
ACE_Proactor *r = ACE_Proactor::instance ();
+
(void) ACE_High_Res_Timer::global_scale_factor ();
- r->timer_queue ()->gettimeofday (&ACE_High_Res_Timer::gettimeofday_hr);
+
+ // Change the source of time in the Proactor to the
+ // high-resolution timer. Why does this test require such
+ // precision for a 1 second timer is beyond me ... I think it
+ // is a cut&paste error.
+ //
+ // The use of auto_ptr<> is optional, ACE uses dangerous memory
+ // management idioms everywhere, I thought I could demonstrate how
+ // to do it right in at least one test. Notice the lack of
+ // ACE_NEW_RETURN, that monstrosity has no business in proper C++
+ // code ...
+ typedef ACE_Timer_Heap_T<ACE_Handler*,ACE_Proactor_Handle_Timeout_Upcall,ACE_SYNCH_RECURSIVE_MUTEX,ACE_FPointer_Time_Policy> Timer_Queue;
+
+ auto_ptr<Timer_Queue> tq(new Timer_Queue);
+ // ... notice how the policy is in the derived timer queue type.
+ // The abstract timer queue does not have a time policy ...
+ tq->set_time_policy(&ACE_High_Res_Timer::gettimeofday_hr);
+ // ... and then the timer queue is replaced. Strangely, the
+ // Proactor does *not* copy the timers, it just deletes the
+ // existing timer queue ....
+ r->timer_queue(tq.get());
+ // ... the Proactor has assumed ownership, release the
+ // auto_ptr<> ...
+ tq.release();
}
// Register all different handlers, i.e., one per timer.
diff --git a/ACE/tests/Reactor_Timer_Test.cpp b/ACE/tests/Reactor_Timer_Test.cpp
index f376b51c069..22dfc273b7b 100644
--- a/ACE/tests/Reactor_Timer_Test.cpp
+++ b/ACE/tests/Reactor_Timer_Test.cpp
@@ -23,6 +23,8 @@
#include "ace/Trace.h"
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Log_Msg.h"
+#include "ace/Timer_Heap.h"
+#include "ace/Auto_Ptr.h"
@@ -246,8 +248,31 @@ run_main (int argc, ACE_TCHAR *[])
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Running with high-res timer queue\n")));
ACE_Reactor *r = ACE_Reactor::instance ();
+
(void) ACE_High_Res_Timer::global_scale_factor ();
- r->timer_queue ()->gettimeofday (&ACE_High_Res_Timer::gettimeofday_hr);
+
+ // Change the source of time in the Reactor to the
+ // high-resolution timer. Why does this test require such
+ // precision for a 1 second timer is beyond me ... I think it
+ // is a cut&paste error.
+ //
+ // The use of auto_ptr<> is optional, ACE uses dangerous memory
+ // management idioms everywhere, I thought I could demonstrate how
+ // to do it right in at least one test. Notice the lack of
+ // ACE_NEW_RETURN, that monstrosity has no business in proper C++
+ // code ...
+ auto_ptr<ACE_Timer_Heap_Variable_Time_Source> tq(
+ new ACE_Timer_Heap_Variable_Time_Source);
+ // ... notice how the policy is in the derived timer queue type.
+ // The abstract timer queue does not have a time policy ...
+ tq->set_time_policy(&ACE_High_Res_Timer::gettimeofday_hr);
+ // ... and then the timer queue is replaced. Strangely, the
+ // Reactor does *not* copy the timers, it just deletes the
+ // existing timer queue ....
+ r->timer_queue(tq.get());
+ // ... the Reactor has assumed ownership, release the
+ // auto_ptr<> ...
+ tq.release();
}
// Register all different handlers, i.e., one per timer.
diff --git a/ACE/tests/Timer_Queue_Reference_Counting_Test.cpp b/ACE/tests/Timer_Queue_Reference_Counting_Test.cpp
index 400a8711b1c..43bd43b0c73 100644
--- a/ACE/tests/Timer_Queue_Reference_Counting_Test.cpp
+++ b/ACE/tests/Timer_Queue_Reference_Counting_Test.cpp
@@ -263,38 +263,8 @@ invoke_expire (ACE_Timer_Queue &timer_queue)
int
invoke_one_upcall (ACE_Timer_Queue &timer_queue)
{
- // Get the current time
- ACE_Time_Value current_time (timer_queue.gettimeofday () +
- timer_queue.timer_skew ());
-
- // Look for a node in the timer queue whose timer <= the present
- // time.
- ACE_Timer_Node_Dispatch_Info dispatch_info;
-
- if (timer_queue.dispatch_info (current_time,
- dispatch_info))
- {
- const void *upcall_act = 0;
-
- // Preinvoke.
- timer_queue.preinvoke (dispatch_info,
- current_time,
- upcall_act);
-
- // Call the functor
- timer_queue.upcall (dispatch_info,
- current_time);
-
- // Postinvoke
- timer_queue.postinvoke (dispatch_info,
- current_time,
- upcall_act);
-
- // We have dispatched a timer
- return 1;
- }
-
- return 0;
+ ACE_Noop_Command command;
+ return timer_queue.expire_single(command);
}
void
diff --git a/ACE/tests/Timer_Queue_Test.cpp b/ACE/tests/Timer_Queue_Test.cpp
index 209ea014356..bd8837fb6f1 100644
--- a/ACE/tests/Timer_Queue_Test.cpp
+++ b/ACE/tests/Timer_Queue_Test.cpp
@@ -29,10 +29,12 @@
#include "ace/Timer_Wheel.h"
#include "ace/Timer_Hash.h"
#include "ace/Timer_Queue.h"
+#include "ace/Time_Policy.h"
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Null_Mutex.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Containers_T.h"
+#include "ace/Event_Handler.h"
@@ -326,7 +328,10 @@ test_performance (ACE_Timer_Queue *tq,
// Set up a bunch of times TIMER_DISTANCE ms apart.
for (i = 0; i < max_iterations; ++i)
- times[i] = tq->gettimeofday() + ACE_Time_Value(0, i * TIMER_DISTANCE * 1000);
+ {
+ times[i] = (tq->gettimeofday()
+ + ACE_Time_Value(0, i * TIMER_DISTANCE * 1000));
+ }
ACE_Time_Value last_time = times[max_iterations-1];
@@ -674,15 +679,31 @@ run_main (int argc, ACE_TCHAR *argv[])
-1);
// Timer_Heap without preallocated memory, using high-res time.
+ // @deprecated
(void) ACE_High_Res_Timer::global_scale_factor ();
- ACE_Timer_Heap *tq_heap = new ACE_Timer_Heap;
- tq_heap->gettimeofday (&ACE_High_Res_Timer::gettimeofday_hr);
+
+ ACE_Timer_Heap *tq_heap =
+ new ACE_Timer_Heap;
+ tq_heap->gettimeofday(&ACE_High_Res_Timer::gettimeofday_hr);
ACE_NEW_RETURN (tq_stack,
Timer_Queue_Stack (tq_heap,
+ ACE_TEXT ("ACE_Timer_Heap (high-res timer; deprecated version)"),
+ tq_stack),
+ -1);
+
+ // new (optimized) version
+ typedef ACE_Timer_Heap_T<ACE_Event_Handler *,
+ ACE_Event_Handler_Handle_Timeout_Upcall,
+ ACE_SYNCH_RECURSIVE_MUTEX,
+ ACE_HR_Time_Policy>
+ timer_heap_hr_type;
+ ACE_NEW_RETURN (tq_stack,
+ Timer_Queue_Stack (new timer_heap_hr_type,
ACE_TEXT ("ACE_Timer_Heap (high-res timer)"),
tq_stack),
-1);
+
// Create the Timer ID array
ACE_NEW_RETURN (timer_ids,
long[max_iterations],