Drizzled Public API Documentation

locks.h
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 #include <drizzled/util/string.h>
00032 
00033 
00034 #pragma once
00035 
00036 namespace user_locks {
00037 
00038 namespace locks {
00039   enum return_t {
00040     SUCCESS,
00041     NOT_FOUND,
00042     NOT_OWNED_BY
00043   };
00044 } /* locks user_locks */
00045 
00046 const size_t LARGEST_LOCK_NAME= 64;
00047 
00048 class Locks
00049 {
00050 public:
00051   typedef boost::unordered_map<user_locks::Key, user_locks::Lock::shared_ptr> LockMap;
00052 
00053   static Locks &getInstance(void)
00054   {
00055     static Locks instance;
00056     return instance;
00057   }
00058 
00059   void waitCreate(int64_t wait_for= 2); // Default is to wait 2 seconds before returning
00060 
00061   bool lock(drizzled::session_id_t id_arg, const user_locks::Key &arg, int64_t wait_for= 0);
00062   bool lock(drizzled::session_id_t id_arg, const user_locks::Keys &arg);
00063   locks::return_t release(const user_locks::Key &arg, drizzled::session_id_t &id_arg, bool and_wait= false);
00064   bool isFree(const user_locks::Key &arg);
00065   bool isUsed(const user_locks::Key &arg, drizzled::session_id_t &id_arg);
00066   void Copy(LockMap &lock_map);
00067 
00068 private:
00069   boost::mutex mutex;
00070   boost::condition_variable create_cond; // Signal next 
00071   boost::condition_variable release_cond;
00072   LockMap lock_map; 
00073 };
00074 
00075 
00076 } /* namespace user_locks */
00077