~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/user_locks/locks.h

  • Committer: Brian Aker
  • Date: 2010-11-08 17:40:41 UTC
  • mto: (1921.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1916.
  • Revision ID: brian@tangent.org-20101108174041-owap774v8l5vvnl4
Push some functions behind classes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <boost/thread/mutex.hpp>
22
22
#include <boost/thread/condition_variable.hpp>
23
23
#include <boost/unordered_map.hpp>
 
24
#include <boost/logic/tribool.hpp>
24
25
#include <boost/unordered/unordered_set.hpp>
25
26
 
26
 
#include "plugin/user_locks/lock.h"
27
 
 
28
27
#include <string>
29
28
 
30
29
#include "drizzled/session.h"
36
35
 
37
36
namespace user_locks {
38
37
 
39
 
namespace locks {
40
 
  enum return_t {
41
 
    SUCCESS,
42
 
    NOT_FOUND,
43
 
    NOT_OWNED_BY
44
 
  };
45
 
} /* locks user_locks */
46
 
 
47
38
const size_t LARGEST_LOCK_NAME= 64;
48
39
 
49
40
class Locks
50
41
{
51
42
public:
52
 
  typedef boost::unordered_map<user_locks::Key, user_locks::Lock::shared_ptr> LockMap;
 
43
  struct lock_st {
 
44
    drizzled::session_id_t id;
 
45
 
 
46
    lock_st(drizzled::session_id_t id_arg) :
 
47
      id(id_arg)
 
48
    {
 
49
    }
 
50
  };
 
51
 
 
52
  typedef boost::shared_ptr<lock_st> lock_st_ptr;
 
53
 
 
54
  typedef boost::unordered_map<user_locks::Key, lock_st_ptr> LockMap;
53
55
 
54
56
  static Locks &getInstance(void)
55
57
  {
57
59
    return instance;
58
60
  }
59
61
 
60
 
  void waitCreate(int64_t wait_for= 2); // Default is to wait 2 seconds before returning
61
 
 
 
62
  bool lock(drizzled::session_id_t id_arg, const user_locks::Key &arg);
62
63
  bool lock(drizzled::session_id_t id_arg, const user_locks::Key &arg, int64_t wait_for= 0);
63
64
  bool lock(drizzled::session_id_t id_arg, const user_locks::Keys &arg);
64
 
  locks::return_t release(const user_locks::Key &arg, drizzled::session_id_t &id_arg, bool and_wait= false);
 
65
  boost::tribool release(const user_locks::Key &arg, drizzled::session_id_t &id_arg);
65
66
  bool isFree(const user_locks::Key &arg);
66
67
  bool isUsed(const user_locks::Key &arg, drizzled::session_id_t &id_arg);
67
68
  void Copy(LockMap &lock_map);
68
69
 
69
70
private:
70
71
  boost::mutex mutex;
71
 
  boost::condition_variable create_cond; // Signal next 
72
 
  boost::condition_variable release_cond;
 
72
  boost::condition_variable cond;
73
73
  LockMap lock_map; 
74
74
};
75
75