OpenVPN 3 Core Library
Loading...
Searching...
No Matches
bigmutex.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12// Macro to maintain thread-safety.
13
14// Platforms like UWP and iOS may call core methods
15// from another threads. Since core is not thread-safe,
16// we provide OPENVPN_ASYNC_HANDLER macro which instantiates
17// lock guard. It follows RIAA principle and locks global
18// mutex in constructor and unlocks in destructor. This
19// guarantees that code in block protected with this macro
20// won't be called simultaneously from different threads.
21
22#ifndef OPENVPN_COMMON_BIGMUTEX_H
23#define OPENVPN_COMMON_BIGMUTEX_H
24
25#include <mutex>
26
27namespace openvpn {
28namespace bigmutex {
29inline std::recursive_mutex the_recursive_mutex;
30}
31
32#ifdef OPENVPN_ENABLE_BIGMUTEX
33#define OPENVPN_ASYNC_HANDLER \
34 std::lock_guard<std::recursive_mutex> lg(bigmutex::the_recursive_mutex);
35#else
36#define OPENVPN_ASYNC_HANDLER
37#endif
38} // namespace openvpn
39
40#endif
std::recursive_mutex the_recursive_mutex
Definition bigmutex.hpp:29