Debian Codegraph @

src/Main/MultipleInstanceLock.hxx

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2025 James Turner
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <optional>
7 #include <string>
8
9 #include <simgear/misc/sg_path.hxx>
10
11 namespace flightgear {
12
13 /**
14 * @brief RAII object to ensure only a single instance of FG is running
15 * a particular section of code.
16 *
17 */
18 class ExclusiveInstanceLock
19 {
20 public:
21 static ExclusiveInstanceLock* instance();
22
23 static ExclusiveInstanceLock* createInstance(const std::string& reason);
24
25 static void destroyInstance();
26
27 ~ExclusiveInstanceLock();
28
29 // @brief update the reason code, without releasing the lock
30 void updateReason(const std::string& reason);
31
32 /** check if another instance of FG is holding the exclusive lock */
33 static std::optional<std::string> isLocked();
34
35 /**
36 * @brief show a dialog telling the user to wait until the exclusive lock is
37 * released by another copy of FG
38 *
39 */
40 static bool showWaitDialog();
41
42 private:
43 ExclusiveInstanceLock(std::string reason);
44
45 std::string _reason;
46 SGPath _lockPath;
47 };
48
49
50 } // namespace flightgear