tesseract  5.0.0
tesseract::SVSemaphore Class Reference

#include <svutil.h>

Public Member Functions

 SVSemaphore ()
 Sets up a semaphore. More...
 
 ~SVSemaphore ()
 Cleans up the mutex. More...
 
void Signal ()
 Signal a semaphore. More...
 
void Wait ()
 Wait on a semaphore. More...
 

Detailed Description

A semaphore class which encapsulates the main signaling and wait abilities of semaphores for windows and unix.

Definition at line 46 of file svutil.h.

Constructor & Destructor Documentation

◆ SVSemaphore()

tesseract::SVSemaphore::SVSemaphore ( )

Sets up a semaphore.

Definition at line 118 of file svutil.cpp.

118  {
119 # ifdef _WIN32
120  semaphore_ = CreateSemaphore(0, 0, 10, 0);
121 # elif defined(__APPLE__)
122  auto name = std::to_string(random());
123  sem_unlink(name.c_str());
124  semaphore_ = sem_open(name.c_str(), O_CREAT, S_IWUSR, 0);
125  if (semaphore_ == SEM_FAILED) {
126  perror("sem_open");
127  }
128 # else
129  sem_init(&semaphore_, 0, 0);
130 # endif
131 }

◆ ~SVSemaphore()

tesseract::SVSemaphore::~SVSemaphore ( )

Cleans up the mutex.

Definition at line 133 of file svutil.cpp.

133  {
134 # ifdef _WIN32
135  CloseHandle(semaphore_);
136 # elif defined(__APPLE__)
137  sem_close(semaphore_);
138 # else
139  sem_close(&semaphore_);
140 # endif
141 }

Member Function Documentation

◆ Signal()

void tesseract::SVSemaphore::Signal ( )

Signal a semaphore.

Definition at line 143 of file svutil.cpp.

143  {
144 # ifdef _WIN32
145  ReleaseSemaphore(semaphore_, 1, nullptr);
146 # elif defined(__APPLE__)
147  sem_post(semaphore_);
148 # else
149  sem_post(&semaphore_);
150 # endif
151 }

◆ Wait()

void tesseract::SVSemaphore::Wait ( )

Wait on a semaphore.

Definition at line 153 of file svutil.cpp.

153  {
154 # ifdef _WIN32
155  WaitForSingleObject(semaphore_, INFINITE);
156 # elif defined(__APPLE__)
157  sem_wait(semaphore_);
158 # else
159  sem_wait(&semaphore_);
160 # endif
161 }

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