OnixS C++ B3 BOE Binary Order Entry  1.2.0
API Documentation
Mutex.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
22 #include <OnixS/B3/BOE/ABI.h>
23 
24 namespace OnixS {
25 namespace B3 {
26 namespace BOE {
27 namespace Threading {
28 
29 /// Mutex.
30 ///
31 /// Protects resources from simultaneous access by multiple threads.
32 ///
33 /// Only one thread at a time can own instance of this class.
34 ///
35 /// This implementation is optimized for locking threads that are in the same process.
36 ///
37 /// \note It is NOT suitable for interprocess synchronization.
38 /// \note Recursive locking is NOT supported.
40 {
41 public:
43 
44  /// Initializes the instance.
45  Mutex();
46 
47  /// Destructs the instance.
48  ~Mutex();
49 
50  /// Acquires the lock ownership.
51  ///
52  /// If the mutex is already occupied by another thread
53  /// blocks the current thread and waits until it
54  /// will be released by the owner.
55  void acquire();
56 
57  /// Tries to acquires the lock ownership.
58  ///
59  /// \return `false` if the mutex is already occupied by another thread,
60  /// otherwise - `true`.
61  bool tryAcquire();
62 
63  /// Releases the ownership (lock) and
64  /// unblocks one of the waiting threads.
65  void release();
66 
67 private:
68  void * impl_;
69 
70  // Copying & assignment is prohibited.
71  Mutex(const Mutex &);
72  Mutex & operator = (const Mutex &);
73 };
74 }
75 }
76 }
77 }
#define ONIXS_B3_BOE_API_DECL(typeKind, typeName)
Definition: ABI.h:29
#define ONIXS_B3_BOE_EXPORTED
Definition: Compiler.h:181
Definition: Defines.h:40
Condition variable - a synchronization objects that allows threads to wait for certain events (condit...
Definition: Condition.h:36