~percona-dev/percona-server/5.1-kill_idle_transaction-innodb_fake_changes

« back to all changes in this revision

Viewing changes to HandlerSocket-Plugin-for-MySQL/libhsclient/mutex.hpp

  • Committer: Aleksandr Kuzminsky
  • Date: 2010-11-24 08:58:24 UTC
  • mto: This revision was merged to the branch mainline in revision 155.
  • Revision ID: aleksandr.kuzminsky@percona.com-20101124085824-9742ytdt2x50djw3
Added HandlerSocket-Plugin-for-MySQL sources

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// vim:sw=2:ai
 
3
 
 
4
/*
 
5
 * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
 
6
 * See COPYRIGHT.txt for details.
 
7
 */
 
8
 
 
9
#ifndef DENA_MUTEX_HPP
 
10
#define DENA_MUTEX_HPP
 
11
 
 
12
#include <pthread.h>
 
13
#include <stdlib.h>
 
14
 
 
15
#include "fatal.hpp"
 
16
#include "util.hpp"
 
17
 
 
18
namespace dena {
 
19
 
 
20
struct condition;
 
21
 
 
22
struct mutex : private noncopyable {
 
23
  friend struct condition;
 
24
  mutex() {
 
25
    if (pthread_mutex_init(&mtx, 0) != 0) {
 
26
      fatal_abort("pthread_mutex_init");
 
27
    }
 
28
  }
 
29
  ~mutex() {
 
30
    if (pthread_mutex_destroy(&mtx) != 0) {
 
31
      fatal_abort("pthread_mutex_destroy");
 
32
    }
 
33
  }
 
34
  void lock() const {
 
35
    if (pthread_mutex_lock(&mtx) != 0) {
 
36
      fatal_abort("pthread_mutex_lock");
 
37
    }
 
38
  }
 
39
  void unlock() const {
 
40
    if (pthread_mutex_unlock(&mtx) != 0) {
 
41
      fatal_abort("pthread_mutex_unlock");
 
42
    }
 
43
  }
 
44
 private:
 
45
  mutable pthread_mutex_t mtx;
 
46
};
 
47
 
 
48
};
 
49
 
 
50
#endif
 
51