tesseract  4.0.0-1-g2a2b
SVSemaphore Class Reference

#include <svutil.h>

Public Member Functions

 SVSemaphore ()
 Sets up a semaphore. More...
 
void Signal ()
 Signal a semaphore. More...
 
void Wait ()
 Wait on a semaphore. More...
 

Detailed Description

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

Definition at line 58 of file svutil.h.

Constructor & Destructor Documentation

◆ SVSemaphore()

SVSemaphore::SVSemaphore ( )

Sets up a semaphore.

Definition at line 172 of file svutil.cpp.

172  {
173 #ifdef _WIN32
174  semaphore_ = CreateSemaphore(0, 0, 10, 0);
175 #elif defined(__APPLE__)
176  char name[50];
177  snprintf(name, sizeof(name), "%ld", random());
178  sem_unlink(name);
179  semaphore_ = sem_open(name, O_CREAT , S_IWUSR, 0);
180  if (semaphore_ == SEM_FAILED) {
181  perror("sem_open");
182  }
183 #else
184  sem_init(&semaphore_, 0, 0);
185 #endif
186 }

Member Function Documentation

◆ Signal()

void SVSemaphore::Signal ( )

Signal a semaphore.

Definition at line 188 of file svutil.cpp.

188  {
189 #ifdef _WIN32
190  ReleaseSemaphore(semaphore_, 1, nullptr);
191 #elif defined(__APPLE__)
192  sem_post(semaphore_);
193 #else
194  sem_post(&semaphore_);
195 #endif
196 }

◆ Wait()

void SVSemaphore::Wait ( )

Wait on a semaphore.

Definition at line 198 of file svutil.cpp.

198  {
199 #ifdef _WIN32
200  WaitForSingleObject(semaphore_, INFINITE);
201 #elif defined(__APPLE__)
202  sem_wait(semaphore_);
203 #else
204  sem_wait(&semaphore_);
205 #endif
206 }

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