Drizzled Public API Documentation

barriers.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 <string>
00027 
00028 #include <drizzled/session.h>
00029 #include <drizzled/util/string.h>
00030 
00031 
00032 #pragma once
00033 
00034 namespace user_locks {
00035 namespace barriers {
00036 
00037 const size_t LARGEST_BARRIER_NAME= 64;
00038 
00039 enum return_t {
00040   SUCCESS,
00041   NOT_FOUND,
00042   NOT_OWNED_BY
00043 };
00044 
00045 class Barriers
00046 {
00047 public:
00048   typedef boost::unordered_map<user_locks::Key, Barrier::shared_ptr> Map;
00049 
00050   static Barriers &getInstance(void)
00051   {
00052     static Barriers instance;
00053     return instance;
00054   }
00055 
00056   bool create(const user_locks::Key &arg, drizzled::session_id_t owner);
00057   bool create(const user_locks::Key &arg, drizzled::session_id_t owner, int64_t wait_count);
00058   return_t release(const user_locks::Key &arg, drizzled::session_id_t owner);
00059   Barrier::shared_ptr find(const user_locks::Key &arg);
00060   void Copy(Map &arg);
00061 
00062 private:
00063 
00064   boost::mutex mutex;
00065   Map barrier_map; 
00066 };
00067 
00068 
00069 } /* namespace barriers */
00070 } /* namespace user_locks */
00071