summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/jdbc/Object.cxx
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2005-01-21 15:42:11 +0000
committerKurt Zenker <kz@openoffice.org>2005-01-21 15:42:11 +0000
commit2b201edea8ffd6444db9cfe22a54886382ebed9b (patch)
tree32e4267038a3afd40b59a31f291dc05493a6973a /connectivity/source/drivers/jdbc/Object.cxx
parent051cd927e93a75ab5fef739c23692bf1e6b1a92e (diff)
INTEGRATION: CWS dba22 (1.18.16); FILE MERGED
2005/01/14 12:35:22 oj 1.18.16.3: #i39671# attachguard for every call 2005/01/10 06:29:19 oj 1.18.16.2: compile error under linux 2005/01/04 11:45:21 oj 1.18.16.1: #i39671# erase guard when no longer needed
Diffstat (limited to 'connectivity/source/drivers/jdbc/Object.cxx')
-rw-r--r--connectivity/source/drivers/jdbc/Object.cxx44
1 files changed, 14 insertions, 30 deletions
diff --git a/connectivity/source/drivers/jdbc/Object.cxx b/connectivity/source/drivers/jdbc/Object.cxx
index eb5243364c..64f4771b43 100644
--- a/connectivity/source/drivers/jdbc/Object.cxx
+++ b/connectivity/source/drivers/jdbc/Object.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Object.cxx,v $
*
- * $Revision: 1.18 $
+ * $Revision: 1.19 $
*
- * last change: $Author: hr $ $Date: 2004-11-09 12:12:58 $
+ * last change: $Author: kz $ $Date: 2005-01-21 16:42:11 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -114,54 +114,34 @@ using namespace ::com::sun::star::lang;
return xVM;
}
// -----------------------------------------------------------------------------
-typedef ::std::map<oslThreadIdentifier,TGuard> TGuardMap;
-TGuardMap& lcl_getGuardMap()
-{
- static TGuardMap s_sMap;
- return s_sMap;
-}
-// -----------------------------------------------------------------------------
-TGuard getVMGuard()
-{
- TGuardMap& s_sMap = lcl_getGuardMap();
-
- oslThreadIdentifier id = osl_getThreadIdentifier(NULL);
- TGuardMap::iterator aFind = s_sMap.find(id);
- if ( aFind == s_sMap.end() )
- aFind = s_sMap.insert(TGuardMap::value_type(id,TGuard(new jvmaccess::VirtualMachine::AttachGuard(java_lang_Object::getVM())))).first;
- return aFind->second;
-}
-// -----------------------------------------------------------------------------
SDBThreadAttach::SDBThreadAttach()
- : pEnv(NULL)
+ : m_aGuard(java_lang_Object::getVM())
+ , pEnv(NULL)
{
- m_aGuard = getVMGuard();
- if ( m_aGuard.get() )
- pEnv = m_aGuard->getEnvironment();
+ pEnv = m_aGuard.getEnvironment();
+ OSL_ENSURE(pEnv,"Environment is nULL!");
}
// -----------------------------------------------------------------------------
SDBThreadAttach::~SDBThreadAttach()
{
}
// -----------------------------------------------------------------------------
-sal_Int32& getJavaVMRefCount()
+oslInterlockedCount& getJavaVMRefCount()
{
- static sal_Int32 s_nRefCount = 0;
+ static oslInterlockedCount s_nRefCount = 0;
return s_nRefCount;
}
// -----------------------------------------------------------------------------
void SDBThreadAttach::addRef()
{
- getJavaVMRefCount()++;
+ osl_incrementInterlockedCount(&getJavaVMRefCount());
}
// -----------------------------------------------------------------------------
void SDBThreadAttach::releaseRef()
{
- getJavaVMRefCount()--;
+ osl_decrementInterlockedCount(&getJavaVMRefCount());
if ( getJavaVMRefCount() == 0 )
{
- TGuardMap& s_sMap = lcl_getGuardMap();
- s_sMap.clear();
getJavaVM2(::rtl::Reference< jvmaccess::VirtualMachine >(),sal_True);
}
}
@@ -186,12 +166,14 @@ jclass java_lang_Object::getMyClass()
java_lang_Object::java_lang_Object(const Reference<XMultiServiceFactory >& _rxFactory)
: object( 0 ),m_xFactory(_rxFactory)
{
+ SDBThreadAttach::addRef();
}
// der protected-Konstruktor fuer abgeleitete Klassen
java_lang_Object::java_lang_Object( JNIEnv * pXEnv, jobject myObj )
: object( NULL )
{
+ SDBThreadAttach::addRef();
if( pXEnv && myObj )
object = pXEnv->NewGlobalRef( myObj );
}
@@ -203,7 +185,9 @@ java_lang_Object::~java_lang_Object()
SDBThreadAttach t;
if( t.pEnv )
t.pEnv->DeleteGlobalRef( object );
+ object = NULL;
}
+ SDBThreadAttach::releaseRef();
}
void java_lang_Object::clearObject(JNIEnv& rEnv)
{