From 69f15d0c5a4c384f1540283023d2a75b6734ae15 Mon Sep 17 00:00:00 2001 From: Ulrich Germann Date: Mon, 8 Jun 2015 13:54:22 +0100 Subject: [PATCH] New member function wait that won't return until sampling is done. --- moses/TranslationModel/UG/mm/ug_bitext_pstats.cc | 14 ++++++++++++-- moses/TranslationModel/UG/mm/ug_bitext_pstats.h | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/moses/TranslationModel/UG/mm/ug_bitext_pstats.cc b/moses/TranslationModel/UG/mm/ug_bitext_pstats.cc index 580d7669b..11e098f6d 100644 --- a/moses/TranslationModel/UG/mm/ug_bitext_pstats.cc +++ b/moses/TranslationModel/UG/mm/ug_bitext_pstats.cc @@ -1,3 +1,4 @@ +#include #include "ug_bitext_pstats.h" namespace Moses @@ -65,7 +66,7 @@ namespace Moses bool pstats:: - add(uint64_t pid, float const w, + add(uint64_t pid, float const w, float const b, vector const& a, uint32_t const cnt2, uint32_t fwd_o, @@ -73,7 +74,7 @@ namespace Moses { boost::lock_guard guard(this->lock); jstats& entry = this->trg[pid]; - entry.add(w, a, cnt2, fwd_o, bwd_o, docid); + entry.add(w, b, a, cnt2, fwd_o, bwd_o, docid); if (this->good < entry.rcnt()) { UTIL_THROW(util::Exception, "more joint counts than good counts:" @@ -82,5 +83,14 @@ namespace Moses return true; } + void + pstats:: + wait() const + { + boost::unique_lock lock(this->lock); + while (this->in_progress) + this->ready.wait(lock); + } + } } diff --git a/moses/TranslationModel/UG/mm/ug_bitext_pstats.h b/moses/TranslationModel/UG/mm/ug_bitext_pstats.h index 9a14e378b..b7cb142fe 100644 --- a/moses/TranslationModel/UG/mm/ug_bitext_pstats.h +++ b/moses/TranslationModel/UG/mm/ug_bitext_pstats.h @@ -21,8 +21,8 @@ namespace Moses #if UG_BITEXT_TRACK_ACTIVE_THREADS static ThreadSafeCounter active; #endif - boost::mutex lock; // for parallel gathering of stats - boost::condition_variable ready; // consumers can wait for me to be ready + mutable boost::mutex lock; // for parallel gathering of stats + mutable boost::condition_variable ready; // consumers can wait for me to be ready size_t raw_cnt; // (approximate) raw occurrence count size_t sample_cnt; // number of instances selected during sampling @@ -46,6 +46,7 @@ namespace Moses bool add(uint64_t const pid, // target phrase id float const w, // sample weight (1./(# of phrases extractable)) + float const b, // sample bias score alnvec const& a, // local alignment uint32_t const cnt2, // raw target phrase count uint32_t fwd_o, // fwd. phrase orientation @@ -57,6 +58,7 @@ namespace Moses size_t const num_pairs, // # of phrases extractable here int const po_fwd, // fwd phrase orientation int const po_bwd); // bwd phrase orientation + void wait() const; }; }