Drizzled Public API Documentation

cache.cc
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 #include <config.h>
00021 
00022 #include <vector>
00023 
00024 #include <drizzled/session.h>
00025 #include <drizzled/session/cache.h>
00026 #include <drizzled/current_session.h>
00027 #include <drizzled/plugin/authorization.h>
00028 
00029 #include <boost/foreach.hpp>
00030 
00031 namespace drizzled
00032 {
00033 
00034 namespace session
00035 {
00036 
00037 Cache::session_shared_ptr Cache::find(const session_id_t &id)
00038 {
00039   boost::mutex::scoped_lock scopedLock(_mutex);
00040 
00041   BOOST_FOREACH(list::const_reference it, cache)
00042   {
00043     if (it->thread_id == id)
00044     {
00045       return it;
00046     }
00047   }
00048 
00049   return session_shared_ptr();
00050 }
00051 
00052 void Cache::shutdownFirst()
00053 {
00054   boost::mutex::scoped_lock scopedLock(_mutex);
00055   _ready_to_exit= true;
00056 
00057   /* do the broadcast inside the lock to ensure that my_end() is not called */
00058   _end.notify_all();
00059 }
00060 
00061   /* Wait until cleanup is done */
00062 void Cache::shutdownSecond()
00063 {
00064   boost::mutex::scoped_lock scopedLock(_mutex);
00065 
00066   while (not _ready_to_exit)
00067   {
00068     _end.wait(scopedLock);
00069   }
00070 }
00071 
00072 size_t Cache::count()
00073 {
00074   boost::mutex::scoped_lock scopedLock(_mutex);
00075 
00076   return cache.size();
00077 }
00078 
00079 void Cache::insert(session_shared_ptr &arg)
00080 {
00081   boost::mutex::scoped_lock scopedLock(_mutex);
00082   cache.push_back(arg);
00083 }
00084 
00085 void Cache::erase(session_shared_ptr &arg)
00086 {
00087   list::iterator iter= std::find(cache.begin(), cache.end(), arg);
00088   assert(iter != cache.end());
00089   cache.erase(iter);
00090 }
00091 
00092 } /* namespace session */
00093 } /* namespace drizzled */