semaphore.cc

来自「AVR 单片机程序设计用到的模拟器」· CC 代码 · 共 36 行

CC
36
字号
/* $Id: Semaphore.cc,v 1.2 2000/09/24 13:54:53 pure Exp $ */#include "Semaphore.h"Semaphore::Semaphore() : Mutex(){	if (pthread_cond_init(&cond, NULL))		throw;	value = 0;}	Semaphore::~Semaphore(){	pthread_cond_destroy(&cond);}	void Semaphore::signal(int n){    		value += n;	pthread_cond_signal(&cond);}	void Semaphore::wait(){	lock();	while (value <= 0) 		pthread_cond_wait(&cond, (pthread_mutex_t *) this);	value--;	unlock();}	Semaphore::operator pthread_cond_t* (){	return &cond;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?