summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Cleeland <chris.cleeland@gmail.com>1997-11-13 08:17:38 +0000
committerChris Cleeland <chris.cleeland@gmail.com>1997-11-13 08:17:38 +0000
commit8879226c8d04d00e28fe9a15bb4c4e740b2c8bf8 (patch)
tree7e5203725cbd2943127f0ea2af48429712372ce8
parent2ca0cfef04028544ccf7e2149c6d7152e5dd37d7 (diff)
downloadATCD-8879226c8d04d00e28fe9a15bb4c4e740b2c8bf8.tar.gz
* ace/Signal.i: Changed to use new Object Manager member.
* ace/Object_Manager.cpp: Added a new member to the Object Manager--default_mask. This is the default signal mask employed by ACE_Sig_Set. Moving the object into the OM saves cycles b/c we only construct it once and just re-use every time. * ace/Handle_Set.cpp: Added two new macros--ACE_DIV_BY_WORDSIZE and ACE_MULT_BY_WORDSIZE--which either divide or multiply the argument by ACE_Handle_Set::WORDSIZE. The manner in which this is accomplished is governed by the #define ACE_USE_SHIFT_FOR_EFFICIENCY--when defined, ACE tries to use shifts to implement multiplication and division rather than actual multiply and divide operations. Currently this is disabled.
-rw-r--r--ace/Handle_Set.cpp28
-rw-r--r--ace/Object_Manager.cpp8
-rw-r--r--ace/Object_Manager.h7
-rw-r--r--ace/Object_Manager.i8
-rw-r--r--ace/Signal.i8
5 files changed, 49 insertions, 10 deletions
diff --git a/ace/Handle_Set.cpp b/ace/Handle_Set.cpp
index b19fd306ff4..b888b01db52 100644
--- a/ace/Handle_Set.cpp
+++ b/ace/Handle_Set.cpp
@@ -144,6 +144,18 @@ ACE_Handle_Set::bitpos (u_long bit)
// Synchronize the underlying FD_SET with the MAX_FD and the SIZE.
+#if defined(ACE_USE_SHIFT_FOR_EFFICIENCY)
+// These don't work because shifting right 3 bits is not the same as
+// dividing by 3, e.g., dividing by 8 requires shifting right 3 bits.
+// In order to do the shift, we need to calculate the number of bits
+// at some point.
+#define ACE_DIV_BY_WORDSIZE(x) ( (x) >> (ACE_Handle_Set::WORDSIZE) )
+#define ACE_MULT_BY_WORDSIZE(x) ( (x) << (ACE_Handle_Set::WORDSIZE) )
+#else
+#define ACE_DIV_BY_WORDSIZE(x) ( (x) / (ACE_Handle_Set::WORDSIZE) )
+#define ACE_MULT_BY_WORDSIZE(x) ( (x) * (ACE_Handle_Set::WORDSIZE) )
+#endif /* ACE_USE_SHIFT_FOR_DIVIDE */
+
void
ACE_Handle_Set::sync (ACE_HANDLE max)
{
@@ -151,7 +163,7 @@ ACE_Handle_Set::sync (ACE_HANDLE max)
#if !defined (ACE_WIN32)
this->size_ = 0;
- for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE;
+ for (int i = ACE_DIV_BY_WORDSIZE(max - 1);
i >= 0;
i--)
this->size_ += ACE_Handle_Set::count_bits (this->mask_.fds_bits[i]);
@@ -175,20 +187,20 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
{
int i;
- for (i = (current_max - 1) / ACE_Handle_Set::WORDSIZE;
+ for (i = ACE_DIV_BY_WORDSIZE(current_max - 1);
this->mask_.fds_bits[i] == 0;
i--)
continue;
#if 1 /* !defined(ACE_HAS_BIG_FD_SET) */
- this->max_handle_ = i * ACE_Handle_Set::WORDSIZE;
+ this->max_handle_ = ACE_MULT_BY_WORDSIZE(i);
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
+ this->max_handle_ = ACE_MULT_BY_WORDSIZE(i)
+ ACE_Handle_Set::bitpos(val & ~(val - 1));
#endif /* 1 */
}
@@ -256,7 +268,7 @@ ACE_Handle_Set_Iterator::operator () (void)
// and then loop until we've found the first non-zero bit or
// we run past the <maxhandlep1> of the bitset.
- for (this->handle_index_ = ++this->word_num_ * ACE_Handle_Set::WORDSIZE;
+ for (this->handle_index_ = ACE_MULT_BY_WORDSIZE(++this->word_num_);
this->handle_index_ < maxhandlep1
&& this->handles_.mask_.fds_bits[this->word_num_] == 0;
this->word_num_++)
@@ -306,7 +318,7 @@ ACE_Handle_Set_Iterator::operator () (void)
while (lsb == 0);
// Set index to word boundary.
- this->handle_index_ = this->word_num_ * ACE_Handle_Set::WORDSIZE;
+ this->handle_index_ = ACE_MULT_BY_WORDSIZE(this->word_num_);
// Put new word_val.
this->word_val_ = lsb;
@@ -365,7 +377,7 @@ ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
#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))
+ ? 0 : ((ACE_DIV_BY_WORDSIZE(hs.max_handle_)) + 1))
#endif /* ACE_HAS_BIG_FD_SET */
{
ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
@@ -402,7 +414,7 @@ ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
}
else
{
- this->word_num_ = this->handles_.min_handle_ / ACE_Handle_Set::WORDSIZE - 1;
+ this->word_num_ = ACE_DIV_BY_WORDSIZE(this->handles_.min_handle_) - 1;
this->word_val_ = 0;
}
#endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */
diff --git a/ace/Object_Manager.cpp b/ace/Object_Manager.cpp
index 095f9600e75..2df057ef17c 100644
--- a/ace/Object_Manager.cpp
+++ b/ace/Object_Manager.cpp
@@ -13,6 +13,7 @@
#include "ace/Array.h"
#include "ace/Synch.h"
#include "ace/Malloc.h"
+#include "ace/Signal.h"
#if !defined (__ACE_INLINE__)
#include "ace/Object_Manager.i"
@@ -40,6 +41,7 @@ ACE_Object_Manager *ACE_Object_Manager::instance_ = 0;
int ACE_Object_Manager::starting_up_ = 1;
int ACE_Object_Manager::shutting_down_ = 0;
+ACE_Sig_Set *ACE_Object_Manager::default_mask_p_ = 0;
void *ACE_Object_Manager::managed_object[ACE_MAX_MANAGED_OBJECTS] = { 0 };
@@ -212,6 +214,9 @@ ACE_Object_Manager::ACE_Object_Manager (void)
// Finally, indicate that the ACE_Object_Manager instance has been
// constructed.
ACE_Object_Manager::starting_up_ = 0;
+
+ ACE_NEW (ACE_Object_Manager::default_mask_p_,
+ ACE_Sig_Set(1));
}
ACE_Object_Manager *
@@ -714,6 +719,9 @@ ACE_Object_Manager::~ACE_Object_Manager (void)
#if defined (ACE_HAS_THREADS)
ACE_Static_Object_Lock::cleanup_lock ();
#endif /* ACE_HAS_THREADS */
+
+ delete default_mask_p_;
+ default_mask_p_ = 0;
}
#if !defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER)
diff --git a/ace/Object_Manager.h b/ace/Object_Manager.h
index 44119760aaf..20f726a51e9 100644
--- a/ace/Object_Manager.h
+++ b/ace/Object_Manager.h
@@ -26,6 +26,7 @@
class ACE_Recursive_Thread_Mutex;
class ACE_RW_Thread_Mutex;
#endif /* ACE_MT_SAFE */
+class ACE_Sig_Set;
// Forward declaration.
template <class T> class ACE_Unbounded_Queue;
@@ -275,6 +276,9 @@ public:
// construction of <ACE_Singletons>. Returns 0, and the lock in the
// argument, on success; returns -1 on failure.
+ static ACE_Sig_Set &default_mask (void);
+ // Accesses a default signal set used in ACE_Sig_Guard methods.
+
private:
#endif /* ACE_MT_SAFE */
@@ -295,6 +299,9 @@ private:
static int shutting_down_;
// Flag indicating whether the program is shutting down.
+ static ACE_Sig_Set *default_mask_p_;
+ // Default signal set used in ACE_Sig_Guard.
+
public:
// For internal use only by ACE_Managed_Objects.
diff --git a/ace/Object_Manager.i b/ace/Object_Manager.i
index def4ecb385a..9238a7f0f10 100644
--- a/ace/Object_Manager.i
+++ b/ace/Object_Manager.i
@@ -23,3 +23,11 @@ ACE_Object_Manager::at_exit (void *object,
cleanup_hook,
param);
}
+
+ACE_INLINE
+ACE_Sig_Set &
+ACE_Object_Manager::default_mask (void)
+{
+ return *ACE_Object_Manager::default_mask_p_;
+}
+
diff --git a/ace/Signal.i b/ace/Signal.i
index 9e00f3e8a49..ed39ddaa810 100644
--- a/ace/Signal.i
+++ b/ace/Signal.i
@@ -2,6 +2,7 @@
// $Id$
// Signal.i
+#include "ace/Object_Manager.h"
ACE_INLINE
ACE_Sig_Set::ACE_Sig_Set (sigset_t *ss)
@@ -225,13 +226,16 @@ ACE_Sig_Guard::ACE_Sig_Guard (ACE_Sig_Set *mask)
// If MASK is 0 then block all signals!
if (mask == 0)
{
+#if 0
ACE_Sig_Set smask (1);
+#endif
+
#if defined (ACE_LACKS_PTHREAD_THR_SIGSETMASK)
- ACE_OS::sigprocmask (SIG_BLOCK, (sigset_t *) smask, (sigset_t *)
+ ACE_OS::sigprocmask (SIG_BLOCK, (sigset_t *) ACE_Object_Manager::default_mask (), (sigset_t *)
this->omask_);
#else
- ACE_OS::thr_sigsetmask (SIG_BLOCK, (sigset_t *) smask, (sigset_t *)
+ ACE_OS::thr_sigsetmask (SIG_BLOCK, (sigset_t *) ACE_Object_Manager::default_mask (), (sigset_t *)
this->omask_);
#endif /* ACE_LACKS_PTHREAD_THR_SIGSETMASK */
}