kaldi-semaphore.cc
Go to the documentation of this file.
1 // util/kaldi-semaphore.cc
2 
3 // Copyright 2012 Karel Vesely (Brno University of Technology)
4 // 2017 Dogan Can (University of Southern California)
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 
22 
23 #include "base/kaldi-error.h"
24 #include "util/kaldi-semaphore.h"
25 
26 namespace kaldi {
27 
29  KALDI_ASSERT(count >= 0);
30  count_ = count;
31 }
32 
34 
36  std::unique_lock<std::mutex> lock(mutex_);
37  if(count_) {
38  count_--;
39  return true;
40  }
41  return false;
42 }
43 
45  std::unique_lock<std::mutex> lock(mutex_);
46  while(!count_)
47  condition_variable_.wait(lock);
48  count_--;
49 }
50 
52  std::unique_lock<std::mutex> lock(mutex_);
53  count_++;
54  condition_variable_.notify_one();
55 }
56 
57 } // namespace kaldi
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Signal()
increase the counter
kaldi::int32 int32
Semaphore(int32 count=0)
bool TryWait()
Returns true if Wait() goes through.
const size_t count
int32 count_
the semaphore counter, 0 means block on Wait()
std::condition_variable condition_variable_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void Wait()
decrease the counter