1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
4
* Copyright (C) 2009 Sun Microsystems, Inc.
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/session/cache.h>
23
#include <boost/foreach.hpp>
24
#include <drizzled/current_session.h>
25
#include <drizzled/plugin/authorization.h>
26
#include <drizzled/session.h>
24
#include "drizzled/session/cache.h"
25
#include "drizzled/session.h"
26
#include "drizzled/current_session.h"
27
#include "drizzled/plugin/authorization.h"
29
#include <boost/foreach.hpp>
37
Session::shared_ptr Cache::find(const session_id_t &id)
32
bool volatile Cache::_ready_to_exit= false;
33
Cache::list Cache::cache;
34
boost::mutex Cache::_mutex;
35
boost::condition_variable Cache::_end;
37
Cache::session_ptr Cache::find(const session_id_t &id)
39
39
boost::mutex::scoped_lock scopedLock(_mutex);
41
40
BOOST_FOREACH(list::const_reference it, cache)
43
42
if (it->thread_id == id)
49
return Session::shared_ptr();
48
void Cache::shutdownFirst()
50
boost::mutex::scoped_lock scopedLock(_mutex);
53
/* do the broadcast inside the lock to ensure that my_end() is not called */
57
/* Wait until cleanup is done */
58
void Cache::shutdownSecond()
60
boost::mutex::scoped_lock scopedLock(_mutex);
62
while (not _ready_to_exit)
64
_end.wait(scopedLock);
52
68
size_t Cache::count()
56
72
return cache.size();
59
void Cache::erase(Session::Ptr arg)
61
BOOST_FOREACH(list::const_reference it, cache)
71
void Cache::insert(Session::shared_ptr &arg)
75
void Cache::insert(const session_ptr& arg)
73
77
boost::mutex::scoped_lock scopedLock(_mutex);
74
78
cache.push_back(arg);
77
void Cache::erase(Session::shared_ptr &arg)
81
void Cache::erase(const session_ptr& arg)
79
cache.erase(remove(cache.begin(), cache.end(), arg));
83
list::iterator iter= std::find(cache.begin(), cache.end(), arg);
84
assert(iter != cache.end());
82
88
} /* namespace session */