~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session/cache.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-28 14:32:36 UTC
  • mto: (2257.1.1 build) (2276.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: olafvdspek@gmail.com-20110328143236-4ge1d793iqaktfq0
Common fwd

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
21
 
22
22
#include <vector>
23
23
 
24
 
#include "drizzled/session/cache.h"
25
 
#include "drizzled/session.h"
26
 
#include "drizzled/current_session.h"
27
 
#include "drizzled/plugin/authorization.h"
 
24
#include <drizzled/session.h>
 
25
#include <drizzled/session/cache.h>
 
26
#include <drizzled/current_session.h>
 
27
#include <drizzled/plugin/authorization.h>
28
28
 
29
29
#include <boost/foreach.hpp>
30
30
 
34
34
namespace session
35
35
{
36
36
 
37
 
Session::shared_ptr Cache::find(const session_id_t &id)
 
37
Cache::session_shared_ptr Cache::find(const session_id_t &id)
38
38
{
39
39
  boost::mutex::scoped_lock scopedLock(_mutex);
40
40
 
46
46
    }
47
47
  }
48
48
 
49
 
  return Session::shared_ptr();
 
49
  return session_shared_ptr();
 
50
}
 
51
 
 
52
void Cache::shutdownFirst()
 
53
{
 
54
  boost::mutex::scoped_lock scopedLock(_mutex);
 
55
  _ready_to_exit= true;
 
56
 
 
57
  /* do the broadcast inside the lock to ensure that my_end() is not called */
 
58
  _end.notify_all();
 
59
}
 
60
 
 
61
  /* Wait until cleanup is done */
 
62
void Cache::shutdownSecond()
 
63
{
 
64
  boost::mutex::scoped_lock scopedLock(_mutex);
 
65
 
 
66
  while (not _ready_to_exit)
 
67
  {
 
68
    _end.wait(scopedLock);
 
69
  }
50
70
}
51
71
 
52
72
size_t Cache::count()
56
76
  return cache.size();
57
77
}
58
78
 
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)
 
79
void Cache::insert(session_shared_ptr &arg)
72
80
{
73
81
  boost::mutex::scoped_lock scopedLock(_mutex);
74
82
  cache.push_back(arg);
75
83
}
76
84
 
77
 
void Cache::erase(Session::shared_ptr &arg)
 
85
void Cache::erase(session_shared_ptr &arg)
78
86
{
79
 
  cache.erase(remove(cache.begin(), cache.end(), arg));
 
87
  list::iterator iter= std::find(cache.begin(), cache.end(), arg);
 
88
  assert(iter != cache.end());
 
89
  cache.erase(iter);
80
90
}
81
91
 
82
92
} /* namespace session */