~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session/cache.cc

mergeĀ lp:~hingo/drizzle/drizzle-auth_ldap-fix-and-docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
 
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
5
 *
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
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
 
21
#include <drizzled/session/cache.h>
21
22
 
 
23
#include <boost/foreach.hpp>
 
24
#include <drizzled/current_session.h>
 
25
#include <drizzled/plugin/authorization.h>
 
26
#include <drizzled/session.h>
22
27
#include <vector>
23
28
 
24
 
#include "drizzled/session/cache.h"
25
 
#include "drizzled/session.h"
26
 
#include "drizzled/current_session.h"
27
 
#include "drizzled/plugin/authorization.h"
28
 
 
29
 
#include <boost/foreach.hpp>
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
namespace session
35
 
{
36
 
 
37
 
Session::shared_ptr Cache::find(const session_id_t &id)
 
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
38
{
39
39
  boost::mutex::scoped_lock scopedLock(_mutex);
40
 
 
41
40
  BOOST_FOREACH(list::const_reference it, cache)
42
41
  {
43
42
    if (it->thread_id == id)
44
 
    {
45
43
      return it;
46
 
    }
47
 
  }
48
 
 
49
 
  return Session::shared_ptr();
 
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
  }
50
66
}
51
67
 
52
68
size_t Cache::count()
56
72
  return cache.size();
57
73
}
58
74
 
59
 
void Cache::erase(Session::Ptr arg)
60
 
{
61
 
  BOOST_FOREACH(list::const_reference it, cache)
62
 
  {
63
 
    if (it.get() == arg)
64
 
    {
65
 
      cache.remove(it);
66
 
      return;
67
 
    }
68
 
  }
69
 
}
70
 
 
71
 
void Cache::insert(Session::shared_ptr &arg)
 
75
void Cache::insert(const session_ptr& arg)
72
76
{
73
77
  boost::mutex::scoped_lock scopedLock(_mutex);
74
78
  cache.push_back(arg);
75
79
}
76
80
 
77
 
void Cache::erase(Session::shared_ptr &arg)
 
81
void Cache::erase(const session_ptr& arg)
78
82
{
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());
 
85
  cache.erase(iter);
80
86
}
81
87
 
82
88
} /* namespace session */