tesseract  3.05.02
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 70 of file svutil.h.

Constructor & Destructor Documentation

◆ SVSemaphore()

SVSemaphore::SVSemaphore ( )

Sets up a semaphore.

Definition at line 153 of file svutil.cpp.

153  {
154 #ifdef _WIN32
155  semaphore_ = CreateSemaphore(0, 0, 10, 0);
156 #elif defined(__APPLE__)
157  char name[50];
158  snprintf(name, sizeof(name), "%ld", random());
159  sem_unlink(name);
160  semaphore_ = sem_open(name, O_CREAT , S_IWUSR, 0);
161  if (semaphore_ == SEM_FAILED) {
162  perror("sem_open");
163  }
164 #else
165  sem_init(&semaphore_, 0, 0);
166 #endif
167 }

Member Function Documentation

◆ Signal()

void SVSemaphore::Signal ( )

Signal a semaphore.

Definition at line 169 of file svutil.cpp.

169  {
170 #ifdef _WIN32
171  ReleaseSemaphore(semaphore_, 1, NULL);
172 #elif defined(__APPLE__)
173  sem_post(semaphore_);
174 #else
175  sem_post(&semaphore_);
176 #endif
177 }

◆ Wait()

void SVSemaphore::Wait ( )

Wait on a semaphore.

Definition at line 179 of file svutil.cpp.

179  {
180 #ifdef _WIN32
181  WaitForSingleObject(semaphore_, INFINITE);
182 #elif defined(__APPLE__)
183  sem_wait(semaphore_);
184 #else
185  sem_wait(&semaphore_);
186 #endif
187 }

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