00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <boost/thread/mutex.hpp>
00022 #include <boost/thread/condition_variable.hpp>
00023 #include <boost/unordered_map.hpp>
00024 #include <boost/unordered/unordered_set.hpp>
00025
00026 #include <plugin/user_locks/lock.h>
00027
00028 #include <string>
00029
00030 #include <drizzled/session.h>
00031
00032 #pragma once
00033
00034 namespace user_locks {
00035
00036 namespace locks {
00037 enum return_t {
00038 SUCCESS,
00039 NOT_FOUND,
00040 NOT_OWNED_BY
00041 };
00042 }
00043
00044 const size_t LARGEST_LOCK_NAME= 64;
00045
00046 class Locks
00047 {
00048 public:
00049 typedef boost::unordered_map<user_locks::Key, user_locks::Lock::shared_ptr> LockMap;
00050
00051 static Locks &getInstance(void)
00052 {
00053 static Locks instance;
00054 return instance;
00055 }
00056
00057 void waitCreate(int64_t wait_for= 2);
00058
00059 bool lock(drizzled::session_id_t id_arg, const user_locks::Key &arg, int64_t wait_for= 0);
00060 bool lock(drizzled::session_id_t id_arg, const user_locks::Keys &arg);
00061 locks::return_t release(const user_locks::Key &arg, drizzled::session_id_t &id_arg, bool and_wait= false);
00062 bool isFree(const user_locks::Key &arg);
00063 bool isUsed(const user_locks::Key &arg, drizzled::session_id_t &id_arg);
00064 void Copy(LockMap &lock_map);
00065
00066 private:
00067 boost::mutex mutex;
00068 boost::condition_variable create_cond;
00069 boost::condition_variable release_cond;
00070 LockMap lock_map;
00071 };
00072
00073
00074 }
00075