version 1.10, 2002/11/05 22:14:02
|
version 1.11, 2002/11/06 18:50:17
|
|
|
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/Linkage.h> | #include <Pegasus/Common/Linkage.h> |
#include <Pegasus/Common/IPC.h> | #include <Pegasus/Common/IPC.h> |
|
#include <assert.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
Sharable() : _ref(1) { } | Sharable() : _ref(1) { } |
| |
virtual ~Sharable(); | virtual ~Sharable(); |
Uint32 getRef() const { return _ref; } |
Uint32 getRef() const { return _ref.value(); } |
// Uint32 getRef() const { return _ref.value(); } |
|
| |
friend void Inc(const Sharable* sharable); | friend void Inc(const Sharable* sharable); |
| |
friend void Dec(const Sharable* sharable); | friend void Dec(const Sharable* sharable); |
| |
private: | private: |
Uint32 _ref; |
AtomicInt _ref; |
// AtomicInt _ref; |
|
}; | }; |
| |
inline void Inc(const Sharable* x) | inline void Inc(const Sharable* x) |
| |
{ | { |
if (x) | if (x) |
|
{ |
|
// 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.value()); |
((Sharable*)x)->_ref++; | ((Sharable*)x)->_ref++; |
} | } |
| |
|
} |
|
|
|
|
inline void Dec(const Sharable* x) | inline void Dec(const Sharable* x) |
{ | { |
if (x && --((Sharable*)x)->_ref == 0) |
if (x && ((Sharable*)x)->_ref.DecAndTestIfZero()) |
delete (Sharable*)x; | delete (Sharable*)x; |
|
|
// if (x && ((Sharable*)x)->_ref.DecAndTestIfZero()) |
|
// delete (Sharable*)x; |
|
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |