summaryrefslogtreecommitdiff
path: root/implementation/utility/src/criticalsection.cpp
blob: 197ca4d34a9dff96838eaec6c085ea92c0ae697e (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
// Copyright (C) 2016-2021 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/.
#include "../include/criticalsection.hpp"

#ifdef _WIN32

#include <Windows.h>

namespace vsomeip_v3 {

    struct CriticalSection::Impl final {
        CRITICAL_SECTION m_criticalSection;
    };


    CriticalSection::CriticalSection()
    : m_impl(new CriticalSection::Impl()) {
        InitializeCriticalSection(&m_impl->m_criticalSection);
    }

    CriticalSection::~CriticalSection() {
        DeleteCriticalSection(&m_impl->m_criticalSection);
    }

    void CriticalSection::lock() {
        EnterCriticalSection(&m_impl->m_criticalSection);
    }

    bool CriticalSection::try_lock() {
        return (TryEnterCriticalSection(&m_impl->m_criticalSection) != 0);
    }

    void CriticalSection::unlock(){
        LeaveCriticalSection(&m_impl->m_criticalSection);
    }

} // namespace vsomeip_v3

#endif