00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _utils_SHARELOCK
00021 #define _utils_SHARELOCK
00022
00028 #include <multiset.h>
00029 #include <string>
00030 #include "String.h"
00031
00032 namespace utils {
00033 class ShareLock;
00034 };
00035
00049 class utils::ShareLock {
00050 public:
00054 ShareLock();
00055
00059 ~ShareLock();
00060
00070 void lock(const string &resource, bool exclusive=false);
00071
00078 void unlock(const string &resource);
00079 private:
00080 inline void alloc(const string &resource, bool ex);
00081 inline void free(const string &resource);
00082 inline bool isbusy(const string &resource, bool ex);
00083
00084 pthread_mutex_t mut;
00085 pthread_cond_t cond;
00086 multiset<string, fbfs::str_cmp> excl;
00087
00088 multiset<string, fbfs::str_cmp> shared;
00089 };
00090
00091 #endif