blob: 2040b74115771142b9a965e2a1c630b38b1c2ed6 (
plain)
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
|
// Copyright (C) 2016-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef VSOMEIP_V3_CRITICALSECTION_HPP
#define VSOMEIP_V3_CRITICALSECTION_HPP
#include <memory>
#include <mutex>
namespace vsomeip_v3 {
#ifdef _WIN32
// Windows: CriticalSection uses win32 CRITICAL_SECTION.
// Interface mimics std::mutex so we can use it in
// conjunction with std::unique_lock.
class CriticalSection final {
public:
CriticalSection();
~CriticalSection();
// prevent copying
CriticalSection(const CriticalSection&) = delete;
CriticalSection& operator=(const CriticalSection&) = delete;
void lock();
void unlock();
bool try_lock();
private:
struct Impl;
std::unique_ptr<Impl> m_impl;
};
#else
// Linux: CriticalSection is a type alias for std::mutex.
using CriticalSection = std::mutex;
#endif
} // namespace vsomeip_v3
#endif //VSOMEIP_V3_CRITICALSECTION_HPP
|