tesseract  5.0.0-alpha-619-ge9db
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 signaling and wait abilities of semaphores for windows and unix.

Definition at line 44 of file svutil.h.

Constructor & Destructor Documentation

◆ SVSemaphore()

SVSemaphore::SVSemaphore ( )

Sets up a semaphore.

Definition at line 112 of file svutil.cpp.

112  {
113 #ifdef _WIN32
114  semaphore_ = CreateSemaphore(0, 0, 10, 0);
115 #elif defined(__APPLE__)
116  char name[50];
117  snprintf(name, sizeof(name), "%ld", random());
118  sem_unlink(name);
119  semaphore_ = sem_open(name, O_CREAT , S_IWUSR, 0);
120  if (semaphore_ == SEM_FAILED) {
121  perror("sem_open");
122  }
123 #else
124  sem_init(&semaphore_, 0, 0);
125 #endif
126 }

Member Function Documentation

◆ Signal()

void SVSemaphore::Signal ( )

Signal a semaphore.

Definition at line 128 of file svutil.cpp.

128  {
129 #ifdef _WIN32
130  ReleaseSemaphore(semaphore_, 1, nullptr);
131 #elif defined(__APPLE__)
132  sem_post(semaphore_);
133 #else
134  sem_post(&semaphore_);
135 #endif
136 }

◆ Wait()

void SVSemaphore::Wait ( )

Wait on a semaphore.

Definition at line 138 of file svutil.cpp.

138  {
139 #ifdef _WIN32
140  WaitForSingleObject(semaphore_, INFINITE);
141 #elif defined(__APPLE__)
142  sem_wait(semaphore_);
143 #else
144  sem_wait(&semaphore_);
145 #endif
146 }

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