diff options
-rw-r--r-- | ChangeLog-97b | 20 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | ace/Handle_Set.cpp | 141 | ||||
-rw-r--r-- | ace/Handle_Set.h | 33 | ||||
-rw-r--r-- | ace/Handle_Set.i | 68 | ||||
-rw-r--r-- | ace/Reactor.cpp | 4 | ||||
-rw-r--r-- | examples/Threads/process_manager.cpp | 12 |
7 files changed, 219 insertions, 61 deletions
diff --git a/ChangeLog-97b b/ChangeLog-97b index 6abfb887e91..aaf25cd674d 100644 --- a/ChangeLog-97b +++ b/ChangeLog-97b @@ -1,13 +1,10 @@ -Fri Sep 05 16:17:50 1997 David L. Levine <levine@cs.wustl.edu> - - * performance-tests/Misc/preempt.cpp: added command line options, - and explanation on how to interpret the results. - -Fri Sep 05 15:04:40 1997 Douglas C. Schmidt <schmidt@cs.wustl.edu> - - * ACE version 4.3.4, released Fri Sep 05 15:04:40 1997. +Fri Sep 5 19:05:02 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> -Fri Sep 5 14:51:56 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> + * ace/Reactor.cpp (check_handles): When handle_error was optimized + with fstat we put NULL value to second argument. It requires a + value to SCO OpenServer to work. Therefore, I added struct stat + temp and changed ACE_OS::fstat(handle, NULL) by + ACE_OS::fstat(handle, &temp); Thanks to Arturo for fixing this. * examples/Threads/process_manager.cpp (sig_handler): Fixed a bug where the thread was exiting if no more children existed. @@ -43,6 +40,11 @@ Fri Sep 5 14:51:56 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> 0. Thanks to fixing this codeKaren Amestoy <kamestoy@CCGATE.HAC.COM> for reporting this fix. +Fri Sep 05 16:17:50 1997 David L. Levine <levine@cs.wustl.edu> + + * performance-tests/Misc/preempt.cpp: added command line options, + and explanation on how to interpret the results. + Thu Sep 04 10:26:11 1997 David L. Levine <levine@cs.wustl.edu> * ace/OS.cpp: (tss_open): removed paren from around type in "new" @@ -1,4 +1,4 @@ -This is ACE version 4.3.4, released Fri Sep 05 15:04:40 1997. +This is ACE version 4.3.3, released Fri Sep 05 15:04:40 1997. If you have any problems with ACE, please send email to Douglas C. Schmidt (schmidt@cs.wustl.edu). 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, diff --git a/examples/Threads/process_manager.cpp b/examples/Threads/process_manager.cpp index 2b003820c52..3209ff0cc6a 100644 --- a/examples/Threads/process_manager.cpp +++ b/examples/Threads/process_manager.cpp @@ -46,14 +46,10 @@ sig_handler (void *) { pid_t pid = proc_mgr.reap (); - switch (pid) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "reap"), 0); - /* NOTREACHED */ - default: - ACE_DEBUG ((LM_DEBUG, "(%P|%t) reaped pid %d\n", pid)); - } + if (pid == -1) // No more children to reap. + break; + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) reaped pid %d\n", pid)); } /* NOTREACHED */ |