30
30
bool Locks::lock(drizzled::session_id_t id_arg, const user_locks::Key &arg, int64_t wait_for)
32
boost::system_time timeout= boost::get_system_time() + boost::posix_time::seconds(wait_for);
32
33
boost::unique_lock<boost::mutex> scope(mutex);
33
boost::system_time timeout= boost::get_system_time() + boost::posix_time::seconds(wait_for);
35
35
LockMap::iterator iter;
36
36
while ((iter= lock_map.find(arg)) != lock_map.end())
40
40
// We own the lock, so we just exit.
46
bool success= release_cond.timed_wait(scope, timeout);
43
bool success= cond.timed_wait(scope, timeout);
53
release_cond.wait(scope);
56
catch(boost::thread_interrupted const& error)
58
// Currently nothing is done here.
63
49
if (iter == lock_map.end())
65
create_cond.notify_all();
66
return lock_map.insert(std::make_pair(arg, new Lock(id_arg))).second;
51
std::pair<LockMap::iterator, bool> is_locked;
53
is_locked= lock_map.insert(std::make_pair(arg, new lock_st(id_arg)));
54
return is_locked.second;
72
// Currently we just let timeouts occur, and the caller will need to know
73
// what it is looking for/whether to go back into this.
74
void Locks::waitCreate(int64_t wait_for)
60
bool Locks::lock(drizzled::session_id_t id_arg, const user_locks::Key &arg)
62
std::pair<LockMap::iterator, bool> is_locked;
76
63
boost::unique_lock<boost::mutex> scope(mutex);
77
boost::system_time timeout= boost::get_system_time() + boost::posix_time::seconds(wait_for);
64
is_locked= lock_map.insert(std::make_pair(arg, new lock_st(id_arg)));
81
timed_out= create_cond.timed_wait(scope, timeout);
83
catch(boost::thread_interrupted const& error)
85
// Currently nothing is done here.
66
return is_locked.second;
90
69
bool Locks::lock(drizzled::session_id_t id_arg, const user_locks::Keys &arg)
92
71
boost::unique_lock<boost::mutex> scope(mutex);
93
user_locks::Keys created;
96
73
for (user_locks::Keys::const_iterator iter= arg.begin(); iter != arg.end(); iter++)
98
75
LockMap::iterator record= lock_map.find(*iter);
100
if (record != lock_map.end()) // Found, so check ownership of the lock
77
if (record != lock_map.end())
102
79
if (id_arg != (*record).second->id)
104
// So it turns out the locks exist, and we can't grab them all
111
lock_map.insert(std::make_pair(*iter, new Lock(id_arg)));
112
created.insert(*iter);
84
for (Keys::iterator iter= arg.begin(); iter != arg.end(); iter++)
118
for (user_locks::Keys::const_iterator iter= created.begin(); iter != created.end(); iter++)
120
lock_map.erase(*iter);
86
std::pair<LockMap::iterator, bool> is_locked;
87
//is_locked can fail in cases where we already own the lock.
88
is_locked= lock_map.insert(std::make_pair(*iter, new lock_st(id_arg)));
126
create_cond.notify_all();
154
117
void Locks::Copy(LockMap &lock_map_arg)
156
boost::unique_lock<boost::mutex> scope(mutex);
157
119
lock_map_arg= lock_map;
160
locks::return_t Locks::release(const user_locks::Key &arg, drizzled::session_id_t &id_arg, bool and_wait)
122
boost::tribool Locks::release(const user_locks::Key &arg, drizzled::session_id_t &id_arg)
162
124
size_t elements= 0;
163
125
boost::unique_lock<boost::mutex> scope(mutex);
166
128
// Nothing is found
167
129
if ( iter == lock_map.end())
168
return locks::NOT_FOUND;
130
return boost::indeterminate;
170
132
if ((*iter).second->id == id_arg)
172
133
elements= lock_map.erase(arg);
173
assert(elements); // If we can't find what we just found, then we are broken
177
release_cond.notify_one();
184
assert(boost::this_thread::interruption_enabled());
186
create_cond.wait(scope);
188
catch(boost::thread_interrupted const& error)
190
// Currently nothing is done here.
193
iter= lock_map.find(arg);
195
if (iter != lock_map.end())
200
return locks::SUCCESS;
204
return locks::NOT_OWNED_BY;
207
144
} /* namespace user_locks */