mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
Fix locking in AlignmentInfoCollection.*
This commit is contained in:
parent
b317522563
commit
bac859c451
@ -1 +0,0 @@
|
||||
/usr/share/automake-1.9/INSTALL
|
@ -1 +0,0 @@
|
||||
/usr/share/automake-1.10/COPYING
|
@ -1 +0,0 @@
|
||||
/usr/share/automake-1.10/INSTALL
|
@ -38,8 +38,18 @@ const AlignmentInfo &AlignmentInfoCollection::GetEmptyAlignmentInfo() const
|
||||
const AlignmentInfo *AlignmentInfoCollection::Add(
|
||||
const std::set<std::pair<size_t,size_t> > &pairs)
|
||||
{
|
||||
AlignmentInfo pairsAlignmentInfo(pairs);
|
||||
#ifdef WITH_THREADS
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> read_lock(m_accessLock);
|
||||
AlignmentInfoSet::const_iterator i = m_collection.find(pairsAlignmentInfo);
|
||||
if (i != m_collection.end())
|
||||
return &*i;
|
||||
}
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_accessLock);
|
||||
#endif
|
||||
std::pair<AlignmentInfoSet::iterator, bool> ret =
|
||||
m_collection.insert(AlignmentInfo(pairs));
|
||||
m_collection.insert(pairsAlignmentInfo);
|
||||
return &(*ret.first);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,11 @@
|
||||
|
||||
#include <set>
|
||||
|
||||
#ifdef WITH_THREADS
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#endif
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
@ -52,6 +57,12 @@ class AlignmentInfoCollection
|
||||
AlignmentInfoCollection();
|
||||
|
||||
static AlignmentInfoCollection s_instance;
|
||||
|
||||
#ifdef WITH_THREADS
|
||||
//reader-writer lock
|
||||
mutable boost::shared_mutex m_accessLock;
|
||||
#endif
|
||||
|
||||
AlignmentInfoSet m_collection;
|
||||
const AlignmentInfo *m_emptyAlignmentInfo;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user