All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 67 of file svutil.h.

Constructor & Destructor Documentation

SVSemaphore::SVSemaphore ( )

Sets up a semaphore.

Definition at line 125 of file svutil.cpp.

125  {
126 #ifdef _WIN32
127  semaphore_ = CreateSemaphore(0, 0, 10, 0);
128 #elif defined(__APPLE__)
129  char name[50];
130  snprintf(name, sizeof(name), "%d", random());
131  sem_unlink(name);
132  semaphore_ = sem_open(name, O_CREAT , S_IWUSR, 0);
133  if (semaphore_ == SEM_FAILED) {
134  perror("sem_open");
135  }
136 #else
137  sem_init(&semaphore_, 0, 0);
138 #endif
139 }
name_table name

Member Function Documentation

void SVSemaphore::Signal ( )

Signal a semaphore.

Definition at line 141 of file svutil.cpp.

141  {
142 #ifdef _WIN32
143  ReleaseSemaphore(semaphore_, 1, NULL);
144 #elif defined(__APPLE__)
145  sem_post(semaphore_);
146 #else
147  sem_post(&semaphore_);
148 #endif
149 }
#define NULL
Definition: host.h:144
void SVSemaphore::Wait ( )

Wait on a semaphore.

Definition at line 151 of file svutil.cpp.

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

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