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
51 };
52
53 // process-wide singular instance
54 inline static std::weak_ptr<InitImpl> init_instance; // GLOBAL
55 inline static std::mutex the_instance_mutex; // GLOBAL
56
57 // istance of this class to refcount
58 std::shared_ptr<InitImpl> initptr;
59
60 public:
62 {
63 const std::lock_guard<std::mutex> lock(the_instance_mutex);
64
65 initptr = init_instance.lock();
66 if (!initptr)
67 {
68 initptr = std::make_shared<InitImpl>();
70 }
71 }
72
74 {
75 // explicitly reset smart pointer to make the destructor run under the lock_guard
76 const std::lock_guard<std::mutex> lock(the_instance_mutex);
77 initptr.reset();
78 }
79};
80
81} // 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 uninit_openssl()
void init_openssl(const std::string &engine)
void base64_uninit_static()
Definition base64.hpp:310
void base64_init_static()
Definition base64.hpp:302