interface/semaphore

This commit is contained in:
Perttu Ahola 2014-10-18 14:49:05 +03:00
parent ec0dee89a1
commit 62d3c66760
2 changed files with 33 additions and 0 deletions

View File

@ -102,6 +102,7 @@ set(BUILDAT_CORE_SRCS
src/impl/noise.cpp
src/impl/voxel_volume.cpp
src/impl/compress.cpp
src/impl/worker_thread.cpp
)
if(WIN32)
set(BUILDAT_CORE_SRCS ${BUILDAT_CORE_SRCS} src/impl/windows/file_watch.cpp)

32
src/interface/semaphore.h Normal file
View File

@ -0,0 +1,32 @@
// http://www.apache.org/licenses/LICENSE-2.0
// Copyright 2014 Perttu Ahola <celeron55@gmail.com>
#pragma once
#include "core/types.h"
#ifdef _WIN32
#include "ports/windows_compat.h"
#else
#include <semaphore.h>
#endif
namespace interface
{
struct Semaphore
{
sem_t sem;
Semaphore(unsigned int value = 0){
sem_init(&sem, 0, value);
}
~Semaphore(){
sem_destroy(&sem);
}
void wait(){
sem_wait(&sem);
}
void post(){
sem_post(&sem);
}
};
}
// vim: set noet ts=4 sw=4: