mirror of
https://bitbucket.org/theswgsource/src-1.2.git
synced 2026-08-01 02:15:54 -04:00
41 lines
736 B
C++
Executable File
41 lines
736 B
C++
Executable File
// ======================================================================
|
|
//
|
|
// Semaphore.cpp
|
|
// Acy Stapp
|
|
//
|
|
// Copyright 6/19/2001 Sony Online Entertainment
|
|
//
|
|
// ======================================================================
|
|
|
|
#include "sharedFoundation/FirstSharedFoundation.h"
|
|
#include "sharedSynchronization/Semaphore.h"
|
|
|
|
Semaphore::Semaphore(int count, int initial)
|
|
{
|
|
sem_init(&sem, false, initial);
|
|
}
|
|
|
|
Semaphore::~Semaphore()
|
|
{
|
|
sem_destroy(&sem);
|
|
}
|
|
|
|
void Semaphore::wait()
|
|
{
|
|
sem_wait(&sem);
|
|
}
|
|
|
|
void Semaphore::wait(unsigned int maxDurationMs)
|
|
{
|
|
timespec ts;
|
|
ts.tv_sec = maxDurationMs/1000000;
|
|
ts.tv_nsec = maxDurationMs%1000000;
|
|
sem_timedwait(&sem, &ts);
|
|
}
|
|
|
|
void Semaphore::signal(int count)
|
|
{
|
|
sem_post(&sem);
|
|
}
|
|
|