Drizzled Public API Documentation

cache.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
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; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <list>
00023 
00024 #include <drizzled/visibility.h>
00025 
00026 namespace drizzled
00027 {
00028 
00029 class Session;
00030 
00031 namespace session
00032 {
00033 
00034 class DRIZZLED_API Cache 
00035 {
00036   typedef boost::shared_ptr<drizzled::Session> session_shared_ptr;
00037 public:
00038   typedef std::list<session_shared_ptr> list;
00039 
00040   Cache() :
00041     _ready_to_exit(false)
00042   {
00043   }
00044 
00045   static inline Cache &singleton()
00046   {
00047     static Cache open_cache;
00048 
00049     return open_cache;
00050   }
00051 
00052   list &getCache()
00053   {
00054     return cache;
00055   }
00056 
00057   boost::mutex &mutex()
00058   {
00059     return _mutex;
00060   }
00061 
00062   boost::condition_variable &cond()
00063   {
00064     return _end;
00065   }
00066 
00067   void shutdownFirst();
00068   void shutdownSecond();
00069 
00070   void erase(session_shared_ptr&);
00071   size_t count();
00072   void insert(session_shared_ptr &arg);
00073 
00074   session_shared_ptr find(const session_id_t &id);
00075 
00076 private:
00077   bool volatile _ready_to_exit;
00078   list cache;
00079   boost::mutex _mutex;
00080   boost::condition_variable _end;
00081 };
00082 
00083 } /* namespace session */
00084 } /* namespace drizzled */
00085