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

 1 karl  1.16 //%2005////////////////////////////////////////////////////////////////////////
 2 mike  1.6  //
 3 karl  1.15 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
 6 karl  1.14 // IBM Corp.; EMC Corporation, The Open Group.
 7 karl  1.15 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
 8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 9 karl  1.16 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 mike  1.6  //
12            // Permission is hereby granted, free of charge, to any person obtaining a copy
13 kumpf 1.7  // of this software and associated documentation files (the "Software"), to
14            // deal in the Software without restriction, including without limitation the
15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 mike  1.6  // sell copies of the Software, and to permit persons to whom the Software is
17            // furnished to do so, subject to the following conditions:
18            // 
19 kumpf 1.7  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 mike  1.6  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 kumpf 1.7  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 mike  1.6  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27            //
28            //==============================================================================
29            //
30            // Author: Mike Brasher (mbrasher@bmc.com)
31            //
32 kumpf 1.9  // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
33 david.eger 1.12 //              David Eger (dteger@us.ibm.com)
34 mike       1.6  //
35                 //%/////////////////////////////////////////////////////////////////////////////
36                 
37                 #ifndef Pegasus_Sharable_h
38                 #define Pegasus_Sharable_h
39                 
40                 #include <Pegasus/Common/Config.h>
41 kumpf      1.8  #include <Pegasus/Common/Linkage.h>
42 kumpf      1.9  #include <Pegasus/Common/IPC.h>
43 mday       1.11 #include <assert.h>
44 mike       1.6  
45                 PEGASUS_NAMESPACE_BEGIN
46                 
47                 /** 
48                     The Sharable class implements a simple reference counting scheme. 
49                     The static Inc() method increments the reference count member. 
50                     The static Dec() method decrements the reference count and deletes
51                     the object when the reference count becomes zero.
52                 
53                     Other classes may inherit this reference counting behavior simply
54                     by deriving from this class.
55                 */
56                 class PEGASUS_COMMON_LINKAGE Sharable
57                 {
58                 public:
59                 
60 mike       1.16.14.2     Sharable() : _ref(1) { }
61 mike       1.6       
62                          virtual ~Sharable();
63 mday       1.11          Uint32 getRef() const { return _ref.value(); }
64 mike       1.6       
65 david.eger 1.12          friend void Inc(Sharable* sharable); 
66 mike       1.6       
67 david.eger 1.12          friend void Dec(Sharable* sharable);
68 mike       1.6       
69                      private:
70 david.eger 1.12          Sharable(const Sharable &s) : _ref(1) {assert(0);} 
71                          // we should never copy a counter, so we make this private - dte
72 mday       1.13          AtomicInt _ref;
73 mike       1.6       };
74                      
75 david.eger 1.12      inline void Inc(Sharable* x)
76 mike       1.6       {
77 mday       1.11        if (x)
78                          {
79                            // A sharable object should never be incremented from zero.
80                            // If so, there is a double delete being cause by impropoer use
81                            // of sharable assignment or copy constructors somewhere
82                            // << Wed Nov  6 12:46:52 2002 mdd >>
83                            assert(((Sharable*)x)->_ref.value());
84 david.eger 1.12            x->_ref++;
85 mday       1.11          }
86                        
87 mike       1.6       }
88                      
89 mday       1.11      
90 david.eger 1.12      inline void Dec(Sharable* x)
91 mike       1.6       {
92 david.eger 1.12        if (x && x->_ref.DecAndTestIfZero())
93                          delete x;
94 mike       1.6       }
95                      
96                      PEGASUS_NAMESPACE_END
97                      
98                      #endif /* Pegasus_Sharable_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2