00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <plugin/user_locks/module.h>
00023
00024 #include <boost/thread/locks.hpp>
00025
00026 #include <string>
00027
00028 namespace user_locks {
00029 namespace barriers {
00030
00031 bool Barriers::create(const user_locks::Key &arg, drizzled::session_id_t owner)
00032 {
00033 boost::unique_lock<boost::mutex> scope(mutex);
00034 return barrier_map.insert(std::make_pair(arg, new Barrier(owner))).second;
00035 }
00036
00037 bool Barriers::create(const user_locks::Key &arg, drizzled::session_id_t owner, int64_t wait_count)
00038 {
00039 boost::unique_lock<boost::mutex> scope(mutex);
00040 return barrier_map.insert(std::make_pair(arg, new Barrier(owner, wait_count))).second;
00041 }
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 return_t Barriers::release(const user_locks::Key &arg, drizzled::session_id_t owner)
00052 {
00053 boost::unique_lock<boost::mutex> scope(mutex);
00054 Map::iterator iter= barrier_map.find(arg);
00055
00056
00057 if ( iter == barrier_map.end())
00058 return NOT_FOUND;
00059
00060 if (not iter->second->getOwner() == owner)
00061 return NOT_OWNED_BY;
00062
00063 iter->second->signal();
00064 (void)barrier_map.erase(arg);
00065
00066 return SUCCESS;
00067 }
00068
00069 Barrier::shared_ptr Barriers::find(const user_locks::Key &arg)
00070 {
00071 boost::unique_lock<boost::mutex> scope(mutex);
00072 Map::iterator iter= barrier_map.find(arg);
00073
00074 if (iter != barrier_map.end())
00075 return iter->second;
00076
00077 return Barrier::shared_ptr();
00078 }
00079
00080 void Barriers::Copy(Map &arg)
00081 {
00082 boost::unique_lock<boost::mutex> scope(mutex);
00083 arg= barrier_map;
00084 }
00085
00086 }
00087 }