summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-05-25 20:08:55 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-05-25 20:08:55 +0000
commit3d6c8488b128e8720e575f9a0a3498e90defcda1 (patch)
tree28a01631569b5ddffbe680adbf8cd60ab75b90ed
parentadc5782b96fd64e40bb619e364bde8dd5d20ca57 (diff)
downloadATCD-3d6c8488b128e8720e575f9a0a3498e90defcda1.tar.gz
*** empty log message ***
-rw-r--r--ChangeLog-97a17
-rw-r--r--ace/Handle_Set.cpp111
-rw-r--r--ace/Handle_Set.h41
-rw-r--r--ace/Handle_Set.i111
-rw-r--r--ace/OS.h8
-rw-r--r--ace/Reactor.cpp49
-rw-r--r--examples/Reactor/Misc/Makefile15
-rw-r--r--examples/Reactor/Misc/test_handle_set.cpp73
-rw-r--r--tests/Handle_Set_Test.cpp112
9 files changed, 289 insertions, 248 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a
index 864c60d7f1d..f719636b751 100644
--- a/ChangeLog-97a
+++ b/ChangeLog-97a
@@ -1,5 +1,22 @@
Sun May 25 11:36:22 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu>
+ * examples/Reactor/Misc: Removed test_handle_set.cpp since it
+ is now completed subsumed by tests/Handle_Set_Test.cpp.
+
+ * tests/Handle_Set_Test.cpp: Updated the test of
+ the ACE_Handle_Set so that it shows how fast the iterator works.
+
+ * ace/Reactor.cpp: Updated the Reactor to use the new
+ ACE_Handle_Set_Iterator (whic no longer requires calling
+ operator++ to advance the iterator).
+
+ * ace/Handle_Set: Rewrote the ACE_Handle_Set_Iterator to speed it up.
+ The result seems to be about 15% faster than the original.
+
+ * ace/OS.h: Changed the MSB_MASK static constant into a macro and
+ moved it from Handle_Set.cpp into OS.h, changing its name to
+ ACE_MSB_MASK.
+
* ace/Sched_Params.cpp (priority_max): Added another #ifdef for
Chorus. Thanks to Wei Chiang for reporting this.
diff --git a/ace/Handle_Set.cpp b/ace/Handle_Set.cpp
index 0648a515032..b09333d144e 100644
--- a/ace/Handle_Set.cpp
+++ b/ace/Handle_Set.cpp
@@ -17,9 +17,9 @@ ACE_Handle_Set::dump (void) const
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, "[ "));
- ACE_DEBUG ((LM_DEBUG, "size_ = %d", this->size_));
+ ACE_DEBUG ((LM_DEBUG, "\nsize_ = %d", this->size_));
ACE_DEBUG ((LM_DEBUG, "\nmax_handle_ = %d", this->max_handle_));
+ ACE_DEBUG ((LM_DEBUG, "\n[ "));
#if defined (ACE_WIN32)
for (size_t i = 0; i < this->mask_.fd_count + 1; i++)
@@ -30,17 +30,10 @@ ACE_Handle_Set::dump (void) const
ACE_DEBUG ((LM_DEBUG, " %d ", i));
#endif /* ACE_WIN32 */
- ACE_DEBUG ((LM_DEBUG, " ]"));
+ ACE_DEBUG ((LM_DEBUG, " ]\n"));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-#if defined (ACE_HAS_BROKEN_BITSHIFT)
-static const ACE_UINT32 MSB_MASK = ~(ACE_UINT32 (1) << ACE_UINT32 (NFDBITS - 1));
-#else
-// This needs to go here to avoid overflow problems on some compilers.
-static const ACE_UINT32 MSB_MASK = ~(1 << (NFDBITS - 1));
-#endif /* ACE_HAS_BROKEN_BITSHIFT */
-
// Table that maps bytes to counts of the enabled bits.
const char ACE_Handle_Set::nbits_[256] =
@@ -86,11 +79,13 @@ ACE_Handle_Set::ACE_Handle_Set (const ACE_FD_SET_TYPE &fd_mask)
// speed up the count.
int
-ACE_Handle_Set::count_bits (unsigned long n) const
+ACE_Handle_Set::count_bits (u_long n) const
{
ACE_TRACE ("ACE_Handle_Set::count_bits");
- return (ACE_Handle_Set::nbits_[n & 0xff] + ACE_Handle_Set::nbits_[(n >> 8) & 0xff] +
- ACE_Handle_Set::nbits_[(n >> 16) & 0xff] + ACE_Handle_Set::nbits_[n >> 24]);
+ return (ACE_Handle_Set::nbits_[n & 0xff]
+ + ACE_Handle_Set::nbits_[(n >> 8) & 0xff]
+ + ACE_Handle_Set::nbits_[(n >> 16) & 0xff]
+ + ACE_Handle_Set::nbits_[n >> 24]);
}
// Synchronize the underlying FD_SET with the MAX_FD and the SIZE.
@@ -100,16 +95,16 @@ ACE_Handle_Set::sync (ACE_HANDLE max)
{
ACE_TRACE ("ACE_Handle_Set::sync");
#if !defined(ACE_WIN32)
- this->size_ = 0;
+ this->size_ = 0;
- for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE;
- i >= 0;
- i--)
- this->size_ += count_bits (this->mask_.fds_bits[i]);
+ for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE;
+ i >= 0;
+ i--)
+ this->size_ += count_bits (this->mask_.fds_bits[i]);
- this->set_max (max);
+ this->set_max (max);
#else
- ACE_UNUSED_ARG (max);
+ ACE_UNUSED_ARG (max);
#endif /* !ACE_WIN32 */
}
@@ -120,9 +115,8 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
{
ACE_TRACE ("ACE_Handle_Set::set_max");
#if !defined(ACE_WIN32)
-
if (this->size_ == 0)
- this->max_handle_ = -1;
+ this->max_handle_ = ACE_INVALID_HANDLE;
else
{
int i;
@@ -133,9 +127,10 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
continue;
this->max_handle_ = i * ACE_Handle_Set::WORDSIZE;
+
for (fd_mask val = this->mask_.fds_bits[i];
- (val & ~1) != 0;
- val = (val >> 1) & MSB_MASK)
+ (val & ~1) != 0; // This obscure code is needed since "bit 0" is in location 1...
+ val = (val >> 1) & ACE_MSB_MASK)
this->max_handle_++;
}
@@ -143,7 +138,7 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
if (this->max_handle_ >= ACE_Handle_Set::MAXSIZE)
this->max_handle_ = ACE_Handle_Set::MAXSIZE - 1;
#else
- ACE_UNUSED_ARG(current_max);
+ ACE_UNUSED_ARG (current_max);
#endif /* !ACE_WIN32 */
}
@@ -155,69 +150,7 @@ ACE_Handle_Set_Iterator::dump (void) const
ACE_TRACE ("ACE_Handle_Set_Iterator::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, "num_ = %d", this->num_));
- ACE_DEBUG ((LM_DEBUG, "\nindex_ = %d", this->index_));
+ ACE_DEBUG ((LM_DEBUG, "\nhandle_index_ = %d", this->handle_index_));
+ ACE_DEBUG ((LM_DEBUG, "\nword_num_ = %d", this->word_num_));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-
-void
-ACE_Handle_Set_Iterator::operator++ (void)
-{
- ACE_TRACE ("ACE_Handle_Set_Iterator::operator++");
-
-#if defined(ACE_WIN32)
- this->index_++;
-#else /* !ACE_WIN32 */
- this->val_ = (this->val_ >> 1) & MSB_MASK;
- this->num_++;
-
-
- if (this->val_ == 0)
- {
- for (this->index_++;
- this->index_ < ACE_Handle_Set::NUM_WORDS
- && this->handles_.mask_.fds_bits[this->index_] == 0;
- this->index_++)
- continue;
-
- if (this->index_ >= ACE_Handle_Set::NUM_WORDS)
- {
- this->num_ = this->handles_.max_handle_ + 1;
- return;
- }
- else
- {
- this->val_ = this->handles_.mask_.fds_bits[this->index_];
- this->num_ = this->index_ * ACE_Handle_Set::WORDSIZE;
- }
- }
-
- for (; ACE_BIT_DISABLED (this->val_, 1); this->num_++)
- this->val_ = (this->val_ >> 1) & MSB_MASK;
-#endif /* !ACE_WIN32 */
-}
-
-ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &f)
- : handles_ (f),
- num_ (0),
- index_ (0)
-{
- ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
-#if !defined(ACE_WIN32)
- // Loop until we've found the first non-zero bit or we run off the
- // end of the bitset.
- for (;
- this->num_ < ACE_Handle_Set::MAXSIZE
- && this->handles_.mask_.fds_bits[this->index_] == 0;
- this->index_++)
- this->num_ += ACE_Handle_Set::WORDSIZE;
-
- if (this->num_ >= ACE_Handle_Set::MAXSIZE)
- this->num_ = this->handles_.max_handle_ + 1;
- else
- for (this->val_ = this->handles_.mask_.fds_bits[this->index_];
- (ACE_BIT_DISABLED (this->val_, 1)) && this->num_ < ACE_Handle_Set::MAXSIZE;
- this->num_++)
- this->val_ = (this->val_ >> 1) & MSB_MASK;
-#endif /* !ACE_WIN32 */
-}
diff --git a/ace/Handle_Set.h b/ace/Handle_Set.h
index ef01db484e6..3be77f18371 100644
--- a/ace/Handle_Set.h
+++ b/ace/Handle_Set.h
@@ -19,16 +19,6 @@
#include "ace/ACE.h"
-// This wrapper design is not very portable to DEC OSF/1 I had to
-// redefine NFDBITS to 32. On OSF/1 NFDBITS is a macro that expands to
-// (sizeof(fd_mask)*8) which is 4096 by default. This was an
-// inappropriate value for defining the MSB_MASK default value. Any
-// ideas? The workaround is a pretty severe restriction for OSF/1.
-// DJT
-// #if defined (__osf__)
-// #define NFDBITS 32
-// #endif
-
class ACE_Export ACE_Handle_Set
{
// = TITLE
@@ -81,7 +71,7 @@ public:
private:
int size_;
- // Size of the set.
+ // Size of the set, i.e., a count of the number of enabled bits.
ACE_HANDLE max_handle_;
// Current max handle.
@@ -98,7 +88,7 @@ private:
NBITS = 256
};
- int count_bits (unsigned long n) const;
+ int count_bits (u_long n) const;
// Counts the number of bits enabled in N. Uses a table lookup to
// speed up the count.
@@ -111,17 +101,22 @@ private:
class ACE_Export ACE_Handle_Set_Iterator
// = TITLE
- // Iterator for the ACE_Handle_Set abstraction.
+ // Iterator for the <ACE_Handle_Set> abstraction.
{
public:
- ACE_Handle_Set_Iterator (const ACE_Handle_Set &);
+ ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs);
// Constructor.
- ACE_HANDLE operator ()(void);
- // "Next" operator.
+ ACE_HANDLE operator () (void);
+ // "Next" operator. Returns the next unseen <ACE_HANDLE> in the
+ // <Handle_Set> up to <handle_set_.max_handle_>). When all the
+ // handles have been seen returns <ACE_INVALID_HANDLE>. Advances
+ // the iterator automatically, so you need not call <operator++>
+ // (which is now obsolete).
void operator++ (void);
- // Advance by "one."
+ // This is a no-op and no longer does anything. It's only here for
+ // backwards compatibility.
void dump (void) const;
// Dump the state of an object.
@@ -133,16 +128,16 @@ private:
const ACE_Handle_Set &handles_;
// The <Handle_Set> we are iterating through.
- int num_;
- // Number of the word we're iterating on.
+ int handle_index_;
+ // Index of the bit we're examining in the current <word_num_> word.
- size_t index_;
- // Index of the current <num_> word.
+ int word_num_;
+ // Number of the word we're iterating over (typically between 0..7).
#if !defined (ACE_WIN32)
- fd_mask val_;
-#endif /* ACE_WIN32 */
+ fd_mask word_val_;
// Value of the bits in the word we're iterating on.
+#endif /* ACE_WIN32 */
};
#if defined (__ACE_INLINE__)
diff --git a/ace/Handle_Set.i b/ace/Handle_Set.i
index d7577404ea3..db3d7ccb446 100644
--- a/ace/Handle_Set.i
+++ b/ace/Handle_Set.i
@@ -41,7 +41,7 @@ ACE_Handle_Set::set_bit (ACE_HANDLE handle)
if (!this->is_set (handle))
{
#if defined(ACE_WIN32)
- FD_SET ((SOCKET)handle, &this->mask_);
+ FD_SET ((SOCKET) handle, &this->mask_);
#else /* !ACE_WIN32 */
FD_SET (handle, &this->mask_);
this->size_++;
@@ -77,7 +77,7 @@ ACE_INLINE int
ACE_Handle_Set::num_set (void) const
{
ACE_TRACE ("ACE_Handle_Set::num_set");
-#if defined(ACE_WIN32)
+#if defined (ACE_WIN32)
return this->mask_.fd_count;
#else /* !ACE_WIN32 */
return this->size_;
@@ -97,11 +97,108 @@ ACE_INLINE ACE_HANDLE
ACE_Handle_Set_Iterator::operator () (void)
{
ACE_TRACE ("ACE_Handle_Set_Iterator::operator");
-#if defined(ACE_WIN32)
- return this->index_ < this->handles_.mask_.fd_count
- ? (ACE_HANDLE)this->handles_.mask_.fd_array[this->index_]
- : ACE_INVALID_HANDLE;
+#if defined (ACE_WIN32)
+ if (this->handle_index_ < this->handles_.mask_.fd_count)
+ // Return the handle and advance the iterator.
+ return (ACE_HANDLE) this->handles_.mask_.fd_array[this->handle_index_++];
+ else
+ return ACE_INVALID_HANDLE;
+
#else /* !ACE_WIN32 */
- return this->num_ <= this->handles_.max_handle_ ? this->num_ : -1;
+ // No sense searching further than the max_handle_ + 1;
+ ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
+
+ if (this->handle_index_ >= maxhandlep1)
+ // We've seen all the handles we're interested in seeing for this
+ // iterator.
+ return ACE_INVALID_HANDLE;
+ else
+ {
+ ACE_HANDLE result = this->handle_index_;
+
+ // Increment the iterator.
+ this->handle_index_++;
+ this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
+
+ // If've examined all the bits in this word, we'll go onto the
+ // next word.
+
+ if (this->word_val_ == 0)
+ {
+ // Loop until we've found the first non-zero bit or we run
+ // past the <maxhandlep1> of the bitset.
+ while (this->handle_index_ < maxhandlep1
+ && this->handles_.mask_.fds_bits[++this->word_num_] == 0)
+ this->handle_index_ += ACE_Handle_Set::WORDSIZE;
+
+ // If the bit index becomes >= the maxhandlep1 that means
+ // there weren't any more bits set that we want to consider.
+ // Therefore, we'll just store the maxhandlep1, which will
+ // cause <operator()> to return <ACE_INVALID_HANDLE>
+ // immediately next time it's called.
+ if (this->handle_index_ >= maxhandlep1)
+ {
+ this->handle_index_ = maxhandlep1;
+ return result;
+ }
+ else
+ // Load the bits of the next word.
+ this->word_val_ = this->handles_.mask_.fds_bits[this->word_num_];
+ }
+
+ // Loop until we get <word_val_> to have its least significant
+ // bit enabled, keeping track of which <handle_index> this
+ // represents (this information is used by subsequent calls to
+ // <operator()>).
+
+ for (;
+ ACE_BIT_DISABLED (this->word_val_, 1);
+ this->handle_index_++)
+ this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
+
+ return result;
#endif /* ACE_WIN32 */
+ }
+}
+
+ACE_INLINE void
+ACE_Handle_Set_Iterator::operator++ (void)
+{
+ ACE_TRACE ("ACE_Handle_Set_Iterator::operator++");
+
+ // This is now a no-op.
+}
+
+ACE_INLINE
+ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
+ : handles_ (hs),
+ handle_index_ (0),
+ word_num_ (-1)
+{
+ ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
+#if !defined(ACE_WIN32)
+ // No sense searching further than the max_handle_ + 1;
+ ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
+
+ // Loop until we've found the first non-zero bit or we run past the
+ // <maxhandlep1> of the bitset.
+ while (this->handle_index_ < maxhandlep1
+ && this->handles_.mask_.fds_bits[++this->word_num_] == 0)
+ this->handle_index_ += ACE_Handle_Set::WORDSIZE;
+
+ // If the bit index becomes >= the maxhandlep1 that means there weren't
+ // any bits set. Therefore, we'll just store the maxhandlep1, which will
+ // cause <operator()> to return <ACE_INVALID_HANDLE> immediately.
+ if (this->handle_index_ >= maxhandlep1)
+ this->handle_index_ = maxhandlep1;
+ else
+ // Loop until we get <word_val_> to have its least significant bit
+ // enabled, keeping track of which <handle_index> this represents
+ // (this information is used by <operator()>).
+ for (this->word_val_ = this->handles_.mask_.fds_bits[this->word_num_];
+ ACE_BIT_DISABLED (this->word_val_, 1)
+ && this->handle_index_ < maxhandlep1;
+ this->handle_index_++)
+ this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
+#endif /* !ACE_WIN32 */
}
diff --git a/ace/OS.h b/ace/OS.h
index 27de30f71f5..d9645985ef4 100644
--- a/ace/OS.h
+++ b/ace/OS.h
@@ -190,7 +190,6 @@ private:
#define ACE_MAX(x,y) (((x)>(y))?(x):(y))
#define ACE_MIN(x,y) (((x)<(y))?(x):(y))
-
// keep the compiler from complaining of
// parameters which are not used.
#if defined (ghs)
@@ -2573,6 +2572,13 @@ struct ACE_Export ACE_Str_Buf : public strbuf
// Constructor.
};
+#if defined (ACE_HAS_BROKEN_BITSHIFT)
+#define ACE_MSB_MASK (~(ACE_UINT32 (1) << ACE_UINT32 (NFDBITS - 1)))
+#else
+// This needs to go here to avoid overflow problems on some compilers.
+#define ACE_MSB_MASK (~(1 << (NFDBITS - 1)))
+#endif /* ACE_HAS_BROKEN_BITSHIFT */
+
class ACE_Export ACE_OS
// = TITLE
// This class defines an operating system independent
diff --git a/ace/Reactor.cpp b/ace/Reactor.cpp
index 2373f5fa0c6..0ccb58321c6 100644
--- a/ace/Reactor.cpp
+++ b/ace/Reactor.cpp
@@ -1031,9 +1031,9 @@ ACE_Reactor::remove_handler_i (const ACE_Handle_Set &handles,
ACE_TRACE ("ACE_Reactor::remove_handler_i");
ACE_HANDLE h;
- for (ACE_Handle_Set_Iterator handle_iter (handles);
- (h = handle_iter ()) != ACE_INVALID_HANDLE;
- ++handle_iter)
+ ACE_Handle_Set_Iterator handle_iter (handles);
+
+ while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
if (this->remove_handler_i (h, mask) == -1)
return -1;
@@ -1048,9 +1048,8 @@ ACE_Reactor::register_handler_i (const ACE_Handle_Set &handles,
ACE_TRACE ("ACE_Reactor::register_handler_i");
ACE_HANDLE h;
- for (ACE_Handle_Set_Iterator handle_iter (handles);
- (h = handle_iter ()) != ACE_INVALID_HANDLE;
- ++handle_iter)
+ ACE_Handle_Set_Iterator handle_iter (handles);
+ while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
if (this->register_handler_i (h, handler, mask) == -1)
return -1;
@@ -1427,16 +1426,15 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles,
{
ACE_HANDLE handle;
- // Handle output events (this code needs to come first
- // to handle the obscure case of piggy-backed data
- // coming along with the final handshake message of a
- // nonblocking connection).
+ // Handle output events (this code needs to come first to handle
+ // the obscure case of piggy-backed data coming along with the
+ // final handshake message of a nonblocking connection).
+
+ ACE_Handle_Set_Iterator handle_iter_wr (dispatch_set.wr_mask_);
- for (ACE_Handle_Set_Iterator handle_iter_wr (dispatch_set.wr_mask_);
- (handle = handle_iter_wr ()) != ACE_INVALID_HANDLE
+ while ((handle = handle_iter_wr ()) != ACE_INVALID_HANDLE
&& number_dispatched < number_of_active_handles
- && this->state_changed_ == 0;
- ++handle_iter_wr)
+ && this->state_changed_ == 0)
{
number_dispatched++;
this->notify_handle (handle,
@@ -1461,11 +1459,12 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles,
ACE_HANDLE handle;
// Handle "exceptional" events.
- for (ACE_Handle_Set_Iterator handle_iter_ex (dispatch_set.ex_mask_);
- (handle = handle_iter_ex ()) != ACE_INVALID_HANDLE
+
+ ACE_Handle_Set_Iterator handle_iter_ex (dispatch_set.ex_mask_);
+
+ while ((handle = handle_iter_ex ()) != ACE_INVALID_HANDLE
&& number_dispatched < number_of_active_handles
- && this->state_changed_ == 0;
- ++handle_iter_ex)
+ && this->state_changed_ == 0)
{
this->notify_handle (handle,
ACE_Event_Handler::EXCEPT_MASK,
@@ -1475,6 +1474,7 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles,
number_dispatched++;
}
}
+
if (number_dispatched > 0)
{
number_of_active_handles -= number_dispatched;
@@ -1489,11 +1489,12 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles,
ACE_HANDLE handle;
// Handle input, passive connection, and shutdown events.
- for (ACE_Handle_Set_Iterator handle_iter_rd (dispatch_set.rd_mask_);
- (handle = handle_iter_rd ()) != ACE_INVALID_HANDLE
+
+ ACE_Handle_Set_Iterator handle_iter_rd (dispatch_set.rd_mask_);
+
+ while ((handle = handle_iter_rd ()) != ACE_INVALID_HANDLE
&& number_dispatched < number_of_active_handles
- && this->state_changed_ == 0;
- ++handle_iter_rd)
+ && this->state_changed_ == 0)
{
this->notify_handle (handle,
ACE_Event_Handler::READ_MASK,
@@ -1503,9 +1504,11 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles,
number_dispatched++;
}
}
+
if (number_dispatched > 0)
{
number_of_active_handles -= number_dispatched;
+
if (this->state_changed_)
return -1;
}
@@ -1569,7 +1572,7 @@ ACE_Reactor::dispatch (int number_of_active_handles,
break; // State has changed, exit inner loop.
else if (this->dispatch_io_handlers
(number_of_active_handles, dispatch_set) == -1)
- // State has changed exit inner loop.
+ // State has changed, so exit the inner loop.
break;
}
diff --git a/examples/Reactor/Misc/Makefile b/examples/Reactor/Misc/Makefile
index 07a7e1a548a..21e1a449821 100644
--- a/examples/Reactor/Misc/Makefile
+++ b/examples/Reactor/Misc/Makefile
@@ -12,7 +12,6 @@ BIN = pingpong \
notification \
test_demuxing \
test_event_handler_t \
- test_handle_set \
test_reactors \
test_signals_1 \
test_signals_2 \
@@ -293,20 +292,6 @@ include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU
$(WRAPPER_ROOT)/ace/Log_Record.i \
$(WRAPPER_ROOT)/ace/ACE.i \
$(WRAPPER_ROOT)/ace/Event_Handler.i
-.obj/test_handle_set.o .shobj/test_handle_set.so: test_handle_set.cpp \
- $(WRAPPER_ROOT)/ace/Handle_Set.h \
- $(WRAPPER_ROOT)/ace/ACE.h \
- $(WRAPPER_ROOT)/ace/OS.h \
- $(WRAPPER_ROOT)/ace/config.h \
- $(WRAPPER_ROOT)/ace/stdcpp.h \
- $(WRAPPER_ROOT)/ace/OS.i \
- $(WRAPPER_ROOT)/ace/Trace.h \
- $(WRAPPER_ROOT)/ace/Log_Msg.h \
- $(WRAPPER_ROOT)/ace/Log_Record.h \
- $(WRAPPER_ROOT)/ace/Log_Priority.h \
- $(WRAPPER_ROOT)/ace/Log_Record.i \
- $(WRAPPER_ROOT)/ace/ACE.i \
- $(WRAPPER_ROOT)/ace/Handle_Set.i
.obj/test_reactors.o .shobj/test_reactors.so: test_reactors.cpp \
$(WRAPPER_ROOT)/ace/Reactor.h \
$(WRAPPER_ROOT)/ace/Handle_Set.h \
diff --git a/examples/Reactor/Misc/test_handle_set.cpp b/examples/Reactor/Misc/test_handle_set.cpp
deleted file mode 100644
index cfd4791f6e8..00000000000
--- a/examples/Reactor/Misc/test_handle_set.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-
-// $Id$
-
-#include "ace/Handle_Set.h"
-
-void
-test1 (int count)
-{
- int duplicates = 0;
- int sets = 0;
- int clears = 0;
-
- ACE_Handle_Set handle_set;
-
- ACE_OS::srand (ACE_OS::time (0L));
-
- for (int j = 0; j < count; j++)
- {
- int i = int (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE);
-
- if (ACE_ODD (i))
- {
- if (handle_set.is_set (i))
- duplicates++;
-
- handle_set.set_bit (i);
- sets++;
- }
- else
- {
- if (handle_set.is_set (i))
- duplicates--;
-
- handle_set.clr_bit (i);
- clears++;
- }
- }
-
- ACE_DEBUG ((LM_DEBUG, "count = %d, set_size = %d, duplicates = %d\n",
- count, handle_set.num_set (), (sets - clears) == duplicates));
-}
-
-void
-test2 (void)
-{
- ACE_Handle_Set handle_set;
- ACE_HANDLE handle;
-
- handle_set.set_bit (0);
- handle_set.set_bit (1);
- handle_set.set_bit (32);
- handle_set.set_bit (63);
- handle_set.set_bit (64);
- handle_set.set_bit (65);
- handle_set.set_bit (122);
- handle_set.set_bit (129);
- handle_set.set_bit (245);
- handle_set.set_bit (255);
-
- for (ACE_Handle_Set_Iterator fi (handle_set);
- (handle = fi ()) != -1;
- ++fi)
- ACE_DEBUG ((LM_DEBUG, "handle = %d\n", handle));
-}
-
-int
-main (int argc, char *argv[])
-{
- int count = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_Handle_Set::MAXSIZE;
- test1 (count);
- test2 ();
-}
-
diff --git a/tests/Handle_Set_Test.cpp b/tests/Handle_Set_Test.cpp
index d8803dfb137..b3d1c5f2b69 100644
--- a/tests/Handle_Set_Test.cpp
+++ b/tests/Handle_Set_Test.cpp
@@ -18,50 +18,123 @@
//
// ============================================================================
-
+#include "ace/Profile_Timer.h"
#include "ace/Handle_Set.h"
#include "test_config.h"
-#define IS_ODD(X) (((X) & 1) != 0)
-
static void
-run_test (int count)
+test_duplicates (size_t count)
{
- int duplicates = 0;
- int sets = 0;
- int clears = 0;
+ size_t duplicates = 0;
+ size_t sets = 0;
+ size_t clears = 0;
ACE_Handle_Set handle_set;
ACE_OS::srand (ACE_OS::time (0L));
- for (int i = 0; i < count; i++)
+ for (size_t i = 0; i < count; i++)
{
- int j = int (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE);
+ size_t handle = size_t (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE);
- if (IS_ODD (j))
+ if (ACE_ODD (handle))
{
- if (handle_set.is_set ((ACE_HANDLE) j))
+ if (handle_set.is_set ((ACE_HANDLE) handle))
duplicates++;
- handle_set.set_bit ((ACE_HANDLE) j);
+ handle_set.set_bit ((ACE_HANDLE) handle);
sets++;
}
else
{
- if (handle_set.is_set ((ACE_HANDLE) j))
+ if (handle_set.is_set ((ACE_HANDLE) handle))
duplicates--;
- handle_set.clr_bit ((ACE_HANDLE) j);
+ handle_set.clr_bit ((ACE_HANDLE) handle);
clears++;
}
}
ACE_ASSERT (count == sets + clears);
ACE_ASSERT (handle_set.num_set () + duplicates == sets);
+}
+
+static void
+test_boundaries (void)
+{
+ ACE_Handle_Set handle_set;
+
+ ACE_HANDLE handle;
+
+ // First test an empty set.
-// ACE_DEBUG ((LM_DEBUG, "count = %d, set_size = %d, duplicates = %d\n",
-// count, handle_set.num_set (), (sets - clears) == duplicates));
+ ACE_Handle_Set_Iterator i1 (handle_set);
+
+ while ((handle = i1 ()) != ACE_INVALID_HANDLE)
+ ACE_ASSERT (!"this shouldn't get called since the set is empty!\n");
+
+ // Insert a bunch of HANDLEs into the set, testing for boundary
+ // conditions.
+
+ handle_set.set_bit ((ACE_HANDLE) 0);
+ handle_set.set_bit ((ACE_HANDLE) 1);
+ handle_set.set_bit ((ACE_HANDLE) 32);
+ handle_set.set_bit ((ACE_HANDLE) 63);
+ handle_set.set_bit ((ACE_HANDLE) 64);
+ handle_set.set_bit ((ACE_HANDLE) 65);
+ handle_set.set_bit ((ACE_HANDLE) 127);
+ handle_set.set_bit ((ACE_HANDLE) 128);
+ handle_set.set_bit ((ACE_HANDLE) 129);
+ handle_set.set_bit ((ACE_HANDLE) 255);
+
+ size_t count = 0;
+
+ ACE_Handle_Set_Iterator i2 (handle_set);
+
+ while ((handle = i2 ()) != ACE_INVALID_HANDLE)
+ count++;
+
+ ACE_ASSERT (count == handle_set.num_set ());
+}
+
+static void
+test_performance (size_t max_handles,
+ size_t max_iterations)
+{
+ ACE_Handle_Set handle_set;
+ size_t i;
+
+ for (i = 0; i < max_handles; i++)
+ handle_set.set_bit ((ACE_HANDLE) i);
+
+ ACE_Profile_Timer timer;
+ ACE_HANDLE handle;
+ size_t count = 0;
+
+ timer.start ();
+
+ for (i = 0; i < max_iterations; i++)
+ {
+ ACE_Handle_Set_Iterator iter (handle_set);
+
+ // Only iterate up to <handle_set.max_set ()>.
+ while ((handle = iter ()) != ACE_INVALID_HANDLE)
+ count++;
+ }
+
+ timer.stop ();
+
+ ACE_ASSERT (count == max_handles * max_iterations);
+
+ ACE_Profile_Timer::ACE_Elapsed_Time et;
+
+ timer.elapsed_time (et);
+
+ 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 each of the %d calls = %f usecs\n",
+ count, (et.real_time / double (count)) * 1000000));
}
int
@@ -70,7 +143,12 @@ main (int argc, char *argv[])
ACE_START_TEST ("Handle_Set_Test");
int count = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_Handle_Set::MAXSIZE;
- run_test (count);
+ size_t max_handles = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_Handle_Set::MAXSIZE;
+ size_t max_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : ACE_MAX_ITERATIONS;
+
+ test_duplicates (count);
+ test_boundaries ();
+ test_performance (max_handles, max_iterations);
ACE_END_TEST;
return 0;