summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/GCShared.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/GCShared.cpp')
-rwxr-xr-xcpp/src/Ice/GCShared.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/cpp/src/Ice/GCShared.cpp b/cpp/src/Ice/GCShared.cpp
new file mode 100755
index 00000000000..7dc7b05c7a9
--- /dev/null
+++ b/cpp/src/Ice/GCShared.cpp
@@ -0,0 +1,86 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <Ice/GCShared.h>
+
+namespace IceInternal
+{
+
+GCObjectSet gcObjects;
+
+}
+
+using namespace IceInternal;
+
+IceInternal::GCShared::GCShared() :
+ _ref(0),
+ _noDelete(false)
+{
+}
+
+IceInternal::GCShared::GCShared(const GCShared&) :
+ _ref(0),
+ _noDelete(false)
+{
+}
+
+void
+IceInternal::GCShared::__incRef()
+{
+ gcRecMutex._m->lock();
+ assert(_ref >= 0);
+ ++_ref;
+ gcRecMutex._m->unlock();
+}
+
+void
+IceInternal::GCShared::__decRef()
+{
+ gcRecMutex._m->lock();
+ bool doDelete = false;
+ assert(_ref > 0);
+ if(--_ref == 0)
+ {
+ doDelete = !_noDelete;
+ _noDelete = true;
+ }
+ gcRecMutex._m->unlock();
+ if(doDelete)
+ {
+ delete this;
+ }
+}
+
+int
+IceInternal::GCShared::__getRef() const
+{
+ gcRecMutex._m->lock();
+ int ref = _ref;
+ gcRecMutex._m->unlock();
+ return ref;
+}
+
+void
+IceInternal::GCShared::__setNoDelete(bool b)
+{
+ gcRecMutex._m->lock();
+ _noDelete = b;
+ gcRecMutex._m->unlock();
+}
+
+void
+IceInternal::GCShared::__addObject(GCObjectMultiSet& c, GCShared* p)
+{
+ gcRecMutex._m->lock();
+ if(p)
+ {
+ c.insert(p);
+ }
+ gcRecMutex._m->unlock();
+}