diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 2000-12-08 16:48:57 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 2000-12-08 16:48:57 +0000 |
commit | 913824e5e462f44dda679324c416776b05cecabb (patch) | |
tree | 4d767e709120fce9a4814791c485359993cc94c8 | |
parent | dd0e127683088e889b58a523e9be7c847db33f84 (diff) | |
download | ATCD-913824e5e462f44dda679324c416776b05cecabb.tar.gz |
ChangeLogTag:Fri Dec 8 10:34:32 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu>
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 11 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 11 | ||||
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | ace/Auto_Ptr.h | 149 | ||||
-rw-r--r-- | ace/Auto_Ptr.i | 164 | ||||
-rw-r--r-- | ace/Makefile | 1 | ||||
-rw-r--r-- | ace/QtReactor.h | 2 | ||||
-rw-r--r-- | ace/Refcounted_Auto_Ptr.h | 174 | ||||
-rw-r--r-- | ace/Refcounted_Auto_Ptr.i | 170 |
10 files changed, 380 insertions, 314 deletions
diff --git a/ChangeLog b/ChangeLog index acdcb45ac07..f48b59e7d3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri Dec 8 10:34:32 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> + + * ace/Makefile: Added Refcounted_Auto_Ptr to the list of template + files. + + * ace/Auto_Ptr.{h,i}: + * ace/Refcounted_Auto_Ptr.{h,i}: Moved the new + ACE_Refcounted_Auto_Ptr into a separate file to reduce + unnecessarily coupling in ACE. Thanks to Darrell Brunsch for + pointing this out. + Fri Dec 8 09:27:01 2000 Chad Elliott <elliott_c@ociweb.com> * include/makeinclude/platform_chorus4.x_g++.GNU: diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index acdcb45ac07..f48b59e7d3c 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,14 @@ +Fri Dec 8 10:34:32 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> + + * ace/Makefile: Added Refcounted_Auto_Ptr to the list of template + files. + + * ace/Auto_Ptr.{h,i}: + * ace/Refcounted_Auto_Ptr.{h,i}: Moved the new + ACE_Refcounted_Auto_Ptr into a separate file to reduce + unnecessarily coupling in ACE. Thanks to Darrell Brunsch for + pointing this out. + Fri Dec 8 09:27:01 2000 Chad Elliott <elliott_c@ociweb.com> * include/makeinclude/platform_chorus4.x_g++.GNU: diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index acdcb45ac07..f48b59e7d3c 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,14 @@ +Fri Dec 8 10:34:32 2000 Douglas C. Schmidt <schmidt@ace.cs.wustl.edu> + + * ace/Makefile: Added Refcounted_Auto_Ptr to the list of template + files. + + * ace/Auto_Ptr.{h,i}: + * ace/Refcounted_Auto_Ptr.{h,i}: Moved the new + ACE_Refcounted_Auto_Ptr into a separate file to reduce + unnecessarily coupling in ACE. Thanks to Darrell Brunsch for + pointing this out. + Fri Dec 8 09:27:01 2000 Chad Elliott <elliott_c@ociweb.com> * include/makeinclude/platform_chorus4.x_g++.GNU: @@ -1094,6 +1094,7 @@ Decamps Alain <Alain.Decamps@PIDPA.be> Jon Loeliger <jloeliger@chiaro.com> Ricardo Chan <ricchan@nortelnetworks.com> Sarabjeet Duhra <sarabjeet_duhra@hp.com> +Sathish Tiptur <Sathish.Tiptur@geind.ge.com> Michael Rushton <miker@mbmnz.co.nz> I would particularly like to thank Paul Stephenson, who worked with me diff --git a/ace/Auto_Ptr.h b/ace/Auto_Ptr.h index 32ceb251c03..aa7e0eec35d 100644 --- a/ace/Auto_Ptr.h +++ b/ace/Auto_Ptr.h @@ -8,13 +8,11 @@ * * @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> */ //============================================================================= - #ifndef ACE_AUTO_PTR_H #define ACE_AUTO_PTR_H #include "ace/pre.h" @@ -158,153 +156,6 @@ 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" #endif /* __ACE_INLINE__ */ diff --git a/ace/Auto_Ptr.i b/ace/Auto_Ptr.i index 85f54bfc834..2dca307b97a 100644 --- a/ace/Auto_Ptr.i +++ b/ace/Auto_Ptr.i @@ -3,8 +3,6 @@ // Auto_Ptr.i -#include "Synch_T.h" - template<class X> ACE_INLINE ACE_Auto_Basic_Ptr<X>::ACE_Auto_Basic_Ptr (ACE_Auto_Basic_Ptr<X> &rhs) : p_ (rhs.release ()) @@ -144,165 +142,3 @@ ACE_Auto_Array_Ptr<X>::operator->() const return this->get (); } -template <class X, class ACE_LOCK> ACE_INLINE 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_INLINE 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> ACE_INLINE 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> ACE_INLINE 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_INLINE -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_INLINE -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/Makefile b/ace/Makefile index 7b3f817e844..76a2d99ab39 100644 --- a/ace/Makefile +++ b/ace/Makefile @@ -265,6 +265,7 @@ TEMPLATE_FILES = \ Message_Queue_T \ Module \ Pair_T \ + Refcounted_Auto_Ptr \ RB_Tree \ Select_Reactor_T \ Singleton \ diff --git a/ace/QtReactor.h b/ace/QtReactor.h index 2944a3b7069..7be109e6b4f 100644 --- a/ace/QtReactor.h +++ b/ace/QtReactor.h @@ -36,7 +36,7 @@ * * @brief An object-oriented event demultiplexor and event handler * dispatcher that uses the Qt Library. This class declaration - * also uses the extnsion facilities provided by the Qt. So, + * also uses the extension facilities provided by the Qt. So, * readers of the class declaration should not be upset with * the appearence of the Keywords like Q_OBJECT, private slots * etc. They are specific to Qt which uses these as a call back diff --git a/ace/Refcounted_Auto_Ptr.h b/ace/Refcounted_Auto_Ptr.h new file mode 100644 index 00000000000..a935dd38e20 --- /dev/null +++ b/ace/Refcounted_Auto_Ptr.h @@ -0,0 +1,174 @@ +/* -*- C++ -*- */ + +//============================================================================= +/** + * @file Refcounted_Auto_Ptr.h + * + * $Id$ + * + * @author John Tucker <JTucker@infoglide.com> + */ +//============================================================================= + + +#ifndef ACE_REFCOUNTED_AUTO_PTR_H +#define ACE_REFCOUNTED_AUTO_PTR_H +#include "ace/pre.h" + +#include "ace/OS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +// 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); +}; + +#include "ace/Refcounted_Auto_Ptr.i" + +#include "ace/post.h" +#endif /* ACE_AUTO_PTR_H */ diff --git a/ace/Refcounted_Auto_Ptr.i b/ace/Refcounted_Auto_Ptr.i new file mode 100644 index 00000000000..a712d373175 --- /dev/null +++ b/ace/Refcounted_Auto_Ptr.i @@ -0,0 +1,170 @@ +/* -*- C++ -*- */ +// $Id$ + +// Refcounted_Auto_Ptr.i + +#include "Synch_T.h" + +template <class X, class ACE_LOCK> inline 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> inline 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> inline 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> inline 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> inline +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> inline +ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr_Rep (void) +{ +} + +template<class X, class ACE_LOCK> 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> 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> inline 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> inline +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> inline +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> inline +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr (void) +{ + AUTO_REFCOUNTED_PTR_REP::detach (rep_); +} + +template <class X, class ACE_LOCK> inline 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> inline 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> inline X * +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator-> (void) const +{ + return this->rep_->get(); +} + +template<class X, class ACE_LOCK> inline X & +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator *() const +{ + return *this->rep_->get (); +} + +template <class X, class ACE_LOCK> inline 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> inline X * +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::release (void) +{ + return this->rep_->release (); +} + +template<class X, class ACE_LOCK> inline void +ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::reset (X *p) +{ + this->rep_->reset (p); +} + +template <class X, class ACE_LOCK> inline 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_)); +} + |