summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog-97a7
-rw-r--r--ace/Timer_Heap.cpp2
-rw-r--r--ace/Timer_List.cpp2
-rw-r--r--tests/Timer_Queue_Test.cpp75
4 files changed, 66 insertions, 20 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a
index 37014f40f40..cf415a17cab 100644
--- a/ChangeLog-97a
+++ b/ChangeLog-97a
@@ -1,5 +1,12 @@
Sun Apr 6 14:16:18 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu>
+ * tests/Timer_Queue_Test.cpp: Added tests to make sure that the
+ new ACE_Timer_Queue::cancel() logic is working correctly. So
+ far, it seems to be fine.
+
+ * ace/Timer_{Heap,List}.cpp (cancel): Changed the comparison for
+ dont_call_handle_close to be correct.
+
* ace/OS.cpp: Deleted a useless return. Thanks to Gonzalo
A. Diethelm <gonzo@ing.puc.cl> for reporting this.
diff --git a/ace/Timer_Heap.cpp b/ace/Timer_Heap.cpp
index 8b8e5735b35..c8b46e963be 100644
--- a/ace/Timer_Heap.cpp
+++ b/ace/Timer_Heap.cpp
@@ -490,7 +490,7 @@ ACE_Timer_Heap::cancel (int timer_id,
{
ACE_Timer_Node *temp = this->remove (timer_node_slot);
- if (dont_call_handle_close)
+ if (dont_call_handle_close == 0)
// Call the close hook.
temp->handler_->handle_close (ACE_INVALID_HANDLE,
ACE_Event_Handler::TIMER_MASK);
diff --git a/ace/Timer_List.cpp b/ace/Timer_List.cpp
index 75459345194..02773ef5019 100644
--- a/ace/Timer_List.cpp
+++ b/ace/Timer_List.cpp
@@ -238,7 +238,7 @@ ACE_Timer_List::cancel (int timer_id,
if (arg != 0)
*arg = curr->arg_;
- if (dont_call_handle_close)
+ if (dont_call_handle_close == 0)
// Call the close hook.
curr->handler_->handle_close (ACE_INVALID_HANDLE,
ACE_Event_Handler::TIMER_MASK);
diff --git a/tests/Timer_Queue_Test.cpp b/tests/Timer_Queue_Test.cpp
index f62a3d676b8..0c58449e7f0 100644
--- a/tests/Timer_Queue_Test.cpp
+++ b/tests/Timer_Queue_Test.cpp
@@ -34,9 +34,12 @@ static int *timer_ids = 0;
class Example_Handler : public ACE_Event_Handler
{
public:
+ Example_Handler (void): close_count_ (0) {}
+
virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask mask)
{
ACE_ASSERT (mask == ACE_Event_Handler::TIMER_MASK);
+ this->close_count_++;
return 0;
}
@@ -49,6 +52,9 @@ public:
else
return 0;
}
+
+ int close_count_;
+ // Keeps track of the number of times that <handle_close> is called.
};
static void
@@ -60,25 +66,44 @@ test_functionality (ACE_Timer_Queue *tq)
ACE_ASSERT (ACE_Time_Value::zero == ACE_Time_Value (0));
int timer_id;
- timer_id = tq->schedule (&eh, (const void *) 1, ACE_OS::gettimeofday ());
+ timer_id = tq->schedule (&eh, (const void *) 1,
+ ACE_OS::gettimeofday ());
ACE_ASSERT (timer_id != -1);
ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
ACE_OS::gettimeofday ()) != -1);
ACE_ASSERT (tq->schedule (&eh, (const void *) 42,
ACE_OS::gettimeofday ()) != -1);
- ACE_ASSERT (tq->cancel (timer_id) == 1);
+ // The following method will trigger a call to <handle_close>.
+ ACE_ASSERT (tq->cancel (timer_id, 0, 0) == 1);
ACE_ASSERT (tq->is_empty () == 0);
ACE_ASSERT (tq->expire () == 2);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 4, ACE_OS::gettimeofday ()) != -1);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 5, ACE_OS::gettimeofday ()) != -1);
- ACE_ASSERT (tq->cancel (&eh) == 2);
+ ACE_ASSERT (tq->schedule (&eh, (const void *) 4,
+ ACE_OS::gettimeofday ()) != -1);
+ ACE_ASSERT (tq->schedule (&eh, (const void *) 5,
+ ACE_OS::gettimeofday ()) != -1);
+
+ // The following method will trigger a call to <handle_close>.
+ ACE_ASSERT (tq->cancel (&eh, 0) == 2);
ACE_ASSERT (tq->is_empty ());
ACE_ASSERT (tq->expire () == 0);
- ACE_ASSERT (tq->schedule (&eh, (const void *) 007, ACE_OS::gettimeofday ()) != -1);
+ ACE_ASSERT (tq->schedule (&eh, (const void *) 007,
+ ACE_OS::gettimeofday ()) != -1);
ACE_ASSERT (tq->expire () == 1);
+
+ timer_id = tq->schedule (&eh, (const void *) 6,
+ ACE_OS::gettimeofday ());
+ ACE_ASSERT (timer_id != -1);
+ ACE_ASSERT (tq->schedule (&eh, (const void *) 7,
+ ACE_OS::gettimeofday ()) != -1);
+
+ // The following method will *not* trigger a call to <handle_close>.
+ ACE_ASSERT (tq->cancel (timer_id) == 1);
+ ACE_ASSERT (tq->cancel (&eh) == 1);
+ ACE_ASSERT (tq->expire () == 0);
+ ACE_ASSERT (eh.close_count_ == 2);
}
static void
@@ -98,7 +123,9 @@ test_performance (ACE_Timer_Queue *tq,
for (i = 0; i < max_iterations; i++)
{
- timer_ids[i] = tq->schedule (&eh, (const void *) 42, ACE_OS::gettimeofday ());
+ timer_ids[i] = tq->schedule (&eh,
+ (const void *) 42,
+ ACE_OS::gettimeofday ());
ACE_ASSERT (timer_ids[i] != -1);
}
@@ -110,11 +137,14 @@ test_performance (ACE_Timer_Queue *tq,
timer.elapsed_time (et);
- ACE_DEBUG ((LM_DEBUG, "time to schedule %d timers for %s\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "time to schedule %d timers for %s\n",
max_iterations, test_name));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "real time = %f secs, user time = %f secs, system time = %f secs\n",
et.real_time, et.user_time, et.system_time));
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "time per call = %f usecs\n",
(et.user_time / double (max_iterations)) * 1000000));
// Test the amount of time required to cancel all the timers. We
@@ -132,11 +162,14 @@ test_performance (ACE_Timer_Queue *tq,
timer.elapsed_time (et);
- ACE_DEBUG ((LM_DEBUG, "time to cancel %d timers for %s\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "time to cancel %d timers for %s\n",
max_iterations, test_name));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "real time = %f secs, user time = %f secs, system time = %f secs\n",
et.real_time, et.user_time, et.system_time));
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "time per call = %f usecs\n",
(et.user_time / double (max_iterations)) * 1000000));
// Test the amount of time required to schedule and expire all the
@@ -145,7 +178,9 @@ test_performance (ACE_Timer_Queue *tq,
timer.start ();
for (i = 0; i < max_iterations; i++)
- ACE_ASSERT (tq->schedule (&eh, (const void *) 42, ACE_OS::gettimeofday ()) != -1);
+ ACE_ASSERT (tq->schedule (&eh,
+ (const void *) 42,
+ ACE_OS::gettimeofday ()) != -1);
ACE_ASSERT (tq->is_empty () == 0);
@@ -156,11 +191,14 @@ test_performance (ACE_Timer_Queue *tq,
timer.elapsed_time (et);
- ACE_DEBUG ((LM_DEBUG, "time to schedule and expire %d timers for %s\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "time to schedule and expire %d timers for %s\n",
max_iterations, test_name));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "real time = %f secs, user time = %f secs, system time = %f secs\n",
et.real_time, et.user_time, et.system_time));
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "time per call = %f usecs\n",
(et.user_time / double (max_iterations)) * 1000000));
}
@@ -209,8 +247,9 @@ main (int argc, char *argv[])
{
ACE_DEBUG ((LM_DEBUG, "**** starting test of %s\n",
timer_queues[i].name_));
- test_performance (timer_queues[i].queue_, timer_queues[i].name_);
test_functionality (timer_queues[i].queue_);
+ test_performance (timer_queues[i].queue_,
+ timer_queues[i].name_);
delete timer_queues[i].queue_;
}