diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-05-30 13:18:35 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-05-30 13:18:35 +0000 |
commit | cd8abbb04a79b0d93f34742c49b06607e4e989f7 (patch) | |
tree | fabe04903dac6bd3ecf2ac6f3248ab5c22300fa7 /cpp/src/Freeze/SharedDbEnv.cpp | |
parent | fix problem with possible use of uninitialized local variable (diff) | |
download | ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.tar.bz2 ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.tar.xz ice-cd8abbb04a79b0d93f34742c49b06607e4e989f7.zip |
Removed transactional evictor context
Diffstat (limited to 'cpp/src/Freeze/SharedDbEnv.cpp')
-rw-r--r-- | cpp/src/Freeze/SharedDbEnv.cpp | 91 |
1 files changed, 57 insertions, 34 deletions
diff --git a/cpp/src/Freeze/SharedDbEnv.cpp b/cpp/src/Freeze/SharedDbEnv.cpp index ecf6bc09d04..de30521dfbe 100644 --- a/cpp/src/Freeze/SharedDbEnv.cpp +++ b/cpp/src/Freeze/SharedDbEnv.cpp @@ -11,7 +11,7 @@ #include <Freeze/Exception.h> #include <Freeze/Util.h> #include <Freeze/SharedDb.h> -#include <Freeze/TransactionalEvictorContextI.h> +#include <Freeze/TransactionalEvictorContext.h> #include <IceUtil/IceUtil.h> @@ -218,38 +218,33 @@ void Freeze::SharedDbEnv::__decRef() } -Freeze::TransactionalEvictorContextIPtr -Freeze::SharedDbEnv::getOrCreateCurrent(bool& created) -{ - created = false; - - Freeze::TransactionalEvictorContextIPtr ctx = getCurrent(); - if(ctx == 0) - { - ctx = new TransactionalEvictorContextI(this); +Freeze::TransactionalEvictorContextPtr +Freeze::SharedDbEnv::createCurrent() +{ + assert(getCurrent() == 0); + + Freeze::TransactionalEvictorContextPtr ctx = new TransactionalEvictorContext(this); #ifdef _WIN32 - if(TlsSetValue(_tsdKey, ctx.get()) == 0) - { - IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } + if(TlsSetValue(_tsdKey, ctx.get()) == 0) + { + IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); + } #else - if(int err = pthread_setspecific(_tsdKey, ctx.get())) - { - throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, err); - } -#endif - created = true; - - // - // Give one refcount to this thread! - // - ctx->__incRef(); + if(int err = pthread_setspecific(_tsdKey, ctx.get())) + { + throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, err); } +#endif + + // + // Give one refcount to this thread! + // + ctx->__incRef(); return ctx; } -Freeze::TransactionalEvictorContextIPtr +Freeze::TransactionalEvictorContextPtr Freeze::SharedDbEnv::getCurrent() { #ifdef _WIN32 @@ -260,7 +255,7 @@ Freeze::SharedDbEnv::getCurrent() if(val != 0) { - return static_cast<Freeze::TransactionalEvictorContextI*>(val); + return static_cast<TransactionalEvictorContext*>(val); } else { @@ -269,9 +264,42 @@ Freeze::SharedDbEnv::getCurrent() } void -Freeze::SharedDbEnv::clearCurrent(const Freeze::TransactionalEvictorContextIPtr& oldCtx) +Freeze::SharedDbEnv::setCurrentTransaction(const Freeze::TransactionPtr& tx) { - if(getCurrent() == oldCtx) + Freeze::TransactionalEvictorContextPtr ctx = getCurrent(); + + if(ctx != 0) + { + // + // Release thread's refcount + // + ctx->__decRef(); + } + + if(tx != 0) + { + if(ctx == 0 || ctx->transaction().get() != tx.get()) + { + ctx = new TransactionalEvictorContext(TransactionIPtr::dynamicCast(tx)); + +#ifdef _WIN32 + if(TlsSetValue(_tsdKey, ctx.get()) == 0) + { + IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); + } +#else + if(int err = pthread_setspecific(_tsdKey, ctx.get())) + { + throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, err); + } +#endif + // + // Give one refcount to this thread + // + ctx->__incRef(); + } + } + else if(ctx != 0) { #ifdef _WIN32 if(TlsSetValue(_tsdKey, 0) == 0) @@ -284,11 +312,6 @@ Freeze::SharedDbEnv::clearCurrent(const Freeze::TransactionalEvictorContextIPtr& throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, err); } #endif - - // - // Release thread's refcount - // - oldCtx->__decRef(); } } |