aboutsummaryrefslogtreecommitdiffstats
path: root/fsa/src/vespa/fsamanagers/mutex.h
blob: d03bfa87cdd371125ea6a79c7f4b968e7f7d9c84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * @author  Peter Boros
 * @date    2004/09/07
 * @version $Id$
 * @file    mutex.h
 * @brief   Mutex.
 *
 */

#pragma once

// {{{ class Mutex

namespace fsa {

/**
 * @class Mutex
 * @brief Mutex.
 *
 * Simple mutex class based on POSIX pthread_mutex_t.
 */
class Mutex
{
 protected:
  struct Impl;
  Impl *_impl;

 public:
  /**
   * @brief Constructor
   */
  Mutex(void);

  /**
   * @brief Destructor
   */
  ~Mutex(void);

  /**
   * @brief Try to get a lock.
   *
   * Try to get a lock. This method is non-blocking, and
   * returns true if locking was succesful.
   *
   * @return True if locking was successful.
   */
  bool tryLock (void);

  /**
   * @brief Get a lock.
   *
   * Get a read (shared) lock. This method blocks until a
   * lock is available (that is no other thread holds a
   * lock on the object.)
   *
   * @return True if locking was successful.
   */
  bool lock (void);

  /**
   * @brief Release a lock.
   *
   * @return True if unlocking was successful.
   */
  bool unlock (void);

};

// }}}

} // namespace fsa