Semaphore Class Reference

#include <kaldi-semaphore.h>

Collaboration diagram for Semaphore:

Public Member Functions

 Semaphore (int32 count=0)
 
 ~Semaphore ()
 
bool TryWait ()
 Returns true if Wait() goes through. More...
 
void Wait ()
 decrease the counter More...
 
void Signal ()
 increase the counter More...
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (Semaphore)
 

Private Attributes

int32 count_
 the semaphore counter, 0 means block on Wait() More...
 
std::mutex mutex_
 
std::condition_variable condition_variable_
 

Detailed Description

Definition at line 30 of file kaldi-semaphore.h.

Constructor & Destructor Documentation

◆ Semaphore()

Semaphore ( int32  count = 0)

Definition at line 28 of file kaldi-semaphore.cc.

References count, Semaphore::count_, and KALDI_ASSERT.

28  {
29  KALDI_ASSERT(count >= 0);
30  count_ = count;
31 }
const size_t count
int32 count_
the semaphore counter, 0 means block on Wait()
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ~Semaphore()

~Semaphore ( )

Definition at line 33 of file kaldi-semaphore.cc.

33 {}

Member Function Documentation

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( Semaphore  )
private

◆ Signal()

◆ TryWait()

bool TryWait ( )

Returns true if Wait() goes through.

Definition at line 35 of file kaldi-semaphore.cc.

References Semaphore::count_, and Semaphore::mutex_.

Referenced by NnetBatchInference::GetOutput().

35  {
36  std::unique_lock<std::mutex> lock(mutex_);
37  if(count_) {
38  count_--;
39  return true;
40  }
41  return false;
42 }
int32 count_
the semaphore counter, 0 means block on Wait()

◆ Wait()

Member Data Documentation

◆ condition_variable_

std::condition_variable condition_variable_
private

Definition at line 44 of file kaldi-semaphore.h.

Referenced by Semaphore::Signal(), and Semaphore::Wait().

◆ count_

int32 count_
private

the semaphore counter, 0 means block on Wait()

Definition at line 41 of file kaldi-semaphore.h.

Referenced by Semaphore::Semaphore(), Semaphore::Signal(), Semaphore::TryWait(), and Semaphore::Wait().

◆ mutex_

std::mutex mutex_
private

Definition at line 43 of file kaldi-semaphore.h.

Referenced by Semaphore::Signal(), Semaphore::TryWait(), and Semaphore::Wait().


The documentation for this class was generated from the following files: