Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Bertoldi <bertoldi@fbk.eu>2015-05-04 10:42:44 +0300
committerNicola Bertoldi <bertoldi@fbk.eu>2015-05-04 10:42:44 +0300
commit90a982e579cf97914531b4d595e11c303baae179 (patch)
tree5860799c9182712aecc57b4bcbb478908195be7e /moses/ContextScope.h
parentc4f04670c2a0a89a1fe7f6c657f2e07ecbfbb0c9 (diff)
parent2b671e67dd59a47107ab75a963dd26a1571ebb16 (diff)
merge remote into local
Diffstat (limited to 'moses/ContextScope.h')
-rw-r--r--moses/ContextScope.h50
1 files changed, 28 insertions, 22 deletions
diff --git a/moses/ContextScope.h b/moses/ContextScope.h
index c01489848..5adaadf3c 100644
--- a/moses/ContextScope.h
+++ b/moses/ContextScope.h
@@ -18,8 +18,8 @@
namespace Moses
{
- class ContextScope
- {
+class ContextScope
+{
protected:
typedef std::map<void const*, boost::shared_ptr<void> > scratchpad_t;
typedef scratchpad_t::iterator iter_t;
@@ -35,20 +35,20 @@ namespace Moses
// boost::unique_lock<boost::shared_mutex> m_lock;
// public:
- // write_access(boost::shared_mutex& lock)
- // : m_lock(lock)
- // { }
+ // write_access(boost::shared_mutex& lock)
+ // : m_lock(lock)
+ // { }
- // write_access(write_access& other)
- // {
- // swap(m_lock, other.m_lock);
- // }
- // };
+ // write_access(write_access& other)
+ // {
+ // swap(m_lock, other.m_lock);
+ // }
+ // };
- // write_access lock() const
- // {
- // return write_access(m_lock);
- // }
+ // write_access lock() const
+ // {
+ // return write_access(m_lock);
+ // }
template<typename T>
boost::shared_ptr<void> const&
@@ -92,18 +92,24 @@ namespace Moses
m_scratchpad[key] = ret;
return ret;
}
+ if (!CreateNewIfNecessary) return ret;
+ boost::upgrade_to_unique_lock<shared_mutex> xlock(lock);
+ ret.reset(new T);
+ m_scratchpad[key] = ret;
+ return ret;
+ }
- ContextScope() { }
+ ContextScope() { }
- ContextScope(ContextScope const& other)
- {
+ ContextScope(ContextScope const& other)
+ {
#ifdef WITH_THREADS
- boost::unique_lock<boost::shared_mutex> lock1(this->m_lock);
- boost::unique_lock<boost::shared_mutex> lock2(other.m_lock);
+ boost::unique_lock<boost::shared_mutex> lock1(this->m_lock);
+ boost::unique_lock<boost::shared_mutex> lock2(other.m_lock);
#endif
- m_scratchpad = other.m_scratchpad;
- }
+ m_scratchpad = other.m_scratchpad;
+ }
- };
+};
};