~drizzle-trunk/drizzle/development

1933.1.3 by Brian Aker
First pass though barriers.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Brian Aker
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; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
#include <boost/thread/mutex.hpp>
22
#include <boost/thread/condition_variable.hpp>
23
#include <boost/unordered_map.hpp>
24
#include <boost/unordered/unordered_set.hpp>
25
26
#include <string>
27
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
28
#include <drizzled/session.h>
29
#include <drizzled/util/string.h>
1933.1.3 by Brian Aker
First pass though barriers.
30
31
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
32
#pragma once
1933.1.3 by Brian Aker
First pass though barriers.
33
34
namespace user_locks {
1933.1.4 by Brian Aker
Fix errror messages and namespace.
35
namespace barriers {
1933.1.3 by Brian Aker
First pass though barriers.
36
37
const size_t LARGEST_BARRIER_NAME= 64;
38
1955.1.2 by Brian Aker
Update such that we can now do a lock test with a wait.
39
enum return_t {
40
  SUCCESS,
41
  NOT_FOUND,
42
  NOT_OWNED_BY
43
};
44
1933.1.3 by Brian Aker
First pass though barriers.
45
class Barriers
46
{
47
public:
1933.1.4 by Brian Aker
Fix errror messages and namespace.
48
  typedef boost::unordered_map<user_locks::Key, Barrier::shared_ptr> Map;
1933.1.3 by Brian Aker
First pass though barriers.
49
50
  static Barriers &getInstance(void)
51
  {
52
    static Barriers instance;
53
    return instance;
54
  }
55
1933.1.4 by Brian Aker
Fix errror messages and namespace.
56
  bool create(const user_locks::Key &arg, drizzled::session_id_t owner);
1933.1.5 by Brian Aker
Implemented barrier wait_count feature.
57
  bool create(const user_locks::Key &arg, drizzled::session_id_t owner, int64_t wait_count);
1955.1.2 by Brian Aker
Update such that we can now do a lock test with a wait.
58
  return_t release(const user_locks::Key &arg, drizzled::session_id_t owner);
1933.1.4 by Brian Aker
Fix errror messages and namespace.
59
  Barrier::shared_ptr find(const user_locks::Key &arg);
1933.1.3 by Brian Aker
First pass though barriers.
60
  void Copy(Map &arg);
61
62
private:
63
64
  boost::mutex mutex;
65
  Map barrier_map; 
66
};
67
68
1933.1.4 by Brian Aker
Fix errror messages and namespace.
69
} /* namespace barriers */
1933.1.3 by Brian Aker
First pass though barriers.
70
} /* namespace user_locks */
71