diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-05-02 13:45:24 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-05-02 13:45:24 +0300 |
commit | cc8c6b7b10abd8118014635609f7658f6a7a1857 (patch) | |
tree | cab374bcbf73ff97782e9131380e4f32dbeb1e67 /moses/ContextScope.h | |
parent | a4a7c14593766ab188e1d6ae1c29e67ed201d412 (diff) |
beautify
Diffstat (limited to 'moses/ContextScope.h')
-rw-r--r-- | moses/ContextScope.h | 125 |
1 files changed, 60 insertions, 65 deletions
diff --git a/moses/ContextScope.h b/moses/ContextScope.h index ed9f854ff..e9edf7b15 100644 --- a/moses/ContextScope.h +++ b/moses/ContextScope.h @@ -18,80 +18,75 @@ namespace Moses { - class ContextScope - { - protected: - typedef std::map<void const*, boost::shared_ptr<void> > scratchpad_t; - typedef scratchpad_t::iterator iter_t; - typedef scratchpad_t::value_type entry_t; - typedef scratchpad_t::const_iterator const_iter_t; - scratchpad_t m_scratchpad; - mutable boost::shared_mutex m_lock; - public: - // class write_access - // { - // boost::unique_lock<boost::shared_mutex> m_lock; - // public: +class ContextScope +{ +protected: + typedef std::map<void const*, boost::shared_ptr<void> > scratchpad_t; + typedef scratchpad_t::iterator iter_t; + typedef scratchpad_t::value_type entry_t; + typedef scratchpad_t::const_iterator const_iter_t; + scratchpad_t m_scratchpad; + mutable boost::shared_mutex m_lock; +public: + // class write_access + // { + // 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& - set(void const* const key, boost::shared_ptr<T> const& val) - { - boost::unique_lock<boost::shared_mutex> lock(m_lock); - return (m_scratchpad[key] = val); - } + template<typename T> + boost::shared_ptr<void> const& + set(void const* const key, boost::shared_ptr<T> const& val) { + boost::unique_lock<boost::shared_mutex> lock(m_lock); + return (m_scratchpad[key] = val); + } - template<typename T> - boost::shared_ptr<T> const - get(void const* key, bool CreateNewIfNecessary=false) - { - using boost::shared_mutex; - using boost::upgrade_lock; - // T const* key = reinterpret_cast<T const*>(xkey); - upgrade_lock<shared_mutex> lock(m_lock); - iter_t m = m_scratchpad.find(key); - boost::shared_ptr< T > ret; - if (m != m_scratchpad.end()) - { - if (m->second == NULL && CreateNewIfNecessary) - { - boost::upgrade_to_unique_lock<shared_mutex> xlock(lock); - m->second.reset(new T); - } - ret = boost::static_pointer_cast< T >(m->second); - return ret; - } - if (!CreateNewIfNecessary) return ret; - boost::upgrade_to_unique_lock<shared_mutex> xlock(lock); - ret.reset(new T); - m_scratchpad[key] = ret; + template<typename T> + boost::shared_ptr<T> const + get(void const* key, bool CreateNewIfNecessary=false) { + using boost::shared_mutex; + using boost::upgrade_lock; + // T const* key = reinterpret_cast<T const*>(xkey); + upgrade_lock<shared_mutex> lock(m_lock); + iter_t m = m_scratchpad.find(key); + boost::shared_ptr< T > ret; + if (m != m_scratchpad.end()) { + if (m->second == NULL && CreateNewIfNecessary) { + boost::upgrade_to_unique_lock<shared_mutex> xlock(lock); + m->second.reset(new T); + } + ret = boost::static_pointer_cast< T >(m->second); 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) - { - boost::unique_lock<boost::shared_mutex> lock1(this->m_lock); - boost::unique_lock<boost::shared_mutex> lock2(other.m_lock); - m_scratchpad = other.m_scratchpad; - } + ContextScope(ContextScope const& other) { + boost::unique_lock<boost::shared_mutex> lock1(this->m_lock); + boost::unique_lock<boost::shared_mutex> lock2(other.m_lock); + m_scratchpad = other.m_scratchpad; + } - }; +}; }; |