drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
session/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 <drizzled/current_session.h>
24#include <drizzled/plugin/authorization.h>
25#include <drizzled/session.h>
26#include <vector>
27
28namespace drizzled {
29namespace session {
30
31bool volatile Cache::_ready_to_exit= false;
32Cache::list Cache::cache;
33boost::mutex Cache::_mutex;
34boost::condition_variable Cache::_end;
35
36Cache::session_ptr Cache::find(const session_id_t &id)
37{
38 boost::mutex::scoped_lock scopedLock(_mutex);
39 for (list::const_reference it : cache)
40 {
41 if (it->thread_id == id)
42 return it;
43 }
44 return session_ptr();
45}
46
47void Cache::shutdownFirst()
48{
49 boost::mutex::scoped_lock scopedLock(_mutex);
50 _ready_to_exit= true;
51
52 /* do the broadcast inside the lock to ensure that my_end() is not called */
53 _end.notify_all();
54}
55
56 /* Wait until cleanup is done */
57void Cache::shutdownSecond()
58{
59 boost::mutex::scoped_lock scopedLock(_mutex);
60
61 while (not _ready_to_exit)
62 {
63 _end.wait(scopedLock);
64 }
65}
66
67size_t Cache::count()
68{
69 boost::mutex::scoped_lock scopedLock(_mutex);
70
71 return cache.size();
72}
73
74void Cache::insert(const session_ptr& arg)
75{
76 boost::mutex::scoped_lock scopedLock(_mutex);
77 cache.push_back(arg);
78}
79
80void Cache::erase(const session_ptr& arg)
81{
82 list::iterator iter= std::find(cache.begin(), cache.end(), arg);
83 assert(iter != cache.end());
84 cache.erase(iter);
85}
86
87} /* namespace session */
88} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.