countingsemaphore.cpp
来自「Generic template class library for messa」· C++ 代码 · 共 58 行
CPP
58 行
#include "CountingSemaphore.h"#include <cassert>CountingSemaphore::CountingSemaphore( unsigned long value){ int sysCallResult; sysCallResult = sem_init( &posixSemaphore, 0, value ); assert( sysCallResult != -1 );}CountingSemaphore::~CountingSemaphore(){ int sysCallResult; sysCallResult = sem_destroy( &posixSemaphore ); assert( sysCallResult != -1 );}void CountingSemaphore::post(){ int sysCallResult; sysCallResult = sem_post( &posixSemaphore ); assert( sysCallResult != -1 );}void CountingSemaphore::wait(){ int sysCallResult; sysCallResult = sem_wait( &posixSemaphore ); assert( sysCallResult != -1 );}bool CountingSemaphore::trywait(){ int sysCallResult; bool returnValue; sysCallResult = sem_wait( &posixSemaphore ); if ( sysCallResult == 0 ) { returnValue = true; } else { returnValue = false; } return returnValue;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?