sem_sync.h
来自「用于使用moden进行传真的源代码」· C头文件 代码 · 共 48 行
H
48 行
/* 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 + =
减小字号Ctrl + -
显示快捷键?