FirteX-高性能全文索引和检索平台

API Documentation


首页 | 名字空间列表 | 类继承关系 | 组合类型列表 | $(BL\录(B | 文件列表 | 名字空间成员 | 组合类型成员 | 文件成员

Mutex.h

浏览该文件的文档。
00001 
00002 //  Written by Phillip Sitbon
00003 //  Copyright 2003
00004 //
00005 //  Posix/Mutex.h
00006 //    - Resource locking mechanism using Posix mutexes
00007 //
00009 
00010 #ifndef _MUTEX_LINUX_H
00011 #define _MUTEX_LINUX_H
00012 
00013 #include "Lockable.h"
00014 //#include "NonCopypable.h"
00015 
00016 #include <pthread.h>
00017 
00018 namespace firte
00019 {
00020         namespace thread
00021         {
00022 
00023                 class CMutex : public CLockable//,private CNonCopypable
00024                 {  
00025                 public:
00026                 CMutex()
00027                 {
00028                         pthread_mutexattr_t attr;
00029                         pthread_mutexattr_init(&attr);
00030                         pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
00031                         pthread_mutex_init(&M,&attr);
00032                         pthread_mutexattr_destroy(&attr);
00033                 }
00034 
00035                 virtual ~Mutex()
00036                 {
00037                         pthread_mutex_unlock(&M); 
00038                         pthread_mutex_destroy(&M); 
00039                 }
00040 
00041                 void acquire()
00042                 { 
00043                         pthread_mutex_lock(&M); 
00044                 }
00045 
00046                 bool tryAcquire()
00047                 {
00048                         return pthread_mutex_trylock(&M); 
00049                 }
00050 
00051                 void release()
00052                 { 
00053                         return pthread_mutex_unlock(&M); 
00054                 }
00055 
00056                 protected:
00057                         mutable pthread_mutex_t M;  
00058                 };
00059         }
00060 }
00061 
00062 #endif 

http://www.firtex.org http://www.sourceforge.net/projects/firtex