📄 sem_sync.h
字号:
/* Copyright (C) 2004 Chris VineThis program is distributed under the General Public Licence, version 2.For particulars of this and relevant disclaimers see the fileCOPYING distributed with the source files.*/#ifndef SEM_SYNC_H#define SEM_SYNC_H#include "prog_defs.h"#include <semaphore.h>class Sem_sync { bool valid; sem_t sem;public: bool is_valid(void) const {return valid;} int getvalue(void); int post(void) {return sem_post(&sem);} void wait(void) {sem_wait(&sem);} Sem_sync(unsigned int init_count = 0); ~Sem_sync(void);};inline int Sem_sync::getvalue(void) { int count; sem_getvalue(&sem, &count); return count;}inline Sem_sync::Sem_sync(unsigned int init_count): valid(false) { if(sem_init(&sem, 0, init_count) == 0) valid = true;}inline Sem_sync::~Sem_sync(void) { while (!getvalue()) post(); sem_destroy(&sem);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -