1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "plugin/user_locks/module.h"
26
namespace user_locks {
28
bool Locks::lock(drizzled::session_id_t id_arg, const std::string &arg, int64_t wait_for)
31
std::pair<LockMap::iterator, bool> is_locked;
33
boost::unique_lock<boost::mutex> scope(mutex);
34
is_locked= lock_map.insert(std::make_pair(arg, new lock_st(id_arg)));
36
return is_locked.second;
39
bool Locks::isUsed(const std::string &arg, drizzled::session_id_t &id_arg)
41
boost::unique_lock<boost::mutex> scope(mutex);
43
LockMap::iterator iter= lock_map.find(arg);
45
if ( iter == lock_map.end())
48
id_arg= (*iter).second->id;
53
bool Locks::isFree(const std::string &arg)
55
boost::unique_lock<boost::mutex> scope(mutex);
57
LockMap::iterator iter= lock_map.find(arg);
59
return iter != lock_map.end();
62
bool Locks::release(const std::string &arg)
64
boost::unique_lock<boost::mutex> scope(mutex);
65
size_t elements= lock_map.erase(arg);
67
return elements ? true : false;
70
} /* namespace user_locks */