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

📄 wymutex.h

📁 一个不错
💻 H
字号:
/* Copyright is licensed under GNU LGPL.                 by I.J.Wang 2003   WyMutex provides serializing access of codes between threads.*/#ifndef WYMUTEX_H__#define WYMUTEX_H__#define WYMUTEX_VERSION 31#include "wyret.h"#include <pthread.h>#include <signal.h>   // for sig_atomic_t/*  Note: Operation of WyMutex is often done by the proxy WyLock.         Refer to WyLock.*/class WyMutex {  public:    static const char class_name[];    WY_THROW_REPLY;  // declaraion of Reply    // [Syn] Enumeration of the mutex type    //    enum MutexType { Fast=0,ErrorCheck,Recursive };    explicit  // no implicit conversion    WyMutex(MutexType t=Fast) WY__TSPC(Reply);    ~WyMutex() WY__TSPC();    WyRet lock(void) WY__TSPC();    WyRet trylock(void) WY__TSPC();    WyRet unlock(void) WY__TSPC();    static void lock(WyMutex &mtx) WY__TSPC(Reply);    static void trylock(WyMutex &mtx) WY__TSPC(Reply);    static void unlock(WyMutex &mtx) WY__TSPC(Reply);    ;    ::pthread_mutex_t* wy_mutex_ptr(void) WY__TSPC();  private:   #ifndef NDEBUG    volatile sig_atomic_t _sig; // For check object is valid or not   #endif    ::pthread_mutex_t _mtx;     friend class WyCond;    // WyCond needs to access _mtx directly    // Hidden members    WyMutex(const WyMutex&);    const WyMutex& operator =(const WyMutex&);    bool operator==(const WyMutex&) const;};class WyLock {  public:    static const char class_name[];    WY_THROW_REPLY;  // declaraion of Reply    explicit WyLock(WyMutex& mtx) WY__TSPC(Reply);    ~WyLock() WY__TSPC();    WyRet xlock(WyMutex& mtx);  private:    WyMutex *_pmtx;    friend class WyCond;      // WyCond needs to access _pmtx directly    // Hidden members    WyLock();    WyLock(const WyLock&);    const WyLock &operator=(const WyLock&);    bool operator==(const WyLock&) const;    void* operator new(size_t);};#endif

⌨️ 快捷键说明

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