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

📄 ptrigger.cxx

📁 PTypes是一个扩充了多线程和网络功能的STL库
💻 CXX
字号:
/* * *  C++ Portable Types Library (PTypes) *  Version 2.0.2  Released 17-May-2004 * *  Copyright (C) 2001-2004 Hovik Melikyan * *  http://www.melikyan.com/ptypes/ * */#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 trig_syscheck(int r){    if (r != 0)        trig_fail();}trigger::trigger(bool iautoreset, bool istate)    : state(int(istate)), autoreset(iautoreset){    trig_syscheck(pthread_mutex_init(&mtx, 0));    trig_syscheck(pthread_cond_init(&cond, 0));}trigger::~trigger(){    pthread_cond_destroy(&cond);    pthread_mutex_destroy(&mtx);}void trigger::wait(){    pthread_mutex_lock(&mtx);    while (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 + -