Drizzled Public API Documentation

cache.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2009 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include <config.h>
21 #include <drizzled/session/cache.h>
22 
23 #include <boost/foreach.hpp>
24 #include <drizzled/current_session.h>
25 #include <drizzled/plugin/authorization.h>
26 #include <drizzled/session.h>
27 #include <vector>
28 
29 namespace drizzled {
30 namespace session {
31 
32 bool volatile Cache::_ready_to_exit= false;
33 Cache::list Cache::cache;
34 boost::mutex Cache::_mutex;
35 boost::condition_variable Cache::_end;
36 
37 Cache::session_ptr Cache::find(const session_id_t &id)
38 {
39  boost::mutex::scoped_lock scopedLock(_mutex);
40  BOOST_FOREACH(list::const_reference it, cache)
41  {
42  if (it->thread_id == id)
43  return it;
44  }
45  return session_ptr();
46 }
47 
48 void Cache::shutdownFirst()
49 {
50  boost::mutex::scoped_lock scopedLock(_mutex);
51  _ready_to_exit= true;
52 
53  /* do the broadcast inside the lock to ensure that my_end() is not called */
54  _end.notify_all();
55 }
56 
57  /* Wait until cleanup is done */
58 void Cache::shutdownSecond()
59 {
60  boost::mutex::scoped_lock scopedLock(_mutex);
61 
62  while (not _ready_to_exit)
63  {
64  _end.wait(scopedLock);
65  }
66 }
67 
68 size_t Cache::count()
69 {
70  boost::mutex::scoped_lock scopedLock(_mutex);
71 
72  return cache.size();
73 }
74 
75 void Cache::insert(const session_ptr& arg)
76 {
77  boost::mutex::scoped_lock scopedLock(_mutex);
78  cache.push_back(arg);
79 }
80 
81 void Cache::erase(const session_ptr& arg)
82 {
83  list::iterator iter= std::find(cache.begin(), cache.end(), arg);
84  assert(iter != cache.end());
85  cache.erase(iter);
86 }
87 
88 } /* namespace session */
89 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.