00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include <drizzled/session/cache.h>
00022
00023 #include <boost/foreach.hpp>
00024 #include <drizzled/current_session.h>
00025 #include <drizzled/plugin/authorization.h>
00026 #include <drizzled/session.h>
00027 #include <vector>
00028
00029 namespace drizzled {
00030 namespace session {
00031
00032 bool volatile Cache::_ready_to_exit= false;
00033 Cache::list Cache::cache;
00034 boost::mutex Cache::_mutex;
00035 boost::condition_variable Cache::_end;
00036
00037 Cache::session_ptr Cache::find(const session_id_t &id)
00038 {
00039 boost::mutex::scoped_lock scopedLock(_mutex);
00040 BOOST_FOREACH(list::const_reference it, cache)
00041 {
00042 if (it->thread_id == id)
00043 return it;
00044 }
00045 return session_ptr();
00046 }
00047
00048 void Cache::shutdownFirst()
00049 {
00050 boost::mutex::scoped_lock scopedLock(_mutex);
00051 _ready_to_exit= true;
00052
00053
00054 _end.notify_all();
00055 }
00056
00057
00058 void Cache::shutdownSecond()
00059 {
00060 boost::mutex::scoped_lock scopedLock(_mutex);
00061
00062 while (not _ready_to_exit)
00063 {
00064 _end.wait(scopedLock);
00065 }
00066 }
00067
00068 size_t Cache::count()
00069 {
00070 boost::mutex::scoped_lock scopedLock(_mutex);
00071
00072 return cache.size();
00073 }
00074
00075 void Cache::insert(const session_ptr& arg)
00076 {
00077 boost::mutex::scoped_lock scopedLock(_mutex);
00078 cache.push_back(arg);
00079 }
00080
00081 void Cache::erase(const session_ptr& arg)
00082 {
00083 list::iterator iter= std::find(cache.begin(), cache.end(), arg);
00084 assert(iter != cache.end());
00085 cache.erase(iter);
00086 }
00087
00088 }
00089 }