⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptrigger.cxx

📁 PTypes (C++ Portable Types Library) is a simple alternative to the STL that includes multithreading
💻 CXX
字号:
/* * *  C++ Portable Types Library (PTypes) *  Version 1.7.5   Released 9-Mar-2003 * *  Copyright (c) 2001, 2002, 2003 Hovik Melikyan * *  http://www.melikyan.com/ptypes/ *  http://ptypes.sourceforge.net/ * */#ifdef WIN32#  include <windows.h>#else#  include <sys/time.h>#  include <pthread.h>#  include <errno.h>#endif#include "pasync.h"PTYPES_BEGINstatic void trig_fail(){    fatal(CRIT_FIRST + 41, "Trigger failed");}#ifdef WIN32trigger::trigger(bool autoreset, bool state){    handle = CreateEvent(0, !autoreset, state, 0);    if (handle == 0)        trig_fail();}#elseinline void syscheck(int r){    if (r != 0)        trig_fail();}trigger::trigger(bool iautoreset, bool istate)    : state(int(istate)), autoreset(iautoreset){    syscheck(pthread_mutex_init(&mtx, 0));    syscheck(pthread_cond_init(&cond, 0));}trigger::~trigger(){    pthread_cond_destroy(&cond);    pthread_mutex_destroy(&mtx);}void trigger::wait(){    pthread_mutex_lock(&mtx);    if (state == 0)        pthread_cond_wait(&cond, &mtx);    if (autoreset)	state = 0;    pthread_mutex_unlock(&mtx);} void trigger::post(){    pthread_mutex_lock(&mtx);    state = 1;    if (autoreset)        pthread_cond_signal(&cond);    else        pthread_cond_broadcast(&cond);    pthread_mutex_unlock(&mtx);}void trigger::reset(){    state = 0;}#endifPTYPES_END

⌨️ 快捷键说明

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