summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-09-06 00:51:23 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-09-06 00:51:23 +0000
commit65a0647219dfe8dd20d06b1716a848516be540a6 (patch)
tree01a1797d6968059d75ff164298bde3d833dbc6b8 /ace
parent89e75446daa50f690451c5424d73253c107cfe75 (diff)
downloadATCD-65a0647219dfe8dd20d06b1716a848516be540a6.tar.gz
*** empty log message ***
Diffstat (limited to 'ace')
-rw-r--r--ace/Handle_Set.cpp141
-rw-r--r--ace/Handle_Set.h33
-rw-r--r--ace/Handle_Set.i68
-rw-r--r--ace/Reactor.cpp4
4 files changed, 203 insertions, 43 deletions
diff --git a/ace/Handle_Set.cpp b/ace/Handle_Set.cpp
index 5c13041b6e5..b19fd306ff4 100644
--- a/ace/Handle_Set.cpp
+++ b/ace/Handle_Set.cpp
@@ -73,6 +73,9 @@ ACE_Handle_Set::ACE_Handle_Set (const ACE_FD_SET_TYPE &fd_mask)
sizeof this->mask_);
#if !defined (ACE_WIN32)
this->sync (ACE_Handle_Set::MAXSIZE);
+#if defined (ACE_HAS_BIG_FD_SET)
+ this->min_handle_ = 0;
+#endif /* ACE_HAS_BIG_FD_SET */
#endif /* !ACE_WIN32 */
}
@@ -80,7 +83,7 @@ ACE_Handle_Set::ACE_Handle_Set (const ACE_FD_SET_TYPE &fd_mask)
// speed up the count.
int
-ACE_Handle_Set::count_bits (u_long n) const
+ACE_Handle_Set::count_bits (u_long n)
{
ACE_TRACE ("ACE_Handle_Set::count_bits");
@@ -104,6 +107,41 @@ ACE_Handle_Set::count_bits (u_long n) const
#endif /* ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT */
}
+#if defined (ACE_HAS_BIG_FD_SET)
+// Find the bit position counting from right to left worst case
+// (1<<31) is 8.
+
+int
+ACE_Handle_Set::bitpos (u_long bit)
+{
+ register int l = 0;
+ register u_long n = bit - 1;
+
+ // This is a fast count method when have the most significative bit.
+
+ while (n >> 8)
+ {
+ n >>= 8;
+ l += 8;
+ }
+
+ // Is greater than 15?
+ if (n & 16)
+ {
+ n >>= 4;
+ l += 4;
+ }
+
+ // Count number remaining bits.
+ while (n != 0)
+ {
+ n &= n - 1;
+ l++;
+ }
+ return l;
+}
+#endif /* ACE_HAS_BIG_FD_SET */
+
// Synchronize the underlying FD_SET with the MAX_FD and the SIZE.
void
@@ -116,7 +154,7 @@ ACE_Handle_Set::sync (ACE_HANDLE max)
for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE;
i >= 0;
i--)
- this->size_ += count_bits (this->mask_.fds_bits[i]);
+ this->size_ += ACE_Handle_Set::count_bits (this->mask_.fds_bits[i]);
this->set_max (max);
#else
@@ -142,12 +180,17 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
i--)
continue;
+#if 1 /* !defined(ACE_HAS_BIG_FD_SET) */
this->max_handle_ = i * ACE_Handle_Set::WORDSIZE;
-
for (fd_mask val = this->mask_.fds_bits[i];
(val & ~1) != 0; // This obscure code is needed since "bit 0" is in location 1...
val = (val >> 1) & ACE_MSB_MASK)
this->max_handle_++;
+#else
+ register u_long val = this->mask_.fds_bits[i];
+ this->max_handle_ = i * ACE_Handle_Set::WORDSIZE
+ + ACE_Handle_Set::bitpos(val & ~(val - 1));
+#endif /* 1 */
}
// Do some sanity checking...
@@ -166,7 +209,12 @@ ACE_Handle_Set_Iterator::dump (void) const
ACE_TRACE ("ACE_Handle_Set_Iterator::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+#if defined(ACE_WIN32) || !defined(ACE_HAS_BIG_FD_SET)
ACE_DEBUG ((LM_DEBUG, "\nhandle_index_ = %d", this->handle_index_));
+#elif defined(ACE_HAS_BIG_FD_SET)
+ ACE_DEBUG ((LM_DEBUG, "\nword_max_ = %d", this->word_max_));
+ ACE_DEBUG ((LM_DEBUG, "\nword_val_ = %d", this->word_val_));
+#endif
ACE_DEBUG ((LM_DEBUG, "\nword_num_ = %d", this->word_num_));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
@@ -182,7 +230,7 @@ ACE_Handle_Set_Iterator::operator () (void)
else
return ACE_INVALID_HANDLE;
-#else /* !ACE_WIN32 */
+#elif !defined (ACE_HAS_BIG_FD_SET) /* !ACE_WIN32 */
// No sense searching further than the max_handle_ + 1;
ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
@@ -241,6 +289,63 @@ ACE_Handle_Set_Iterator::operator () (void)
return result;
}
+#else /* !ACE_HAS_BIG_FD_SET */
+ // Find the first word in fds_bits with bit on
+ register u_long lsb = this->word_val_;
+
+ if (lsb == 0)
+ {
+ do
+ {
+ // We have exceeded the word count in Handle_Set?
+ if (++this->word_num_ >= this->word_max_)
+ return ACE_INVALID_HANDLE;
+
+ lsb = this->handles_.mask_.fds_bits[this->word_num_];
+ }
+ while (lsb == 0);
+
+ // Set index to word boundary.
+ this->handle_index_ = this->word_num_ * ACE_Handle_Set::WORDSIZE;
+
+ // Put new word_val.
+ this->word_val_ = lsb;
+
+ // Find the least significative bit.
+ lsb &= ~(lsb - 1);
+
+ // Remove least significative bit.
+ this->word_val_ ^= lsb;
+
+ // Save to calculate bit distance.
+ this->oldlsb_ = lsb;
+
+ // Move index to least significative bit.
+ while (lsb >>= 1)
+ this->handle_index_++;
+ }
+ else
+ {
+ // Find the least significative bit.
+ lsb &= ~(lsb - 1);
+
+ // Remove least significative bit.
+ this->word_val_ ^= lsb;
+
+ register u_long n = lsb - this->oldlsb_;
+
+ // Move index to bit distance between new lsb and old lsb.
+ do
+ {
+ this->handle_index_++;
+ n &= n >> 1;
+ }
+ while (n != 0);
+
+ this->oldlsb_ = lsb;
+ }
+
+ return this->handle_index_;
#endif /* ACE_WIN32 */
}
@@ -254,11 +359,17 @@ ACE_Handle_Set_Iterator::operator++ (void)
ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
: handles_ (hs),
+#if !defined (ACE_HAS_BIG_FD_SET) || defined (ACE_WIN32)
handle_index_ (0),
word_num_ (-1)
+#elif defined (ACE_HAS_BIG_FD_SET)
+ oldlsb_ (0),
+ word_max_ (hs.max_handle_ == ACE_INVALID_HANDLE
+ ? 0 : ((hs.max_handle_ / ACE_Handle_Set::WORDSIZE) + 1))
+#endif /* ACE_HAS_BIG_FD_SET */
{
ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
-#if !defined(ACE_WIN32)
+#if !defined(ACE_WIN32) && !defined(ACE_HAS_BIG_FD_SET)
// No sense searching further than the max_handle_ + 1;
ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
@@ -268,9 +379,10 @@ ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
&& 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 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
@@ -282,5 +394,16 @@ ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
&& this->handle_index_ < maxhandlep1;
this->handle_index_++)
this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
-#endif /* !ACE_WIN32 */
+#elif !defined(ACE_WIN32) && defined(ACE_HAS_BIG_FD_SET)
+ if (this->word_max_==0)
+ {
+ this->word_num_ = -1;
+ this->word_val_ = 0;
+ }
+ else
+ {
+ this->word_num_ = this->handles_.min_handle_ / ACE_Handle_Set::WORDSIZE - 1;
+ this->word_val_ = 0;
+ }
+#endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */
}
diff --git a/ace/Handle_Set.h b/ace/Handle_Set.h
index 4cffdfe2afb..376c37fed64 100644
--- a/ace/Handle_Set.h
+++ b/ace/Handle_Set.h
@@ -64,10 +64,10 @@ public:
// Returns a pointer to the underlying <fd_set>. Returns 0 if
// <size_> == 0.
-#if 0
+#if defined(ACE_HAS_BIG_FD_SET)
void operator= (const ACE_Handle_Set &);
// Assignment operator optimizes for cases where <size_> == 0.
-#endif /* 0 */
+#endif
void dump (void) const;
// Dump the state of an object.
@@ -82,6 +82,11 @@ private:
ACE_HANDLE max_handle_;
// Current max handle.
+#if defined(ACE_HAS_BIG_FD_SET)
+ ACE_HANDLE min_handle_;
+ // Current min handle.
+#endif
+
fd_set mask_;
// Bitmask.
@@ -94,10 +99,15 @@ private:
NBITS = 256
};
- int count_bits (u_long n) const;
+ static int count_bits (u_long n);
// Counts the number of bits enabled in N. Uses a table lookup to
// speed up the count.
+#if defined(ACE_HAS_BIG_FD_SET)
+ static int bitpos (u_long bit);
+ // Find the bitpos in bit counting of right to left.
+#endif
+
void set_max (ACE_HANDLE max);
// Resets the MAX_FD after a clear of the original MAX_FD.
@@ -136,18 +146,29 @@ private:
#if defined (ACE_WIN32)
u_int handle_index_;
-#else
+#elif !defined(ACE_HAS_BIG_FD_SET)
int handle_index_;
+#elif defined(ACE_HAS_BIG_FD_SET)
+ int handle_index_;
+ u_long oldlsb_;
#endif /* ACE_WIN32 */
// Index of the bit we're examining in the current <word_num_> word.
int word_num_;
// Number of the word we're iterating over (typically between 0..7).
-#if !defined (ACE_WIN32)
+#if defined(ACE_HAS_BIG_FD_SET)
+ int word_max_;
+ // Number max of the words with a possible bit on.
+#endif
+
+#if !defined (ACE_WIN32) && !defined(ACE_HAS_BIG_FD_SET)
fd_mask word_val_;
// Value of the bits in the word we're iterating on.
-#endif /* ACE_WIN32 */
+#elif !defined (ACE_WIN32) && defined(ACE_HAS_BIG_FD_SET)
+ u_long word_val_;
+ // Value of the bits in the word we're iterating on.
+#endif /* ACE_WIN32 && ACE_HAS_BIG_FD_SET */
};
#if defined (__ACE_INLINE__)
diff --git a/ace/Handle_Set.i b/ace/Handle_Set.i
index 0dea91af06e..023f3a44a1b 100644
--- a/ace/Handle_Set.i
+++ b/ace/Handle_Set.i
@@ -3,36 +3,39 @@
// Handle_Set.i
-#if 0
+// Initialize the bitmask to all 0s and reset the associated fields.
+
ACE_INLINE void
-ACE_Handle_Set::operator= (const ACE_Handle_Set &rhs)
+ACE_Handle_Set::reset (void)
{
ACE_TRACE ("ACE_Handle_Set::reset");
+ this->max_handle_ = ACE_INVALID_HANDLE;
+#if defined (ACE_HAS_BIG_FD_SET)
+ this->min_handle_ = NUM_WORDS * WORDSIZE;
+#endif
+ this->size_ = 0;
+#if !defined (ACE_HAS_BIG_FD_SET)
+ FD_ZERO (&this->mask_);
+#endif /* ACE_HAS_BIG_FD_SET */
+}
- this->size_ = rhs.size_;
+#if defined (ACE_HAS_BIG_FD_SET)
+ACE_INLINE void
+ACE_Handle_Set::operator= (const ACE_Handle_Set &rhs)
+{
+ ACE_TRACE ("ACE_Handle_Set::reset");
- if (this->size_ > 0)
+ if (rhs.size_ > 0)
{
+ this->size_ = rhs.size_;
this->max_handle_ = rhs.max_handle_;
+ this->min_handle_ = rhs.min_handle_;
this->mask_ = rhs.mask_;
}
else
- {
- FD_ZERO (&this->mask_);
- this->max_handle_ = ACE_INVALID_HANDLE;
- }
-}
-#endif /* 0 */
-// Initialize the bitmask to all 0s and reset the associated fields.
-
-ACE_INLINE void
-ACE_Handle_Set::reset (void)
-{
- ACE_TRACE ("ACE_Handle_Set::reset");
- this->max_handle_ = ACE_INVALID_HANDLE;
- this->size_ = 0;
- FD_ZERO (&this->mask_);
+ this->reset ();
}
+#endif /* ACE_HAS_BIG_FD_SET */
// Returns the number of the large bit.
@@ -49,7 +52,11 @@ ACE_INLINE int
ACE_Handle_Set::is_set (ACE_HANDLE handle) const
{
ACE_TRACE ("ACE_Handle_Set::is_set");
+#if defined (ACE_HAS_BIG_FD_SET)
+ return FD_ISSET (handle, &this->mask_) && size_ > 0;
+#else
return FD_ISSET (handle, &this->mask_);
+#endif /* ACE_HAS_BIG_FD_SET */
}
// Enables the handle.
@@ -60,13 +67,23 @@ ACE_Handle_Set::set_bit (ACE_HANDLE handle)
ACE_TRACE ("ACE_Handle_Set::set_bit");
if (!this->is_set (handle))
{
-#if defined(ACE_WIN32)
+#if defined (ACE_WIN32)
FD_SET ((SOCKET) handle, &this->mask_);
#else /* !ACE_WIN32 */
- FD_SET (handle, &this->mask_);
+#if defined (ACE_HAS_BIG_FD_SET)
+ if (this->size_++ == 0)
+ FD_ZERO(&this->mask_);
+#else /* ACE_HAS_BIG_FD_SET */
this->size_++;
+#endif
+ FD_SET (handle, &this->mask_);
+
if (handle > this->max_handle_)
this->max_handle_ = handle;
+#if defined (ACE_HAS_BIG_FD_SET)
+ if (handle < this->min_handle_)
+ this->min_handle_ = handle;
+#endif /* ACE_HAS_BIG_FD_SET */
#endif /* ACE_WIN32 */
}
}
@@ -77,10 +94,11 @@ ACE_INLINE void
ACE_Handle_Set::clr_bit (ACE_HANDLE handle)
{
ACE_TRACE ("ACE_Handle_Set::clr_bit");
+
if (this->is_set (handle))
{
-#if defined(ACE_WIN32)
- FD_CLR ((SOCKET)handle, &this->mask_);
+#if defined (ACE_WIN32)
+ FD_CLR ((SOCKET) handle, &this->mask_);
#else /* !ACE_WIN32 */
FD_CLR (handle, &this->mask_);
this->size_--;
@@ -111,13 +129,9 @@ ACE_Handle_Set::operator fd_set *()
{
ACE_TRACE ("ACE_Handle_Set::operator ACE_FD_SET_TYPE *");
-#if defined (ACE_WIN32)
- return (fd_set*) &this->mask_;
-#else
if (this->size_ > 0)
return (fd_set*) &this->mask_;
else
return (fd_set*) NULL;
-#endif /* ACE_WIN32 */
}
diff --git a/ace/Reactor.cpp b/ace/Reactor.cpp
index 02b5a93a9ff..0ac7c9b8b3d 100644
--- a/ace/Reactor.cpp
+++ b/ace/Reactor.cpp
@@ -1813,7 +1813,9 @@ ACE_Reactor::check_handles (void)
}
rd_mask.clr_bit (handle);
#else /* !ACE_WIN32 */
- if (ACE_OS::fstat (handle, 0) == -1)
+ struct stat &temp;
+
+ if (ACE_OS::fstat (handle, &temp) == -1)
{
result = 1;
this->remove_handler_i (handle,