全部博文(330)
分类:
2010-12-16 20:49:37
典型的锁哨宏用法
ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
ACE_SYNCH_MUTEX定义在下面的文件中
Synch_T.h
同步对象宏定义,
主要提供typedef统一多线程同步定义
class ACE_Export ACE_MT_SYNCH
{
public:
typedef ACE_Thread_Mutex MUTEX; //线程互斥锁
typedef ACE_Null_Mutex NULL_MUTEX; //空互斥锁
typedef ACE_Process_Mutex PROCESS_MUTEX; // 进程互斥锁
typedef ACE_Recursive_Thread_Mutex RECURSIVE_MUTEX; // 线程递归互斥锁
typedef ACE_RW_Thread_Mutex RW_MUTEX; //线程读写锁
typedef ACE_Condition_Thread_Mutex CONDITION;//线程条件互斥锁
typedef ACE_Condition_Recursive_Thread_Mutex RECURSIVE_CONDITION; //线程条件互斥递归锁
typedef ACE_Thread_Semaphore SEMAPHORE; // 线程信号量
typedef ACE_Null_Semaphore NULL_SEMAPHORE; //空信号量
};
ACE#define同步对象的宏,以ACE_SYNCH_前缀
#if defined (ACE_HAS_THREADS)
#define ACE_SYNCH_MUTEX ACE_Thread_Mutex
#define ACE_SYNCH_NULL_MUTEX ACE_Null_Mutex
#define ACE_SYNCH_RECURSIVE_MUTEX ACE_Recursive_Thread_Mutex
#define ACE_SYNCH_RW_MUTEX ACE_RW_Thread_Mutex
#define ACE_SYNCH_CONDITION ACE_Condition_Thread_Mutex
#define ACE_SYNCH_RECURSIVE_CONDITION ACE_Condition_Recursive_Thread_Mutex
#define ACE_SYNCH_SEMAPHORE ACE_Thread_Semaphore
#define ACE_SYNCH_NULL_SEMAPHORE ACE_Null_Semaphore
#else /* ACE_HAS_THREADS */
#define ACE_SYNCH_MUTEX ACE_Null_Mutex
#define ACE_SYNCH_NULL_MUTEX ACE_Null_Mutex
#define ACE_SYNCH_RECURSIVE_MUTEX ACE_Null_Mutex
#define ACE_SYNCH_RW_MUTEX ACE_Null_Mutex
#define ACE_SYNCH_CONDITION ACE_Null_Condition
#define ACE_SYNCH_RECURSIVE_CONDITION ACE_Null_Condition
#define ACE_SYNCH_SEMAPHORE ACE_Null_Semaphore
#define ACE_SYNCH_NULL_SEMAPHORE ACE_Null_Mutex
#endif /* ACE_HAS_THREADS */