(file) Return to Sharable.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/Sharable.h between version 1.2 and 1.17

version 1.2, 2001/04/25 22:20:56 version 1.17, 2005/10/24 19:35:25
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2005////////////////////////////////////////////////////////////////////////
 //  
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // copy of this software and associated documentation files (the "Software"),  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 // to deal in the Software without restriction, including without limitation  // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  // IBM Corp.; EMC Corporation, The Open Group.
 // and/or sell copies of the Software, and to permit persons to whom the  // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
 // Software is furnished to do so, subject to the following conditions:  // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 //  // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // EMC Corporation; VERITAS Software Corporation; The Open Group.
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  //
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  // Permission is hereby granted, free of charge, to any person obtaining a copy
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  // of this software and associated documentation files (the "Software"), to
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  // deal in the Software without restriction, including without limitation the
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 // DEALINGS IN THE SOFTWARE.  // sell copies of the Software, and to permit persons to whom the Software is
   // furnished to do so, subject to the following conditions:
   //
   // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
   // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
   // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
   // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
   // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
   // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
   // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By:  // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
   //              David Eger (dteger@us.ibm.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 ////////////////////////////////////////////////////////////////////////////////  
 //  
 // Sharable.h  
 //  
 //      The Sharable class implements a simple reference counting scheme.  
 //      The static Inc() method increments the reference count member.  
 //      The static Dec() method decrements the reference count and deletes  
 //      the object when the reference count becomes zero.  
 //  
 //      Other classes may inherit this reference counting behavior simply  
 //      by deriving from this class.  
 //  
 ////////////////////////////////////////////////////////////////////////////////  
   
 #ifndef Pegasus_Sharable_h #ifndef Pegasus_Sharable_h
 #define Pegasus_Sharable_h #define Pegasus_Sharable_h
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
   #include <Pegasus/Common/Linkage.h>
   #include <Pegasus/Common/IPC.h>
   #include <assert.h>
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   /**
       The Sharable class implements a simple reference counting scheme.
       The static Inc() method increments the reference count member.
       The static Dec() method decrements the reference count and deletes
       the object when the reference count becomes zero.
   
       Other classes may inherit this reference counting behavior simply
       by deriving from this class.
   */
 class PEGASUS_COMMON_LINKAGE Sharable class PEGASUS_COMMON_LINKAGE Sharable
 { {
 public: public:
Line 53 
Line 60 
     Sharable() : _ref(1) { }     Sharable() : _ref(1) { }
  
     virtual ~Sharable();     virtual ~Sharable();
       Uint32 getRef() const { return _ref.get(); }
  
     Uint32 getRef() const { return _ref; }      friend void Inc(Sharable* sharable);
  
     friend void Inc(const Sharable* sharable);      friend void Dec(Sharable* sharable);
   
     friend void Dec(const Sharable* sharable);  
  
 private: private:
       Sharable(const Sharable &s) : _ref(1) {assert(0);}
     Uint32 _ref;      // we should never copy a counter, so we make this private - dte
       AtomicInt _ref;
 }; };
  
 inline void Inc(const Sharable* x)  inline void Inc(Sharable* x)
 { {
     if (x)     if (x)
         ((Sharable*)x)->_ref++;      {
         // A sharable object should never be incremented from zero.
         // If so, there is a double delete being cause by impropoer use
         // of sharable assignment or copy constructors somewhere
         // << Wed Nov  6 12:46:52 2002 mdd >>
         assert(((Sharable*)x)->_ref.get());
         x->_ref++;
 } }
  
 inline void Dec(const Sharable* x)  }
   
   
   inline void Dec(Sharable* x)
 { {
     if (x && --((Sharable*)x)->_ref == 0)    if (x && x->_ref.decAndTestIfZero())
         delete (Sharable*)x;      delete x;
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.17

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2