MySQL 8.1.0
Source Code Documentation
process_state_component.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2023, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef MYSQL_HARNESS_PROCESS_STATE_COMPONENT_INCLUDED
26#define MYSQL_HARNESS_PROCESS_STATE_COMPONENT_INCLUDED
27
28#include <string>
29
30#include "harness_export.h"
32
33namespace mysql_harness {
34// set when the Router receives a signal to shut down or some fatal error
35// condition occurred
36class HARNESS_EXPORT ShutdownPending {
37 public:
38 /**
39 * Reason for shutdown.
40 */
41 enum class Reason { NONE, REQUESTED, FATAL_ERROR };
42
43 [[nodiscard]] std::string message() const { return message_; }
44 void message(const std::string &msg) { message_ = msg; }
45
46 [[nodiscard]] Reason reason() const { return reason_; }
47 void reason(Reason r) { reason_ = r; }
48
49 private:
51 std::string message_;
52};
53
54/**
55 * manages the state of the process.
56 *
57 * allows to shutdown the current process in a
58 *
59 * - thread safe
60 * - waitable
61 *
62 * way.
63 *
64 * To be used
65 *
66 * - by the signal-handler to mark the process for shutdown,
67 * - and by the Loader to wait for a shutdown to happen.
68 */
69class HARNESS_EXPORT ProcessStateComponent {
70 public:
71 static ProcessStateComponent &get_instance();
72
73 using key_type = std::string;
74
75 // disable copy, as we are a single-instance
77 void operator=(ProcessStateComponent const &) = delete;
78
79 // no move either
82
83 void clear();
84
85 /**
86 * request application shutdown.
87 *
88 * @param reason reason for the shutdown
89 * @param msg human readable reason of the shutdown
90 * @throws std::system_error same as std::unique_lock::lock does
91 */
92 void request_application_shutdown(
94 const std::string &msg = {});
95
96 /**
97 * pending shutdown state.
98 *
99 * - synchronized
100 * - waitable
101 */
103 return shutdown_pending_;
104 }
105
106 private:
108
109 WaitableMonitor<ShutdownPending> shutdown_pending_{{}};
110};
111
112} // namespace mysql_harness
113
114#endif
Monitor can be waited for.
Definition: monitor.h:61
manages the state of the process.
Definition: process_state_component.h:69
void operator=(ProcessStateComponent &&)=delete
WaitableMonitor< ShutdownPending > & shutdown_pending()
pending shutdown state.
Definition: process_state_component.h:102
ProcessStateComponent(ProcessStateComponent const &)=delete
ProcessStateComponent(ProcessStateComponent &&)=delete
void operator=(ProcessStateComponent const &)=delete
std::string key_type
Definition: process_state_component.h:73
Definition: process_state_component.h:36
void message(const std::string &msg)
Definition: process_state_component.h:44
Reason
Reason for shutdown.
Definition: process_state_component.h:41
std::string message_
Definition: process_state_component.h:51
std::string message() const
Definition: process_state_component.h:43
void reason(Reason r)
Definition: process_state_component.h:47
Reason reason() const
Definition: process_state_component.h:46
Definition: common.h:41
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85