Kaydet (Commit) cf575ec1 authored tarafından Caolán McNamara's avatar Caolán McNamara

give me a deterministic ctor/dtor ordering I can trust, and defer to first use

üst 31ff4439
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "cppu/EnvDcp.hxx" #include "cppu/EnvDcp.hxx"
#include "cppu/Enterable.hxx" #include "cppu/Enterable.hxx"
#include "rtl/instance.hxx"
#include "osl/thread.h" #include "osl/thread.h"
#include "osl/mutex.hxx" #include "osl/mutex.hxx"
...@@ -68,9 +70,11 @@ typedef ::std::hash_map<oslThreadIdentifier, ...@@ -68,9 +70,11 @@ typedef ::std::hash_map<oslThreadIdentifier,
oslThreadIdentifier_hash, oslThreadIdentifier_hash,
oslThreadIdentifier_equal> ThreadMap; oslThreadIdentifier_equal> ThreadMap;
static osl::Mutex s_threadMap_mutex; namespace
static ThreadMap s_threadMap; {
struct s_threadMap_mutex : public rtl::Static< osl::Mutex, s_threadMap_mutex > {};
struct s_threadMap : public rtl::Static< ThreadMap, s_threadMap > {};
}
static rtl::OUString s_uno_envDcp(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO)); static rtl::OUString s_uno_envDcp(RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO));
...@@ -78,14 +82,15 @@ static void s_setCurrent(uno_Environment * pEnv) ...@@ -78,14 +82,15 @@ static void s_setCurrent(uno_Environment * pEnv)
{ {
oslThreadIdentifier threadId = osl_getThreadIdentifier(NULL); oslThreadIdentifier threadId = osl_getThreadIdentifier(NULL);
osl::MutexGuard guard(s_threadMap_mutex); osl::MutexGuard guard(s_threadMap_mutex::get());
ThreadMap &rThreadMap = s_threadMap::get();
if (pEnv) if (pEnv)
s_threadMap[threadId] = pEnv; rThreadMap[threadId] = pEnv;
else else
{ {
ThreadMap::iterator iEnv = s_threadMap.find(threadId); ThreadMap::iterator iEnv = rThreadMap.find(threadId);
s_threadMap.erase(iEnv); rThreadMap.erase(iEnv);
} }
} }
...@@ -95,9 +100,10 @@ static uno_Environment * s_getCurrent(void) ...@@ -95,9 +100,10 @@ static uno_Environment * s_getCurrent(void)
oslThreadIdentifier threadId = osl_getThreadIdentifier(NULL); oslThreadIdentifier threadId = osl_getThreadIdentifier(NULL);
osl::MutexGuard guard(s_threadMap_mutex); osl::MutexGuard guard(s_threadMap_mutex::get());
ThreadMap::iterator iEnv = s_threadMap.find(threadId); ThreadMap &rThreadMap = s_threadMap::get();
if(iEnv != s_threadMap.end()) ThreadMap::iterator iEnv = rThreadMap.find(threadId);
if(iEnv != rThreadMap.end())
pEnv = iEnv->second; pEnv = iEnv->second;
return pEnv; return pEnv;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment