summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/ConnectionI.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2007-09-07 15:34:06 -0400
committerBernard Normier <bernard@zeroc.com>2007-09-07 15:34:06 -0400
commit1e2e7ed93ce4fbe4f1f1ef5c100b38a2edb31527 (patch)
treebb69ccda51b972d01ad1c3381b8d307cdeca5232 /cpp/src/Freeze/ConnectionI.cpp
parentupdating reserved words & keyword test (diff)
downloadice-1e2e7ed93ce4fbe4f1f1ef5c100b38a2edb31527.tar.bz2
ice-1e2e7ed93ce4fbe4f1f1ef5c100b38a2edb31527.tar.xz
ice-1e2e7ed93ce4fbe4f1f1ef5c100b38a2edb31527.zip
Refcounting is now thread-safe
Diffstat (limited to 'cpp/src/Freeze/ConnectionI.cpp')
-rw-r--r--cpp/src/Freeze/ConnectionI.cpp39
1 files changed, 33 insertions, 6 deletions
diff --git a/cpp/src/Freeze/ConnectionI.cpp b/cpp/src/Freeze/ConnectionI.cpp
index dae584e3bbd..258060f9f5c 100644
--- a/cpp/src/Freeze/ConnectionI.cpp
+++ b/cpp/src/Freeze/ConnectionI.cpp
@@ -77,19 +77,44 @@ Freeze::ConnectionI::getName() const
return _envName;
}
-//
-// External refcount operations, from code holding a Connection[I]Ptr
-//
+void
+Freeze::ConnectionI::__incRef()
+{
+ IceUtil::Mutex::Lock sync(_refCountMutex->mutex);
+ _refCount++;
+}
+
+
void
Freeze::ConnectionI::__decRef()
{
- if(__getRef() == 2 && _transaction && _transaction->__getRef() == 1)
+ IceUtil::Mutex::Lock sync(_refCountMutex->mutex);
+ if(--_refCount == 0)
+ {
+ sync.release();
+ delete this;
+ }
+ else if(_refCount == 1 && _transaction != 0 && _transaction->dbTxn() != 0 && _transaction->__getRefNoSync() == 1)
{
+ sync.release();
close();
}
- Shared::__decRef();
}
+int
+Freeze::ConnectionI::__getRef() const
+{
+ IceUtil::Mutex::Lock sync(_refCountMutex->mutex);
+ return _refCount;
+}
+
+int
+Freeze::ConnectionI::__getRefNoSync() const
+{
+ return _refCount;
+}
+
+
Freeze::ConnectionI::~ConnectionI()
{
close();
@@ -101,7 +126,9 @@ Freeze::ConnectionI::ConnectionI(const SharedDbEnvPtr& dbEnv) :
_envName(dbEnv->getEnvName()),
_trace(_communicator->getProperties()->getPropertyAsInt("Freeze.Trace.Map")),
_txTrace(_communicator->getProperties()->getPropertyAsInt("Freeze.Trace.Transaction")),
- _deadlockWarning(_communicator->getProperties()->getPropertyAsInt("Freeze.Warn.Deadlocks") != 0)
+ _deadlockWarning(_communicator->getProperties()->getPropertyAsInt("Freeze.Warn.Deadlocks") != 0),
+ _refCountMutex(new SharedMutex),
+ _refCount(0)
{
}