diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 2000-12-07 02:06:01 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 2000-12-07 02:06:01 +0000 |
commit | f03febd5cf4ada5c2bb0603557650682ea330c4f (patch) | |
tree | ad38cdd6b511c41ded2e96f5735a3b9f149ae63d | |
parent | 2fe777e6ef3821f58af74e6a7d61ba4e10b31805 (diff) | |
download | ATCD-f03febd5cf4ada5c2bb0603557650682ea330c4f.tar.gz |
ChangeLogTag:Wed Dec 6 14:29:13 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu>
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 21 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 21 | ||||
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | ace/Auto_Ptr.h | 155 | ||||
-rw-r--r-- | ace/Auto_Ptr.i | 163 | ||||
-rw-r--r-- | ace/Managed_Object.h | 3 | ||||
-rw-r--r-- | examples/Log_Msg/test_log_msg.cpp | 2 | ||||
-rw-r--r-- | tests/Log_Msg_Test.cpp | 2 | ||||
-rwxr-xr-x | tests/run_tests.sh | 40 |
10 files changed, 404 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog index 4bf9f552dc1..912b780dc5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +Wed Dec 6 14:29:13 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> + + * ace/Auto_Ptr.{h,i}: Added a new set of class (ACE_Refcounted_Auto_Ptr_Rep, + ACE_Refcounted_Auto_Ptr) that implements support for a reference + counted auto_ptr. Thanks to Johnny Tucker + <JTucker@infoglide.com> for contributing this. + + * ace/Managed_Object.h: Added ACE_UNIMPLEMENTED_FUNC macros for + copy constructor and assignment operator in class + ACE_Cleanup_Adapter. Thanks to Johnny Willemsen + <johnny.willemsen@meco.nl> for reporting this. + + * tests/run_tests.sh: Prevent null or zero-length string test name from being + passed into the run() function. Thanks to Jon Loeliger + <jloeliger@chiaro.com> for reporting this. + + * tests/Log_Msg_Test.cpp, + * examples/Log_Msg/test_log_msg.cpp (main): + Replaced int with u_long to make compilers happy. Thanks to + Mike Curtis <mccurry@my-deja.com> for pointing this out. + Tue Dec 5 11:45:42 2000 Darrell Brunsch <brunsch@uci.edu> * ace/SSL/SSL_SOCK_Acceptor.cpp: diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 4bf9f552dc1..912b780dc5b 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,24 @@ +Wed Dec 6 14:29:13 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> + + * ace/Auto_Ptr.{h,i}: Added a new set of class (ACE_Refcounted_Auto_Ptr_Rep, + ACE_Refcounted_Auto_Ptr) that implements support for a reference + counted auto_ptr. Thanks to Johnny Tucker + <JTucker@infoglide.com> for contributing this. + + * ace/Managed_Object.h: Added ACE_UNIMPLEMENTED_FUNC macros for + copy constructor and assignment operator in class + ACE_Cleanup_Adapter. Thanks to Johnny Willemsen + <johnny.willemsen@meco.nl> for reporting this. + + * tests/run_tests.sh: Prevent null or zero-length string test name from being + passed into the run() function. Thanks to Jon Loeliger + <jloeliger@chiaro.com> for reporting this. + + * tests/Log_Msg_Test.cpp, + * examples/Log_Msg/test_log_msg.cpp (main): + Replaced int with u_long to make compilers happy. Thanks to + Mike Curtis <mccurry@my-deja.com> for pointing this out. + Tue Dec 5 11:45:42 2000 Darrell Brunsch <brunsch@uci.edu> * ace/SSL/SSL_SOCK_Acceptor.cpp: diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 4bf9f552dc1..912b780dc5b 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,24 @@ +Wed Dec 6 14:29:13 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> + + * ace/Auto_Ptr.{h,i}: Added a new set of class (ACE_Refcounted_Auto_Ptr_Rep, + ACE_Refcounted_Auto_Ptr) that implements support for a reference + counted auto_ptr. Thanks to Johnny Tucker + <JTucker@infoglide.com> for contributing this. + + * ace/Managed_Object.h: Added ACE_UNIMPLEMENTED_FUNC macros for + copy constructor and assignment operator in class + ACE_Cleanup_Adapter. Thanks to Johnny Willemsen + <johnny.willemsen@meco.nl> for reporting this. + + * tests/run_tests.sh: Prevent null or zero-length string test name from being + passed into the run() function. Thanks to Jon Loeliger + <jloeliger@chiaro.com> for reporting this. + + * tests/Log_Msg_Test.cpp, + * examples/Log_Msg/test_log_msg.cpp (main): + Replaced int with u_long to make compilers happy. Thanks to + Mike Curtis <mccurry@my-deja.com> for pointing this out. + Tue Dec 5 11:45:42 2000 Darrell Brunsch <brunsch@uci.edu> * ace/SSL/SSL_SOCK_Acceptor.cpp: @@ -1091,6 +1091,7 @@ Andy Guy <andy@emory.demon.co.uk> Oscar Rodriquez <Oscar.Rodriquez@eln.ericsson.se> Jonathan Cano <jcano@mmcnet.com> Decamps Alain <Alain.Decamps@PIDPA.be> +Jon Loeliger <jloeliger@chiaro.com> I would particularly like to thank Paul Stephenson, who worked with me at Ericsson. Paul devised the recursive Makefile scheme that diff --git a/ace/Auto_Ptr.h b/ace/Auto_Ptr.h index 104e917d9aa..32ceb251c03 100644 --- a/ace/Auto_Ptr.h +++ b/ace/Auto_Ptr.h @@ -6,10 +6,11 @@ * * $Id$ * - * @author Doug Schmidt - * @author and Irfan Pyarali - * @author Jack Reeves (jack@fx.com) - * @author Dr. Harald M. Mueller (mueller@garwein.hai.siemens.co.at) + * @author Doug Schmidt <schmidt@uci.edu> + * @author Irfan Pyarali <irfan@cs.wustl.edu> + * @author John Tucker <JTucker@infoglide.com> + * @author Jack Reeves <jack@fx.com> + * @author Dr. Harald M. Mueller <mueller@garwein.hai.siemens.co.at> */ //============================================================================= @@ -157,6 +158,152 @@ public: } while (0) # endif /* ACE_AUTO_PTR_LACKS_RESET */ +// Forward decl. +template <class X, class ACE_LOCK> class ACE_Refcounted_Auto_Ptr_Rep; +template <class X, class ACE_LOCK> class ACE_Refcounted_Auto_Ptr; + +/** + * @class ACE_Refcounted_Auto_Ptr + * + * @brief This class implements support for a reference counted auto_ptr. + * Assigning or copying instances of an ACE_Refcounted_Auto_Ptr + * will automatically increment the reference count. When the last + * instance that references a ACE_Refcounted_Auto_Ptr instance is + * destroyed or overwritten, it will invoke delete on its underlying + * pointer. + */ +template <class X, class ACE_LOCK> +class ACE_Refcounted_Auto_Ptr +{ +public: + + // = Initialization and termination methods. + + /// Constructor that initializes an <ACE_Refcounted_Auto_Ptr> to + /// point to the result <r> immediately. + ACE_Refcounted_Auto_Ptr (X *p = 0); + + /// Copy constructor binds <this> and <r> to the same + /// <ACE_Refcounted_Auto_Ptr_Rep>. An <ACE_Refcounted_Auto_Ptr_Rep> + /// is created if necessary. + ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r); + + /// Destructor. + ~ACE_Refcounted_Auto_Ptr (void); + + /// Assignment operator that binds <this> and <r> to the same + /// <ACE_Refcounted_Auto_Ptr_Rep>. An <ACE_Refcounted_Auto_Ptr_Rep> + /// is created if necessary. + void operator = (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r); + + /// Equality operator that returns 1 if both + /// ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> objects point to the same + /// ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> object. Attention: It + /// also returns 1 if both objects have just been instantiated and + /// not used yet. + int operator == (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const; + + /// Inequality operator, which is the opposite of equality. + int operator != (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const; + + /// Redirection operator + X *operator-> (void) const; + + // = Accessor methods. + + X &operator *() const; + + /// Sets the pointer value to 0 and returns its old value. + X *release (void); + + /// Invokes delete on the previous pointer value and then sets the + /// pointer value to the specified value. + void reset (X *p = 0); + + /// Get the pointer value. + X *get (void); + + /// Declare the dynamic allocation hooks. + ACE_ALLOC_HOOK_DECLARE; + +private: + /// the ACE_Refcounted_Auto_Ptr_Rep + typedef ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> AUTO_REFCOUNTED_PTR_REP; + + /// Protect operations on the <ACE_Refcounted_Auto_Ptr>. + AUTO_REFCOUNTED_PTR_REP *rep_; +}; + +/** + * @class ACE_Refcounted_Auto_Ptr_Rep + * + * @brief An ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> object + * incapsulates a pointer to an object of type X. It is pointed to by + * ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> object[s] and only accessible + * through them. + */ +template <class X, class ACE_LOCK> +class ACE_Refcounted_Auto_Ptr_Rep +{ +private: + friend class ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>; + + /// Sets the pointer value to 0 and returns its old value. + X *release (void); + + /// Invokes delete on the previous pointer value and then + /// sets the pointer value to the specified value. + void reset (X *p = 0); + + /// Get the pointer value. + X *get (void); + + /// Declare the dynamic allocation hooks. + ACE_ALLOC_HOOK_DECLARE; + + // = Encapsulate reference count and object lifetime of instances. + // These methods must go after the others to work around a bug with + // Borland's C++ Builder... + + /// Create a ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> and initialize + /// the reference count. + static ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *create (X *p); + + /// Increase the reference count and return argument. Uses the + /// attribute "ace_lock_" to synchronize reference count updating. + /// + /// Precondition (rep != 0). + static ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *attach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *&rep); + + /// Decreases the reference count and and deletes rep if there are no + /// more references to rep. + /// + /// Precondition (rep != 0) + static void detach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *&rep); + + /// Decreases the rep's reference count and and deletes rep if there + /// are no more references to rep. Then assigns new_rep to rep. + /// + /// Precondition (rep != 0 && new_rep != 0) + static void assign (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *&rep, + ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *new_rep); + + /// Pointer to the result. + ACE_Auto_Basic_Ptr<X> ptr_; + + /// Reference count. + int ref_count_; + + // = Mutex variable to protect the <ptr_>. + + /// Synchronization variable for the MT_SAFE <ACE_Hash_Map_Manager_Ex>. + ACE_LOCK lock_; + +private: + // = Constructor and destructor private. + ACE_Refcounted_Auto_Ptr_Rep (X *p = 0); + ~ACE_Refcounted_Auto_Ptr_Rep (void); +}; #if defined (__ACE_INLINE__) #include "ace/Auto_Ptr.i" diff --git a/ace/Auto_Ptr.i b/ace/Auto_Ptr.i index 5342f8b8ede..53b5f1db51e 100644 --- a/ace/Auto_Ptr.i +++ b/ace/Auto_Ptr.i @@ -141,3 +141,166 @@ ACE_Auto_Array_Ptr<X>::operator->() const { return this->get (); } + +template <class X, class ACE_LOCK> ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> * +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::create (X *p) +{ + // Yes set ref count to zero. + return new ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> (p); +} + +template <class X, class ACE_LOCK> ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> * +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::attach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep) +{ + ACE_ASSERT (rep != 0); + + ACE_GUARD_RETURN (ACE_LOCK, guard, rep->lock_, rep); + + ++rep->ref_count_; + + return rep; +} + +template <class X, class ACE_LOCK> void +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::detach (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep) +{ + ACE_ASSERT (rep != 0); + + ACE_GUARD (ACE_LOCK, guard, rep->lock_); + + if (rep->ref_count_-- == 0) + // We do not need the lock when deleting the representation. + // There should be no side effects from deleting rep and we don + // not want to release a deleted mutex. + delete rep; +} + +template <class X, class ACE_LOCK> void +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::assign (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>*& rep, ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>* new_rep) +{ + ACE_ASSERT (rep != 0); + ACE_ASSERT (new_rep != 0); + + ACE_GUARD (ACE_LOCK, guard, rep->lock_); + + ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *old = rep; + rep = new_rep; + + // detached old last for exception safety + if(old->ref_count_-- == 0) + // We do not need the lock when deleting the representation. + // There should be no side effects from deleting rep and we don + // not want to release a deleted mutex. + delete old; +} + +template <class X, class ACE_LOCK> +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr_Rep (X *p) + : ptr_ (p), + ref_count_ (0) +{ +} + +template <class X, class ACE_LOCK> +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr_Rep (void) +{ +} + +template<class X, class ACE_LOCK> ACE_INLINE X * +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::release (void) +{ + ACE_GUARD_RETURN (ACE_LOCK, guard, this->lock_, 0); + + return this->ptr_.release (); +} + +template<class X, class ACE_LOCK> ACE_INLINE void +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::reset (X *p) +{ + ACE_GUARD (ACE_LOCK, guard, this->lock_); + + this->ptr_.reset (p); +} + +template <class X, class ACE_LOCK> X * +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::get (void) +{ + ACE_GUARD_RETURN (ACE_LOCK, guard, this->lock_, 0); + + return this->ptr_.get (); +} + +template <class X, class ACE_LOCK> +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (X *p) + : rep_ (AUTO_REFCOUNTED_PTR_REP::create (p)) +{ +} + +template <class X, class ACE_LOCK> +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) + : rep_ (AUTO_REFCOUNTED_PTR_REP::attach (((ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &) r).rep_)) +{ +} + +template <class X, class ACE_LOCK> +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr (void) +{ + AUTO_REFCOUNTED_PTR_REP::detach (rep_); +} + +template <class X, class ACE_LOCK> int +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator== (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const +{ + return r.rep_ == this->rep_; +} + +template <class X, class ACE_LOCK> int +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator!= (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r) const +{ + return r.rep_ != this->rep_; +} + +template <class X, class ACE_LOCK> X * +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator-> (void) const +{ + return this->rep_->get(); +} + +template<class X, class ACE_LOCK> ACE_INLINE X & +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator *() const +{ + return *this->rep_->get (); +} + +template <class X, class ACE_LOCK> X* +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::get (void) +{ + // We return the ACE_Future_rep. + return this->rep_->get (); +} + +template<class X, class ACE_LOCK> ACE_INLINE X * +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::release (void) +{ + return this->rep_->release (); +} + +template<class X, class ACE_LOCK> ACE_INLINE void +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::reset (X *p) +{ + this->rep_->reset (p); +} + +template <class X, class ACE_LOCK> void +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator = (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &rhs) +{ + // assignment: + // + // bind <this> to the same <ACE_Refcounted_Auto_Ptr_Rep> as <r>. + + // This will work if &r == this, by first increasing the ref count + ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r = (ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &) rhs; + AUTO_REFCOUNTED_PTR_REP::assign (this->rep_, + AUTO_REFCOUNTED_PTR_REP::attach (r.rep_)); +} + diff --git a/ace/Managed_Object.h b/ace/Managed_Object.h index 7b96dd8fdaa..083b2287b30 100644 --- a/ace/Managed_Object.h +++ b/ace/Managed_Object.h @@ -50,6 +50,9 @@ public: TYPE &object (void); private: + ACE_UNIMPLEMENTED_FUNC (ACE_Cleanup_Adapter (const ACE_Cleanup_Adapter<TYPE> &)) + ACE_UNIMPLEMENTED_FUNC (ACE_Cleanup_Adapter& operator= (const ACE_Cleanup_Adapter<TYPE> &)) + /// Contained object. TYPE object_; }; diff --git a/examples/Log_Msg/test_log_msg.cpp b/examples/Log_Msg/test_log_msg.cpp index 0bf38ac8cdc..7547f735382 100644 --- a/examples/Log_Msg/test_log_msg.cpp +++ b/examples/Log_Msg/test_log_msg.cpp @@ -141,7 +141,7 @@ main (int argc, char *argv[]) sizeof array); // Disable the LM_DEBUG and LM_INFO messages. - int priority_mask = ACE_LOG_MSG->priority_mask (); + u_long priority_mask = ACE_LOG_MSG->priority_mask (); ACE_CLR_BITS (priority_mask, LM_DEBUG | LM_INFO); ACE_LOG_MSG->priority_mask (priority_mask); diff --git a/tests/Log_Msg_Test.cpp b/tests/Log_Msg_Test.cpp index 5e87370f2ba..156e106552a 100644 --- a/tests/Log_Msg_Test.cpp +++ b/tests/Log_Msg_Test.cpp @@ -276,7 +276,7 @@ test_log_msg_features (const char *program) sizeof array); // Disable the LM_DEBUG and LM_INFO messages. - int priority_mask = ACE_LOG_MSG->priority_mask (); + u_long priority_mask = ACE_LOG_MSG->priority_mask (); ACE_CLR_BITS (priority_mask, LM_DEBUG | LM_INFO); ACE_LOG_MSG->priority_mask (priority_mask); diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 71a9e9dc5e5..3bac5fe9335 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -186,30 +186,32 @@ fi # ! procnto # Redirection gets confused when rsh is involved (Chorus) for i in `cat run_tests.lst | tr "\012" "$IFS"`; do - case $i in - */*) - p=`dirname $i | sed 's%/% \&\& test $%g'`; - precond="\$$p"; - test=`basename $i`; - ;; - *) - precond=""; - test=$i; - ;; - esac + if [ "$i" != "" ]; then + + case $i in + */*) + p=`dirname $i | sed 's%/% \&\& test $%g'`; + precond="\$$p"; + test=`basename $i`; + ;; + *) + precond=""; + test=$i; + ;; + esac # echo =****= $precond ===== $test; - if test -z "$precond"; then - run $test - elif eval test $precond; then - run $test - else - if echo $precond | egrep '(DISABLED)|(OTHER)' > /dev/null; then :; else - echo Skipping $test on this platform + if test -z "$precond"; then + run $test + elif eval test $precond; then + run $test + else + if echo $precond | egrep '(DISABLED)|(OTHER)' > /dev/null; then :; else + echo Skipping $test on this platform + fi fi fi - done echo "Finished ACE version $ace_version tests." |