OpenVPN 3 Core Library
Loading...
Searching...
No Matches
initprocess.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// Process-wide static initialization
13
14#pragma once
15
16#include <thread>
17#include <mutex>
18
21#include <openvpn/time/time.hpp>
24
25namespace openvpn::InitProcess {
26class Init
27{
28 private:
30 {
31 public:
33 {
34 // initialize time base
36
37 // initialize compression
39
40 // init OpenSSL if included
41 init_openssl("auto");
42
44 }
45
50 };
51
52 // process-wide singular instance
53 inline static std::weak_ptr<InitImpl> init_instance; // GLOBAL
54 inline static std::mutex the_instance_mutex; // GLOBAL
55
56 // istance of this class to refcount
57 std::shared_ptr<InitImpl> initptr;
58
59 public:
61 {
62 const std::lock_guard<std::mutex> lock(the_instance_mutex);
63
64 initptr = init_instance.lock();
65 if (!initptr)
66 {
67 initptr = std::make_shared<InitImpl>();
69 }
70 }
71
73 {
74 // explicitly reset smart pointer to make the destructor run under the lock_guard
75 const std::lock_guard<std::mutex> lock(the_instance_mutex);
76 initptr.reset();
77 }
78};
79
80} // namespace openvpn::InitProcess
static void init_static()
Definition compress.hpp:520
static std::weak_ptr< InitImpl > init_instance
static std::mutex the_instance_mutex
std::shared_ptr< InitImpl > initptr
static void reset_base()
Definition time.hpp:420
void init_openssl(const std::string &engine)
void base64_uninit_static()
Definition base64.hpp:310
void base64_init_static()
Definition base64.hpp:302