mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-29 06:52:34 +03:00
pthread compatibility issue across platforms
This commit is contained in:
parent
e01b8e26d3
commit
af5ca0fb79
@ -146,26 +146,12 @@ PhraseDictionaryCompact::~PhraseDictionaryCompact() {
|
||||
|
||||
//TO_STRING_BODY(PhraseDictionaryCompact)
|
||||
|
||||
TargetPhraseCollection*
|
||||
PhraseDictionaryCompact::RetrieveFromCache(const Phrase &sourcePhrase) {
|
||||
#ifdef WITH_THREADS
|
||||
boost::mutex::scoped_lock lock(m_sentenceMutex);
|
||||
PhraseCache &ref = m_sentenceCache[pthread_self()];
|
||||
#else
|
||||
PhraseCache &ref = m_sentenceCache;
|
||||
#endif
|
||||
PhraseCache::iterator it = ref.find(sourcePhrase);
|
||||
if(it != ref.end())
|
||||
return it->second;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PhraseDictionaryCompact::CacheForCleanup(const Phrase &sourcePhrase,
|
||||
TargetPhraseCollection* tpc) {
|
||||
#ifdef WITH_THREADS
|
||||
boost::mutex::scoped_lock lock(m_sentenceMutex);
|
||||
m_sentenceCache[pthread_self()].insert(std::make_pair(sourcePhrase, tpc));
|
||||
size_t threadId = findThreadId(pthread_self());
|
||||
m_sentenceCache[threadId].insert(std::make_pair(sourcePhrase, tpc));
|
||||
#else
|
||||
m_sentenceCache.insert(std::make_pair(sourcePhrase, tpc));
|
||||
#endif
|
||||
@ -184,7 +170,8 @@ void PhraseDictionaryCompact::CleanUp() {
|
||||
|
||||
#ifdef WITH_THREADS
|
||||
boost::mutex::scoped_lock lock(m_sentenceMutex);
|
||||
PhraseCache &ref = m_sentenceCache[pthread_self()];
|
||||
size_t threadId = findThreadId(pthread_self());
|
||||
PhraseCache &ref = m_sentenceCache[threadId];
|
||||
#else
|
||||
PhraseCache &ref = m_sentenceCache;
|
||||
#endif
|
||||
|
@ -54,7 +54,17 @@ protected:
|
||||
typedef std::map<Phrase, TargetPhraseCollection*> PhraseCache;
|
||||
#ifdef WITH_THREADS
|
||||
boost::mutex m_sentenceMutex;
|
||||
typedef std::map<_opaque_pthread_t*, PhraseCache> SentenceCache;
|
||||
std::vector<pthread_t> m_threadStore;
|
||||
|
||||
size_t findThreadId(pthread_t t) {
|
||||
size_t size = m_threadStore.size();
|
||||
for(size_t i = 0; i < size; i++)
|
||||
if(pthread_equal(t, m_threadStore[i]))
|
||||
return i;
|
||||
return size;
|
||||
}
|
||||
|
||||
typedef std::map<size_t, PhraseCache> SentenceCache;
|
||||
#else
|
||||
typedef PhraseCache SentenceCache;
|
||||
#endif
|
||||
@ -100,7 +110,6 @@ public:
|
||||
|
||||
void InitializeForInput(const Moses::InputType&);
|
||||
|
||||
TargetPhraseCollection* RetrieveFromCache(const Phrase &sourcePhrase);
|
||||
void CacheForCleanup(const Phrase &source, TargetPhraseCollection* tpc);
|
||||
void CleanUp();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user