wymutex.h

来自「一个不错」· C头文件 代码 · 共 81 行

H
81 行
字号
/* 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 + =
减小字号Ctrl + -
显示快捷键?