MySQL 9.3.0
Source Code Documentation
task_control.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2025, 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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_HELPER_TASK_CONTROL_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_HELPER_TASK_CONTROL_H_
28
30
32
34
35namespace helper {
36
37enum State {
42};
43
44template <typename T>
45class TaskControl : public T {
46 public:
47 template <typename... Args>
48 TaskControl(Args &&...args) : T(std::forward<Args>(args)...) {}
49
50 void task_suspend() {
51 log_debug("TaskControl::susspend");
52 if (state_.exchange({k_stateRunning}, k_stateSuspended)) {
53 T::stop();
54 }
55 }
56
57 void task_resume() {
58 log_debug("TaskControl::resume");
59 if (state_.exchange({k_stateSuspended}, k_stateRunning)) {
60 }
61 }
62
63 public:
64 void start() override {
65 log_debug("TaskControl::start");
66 if (state_.exchange(k_stateInitialize, k_stateSuspended)) {
67 State fetched;
68 bool was_running{false};
69 do {
70 fetched = state_.wait({k_stateRunning, k_stateStopped});
71
72 if (was_running) {
73 log_debug("TaskControl::start - reset()");
74 T::reset();
75 was_running = false;
76 }
77 if (fetched == k_stateRunning) {
78 was_running = true;
79 log_debug("TaskControl::start - start()");
80 T::start();
81 }
82
83 } while (fetched != k_stateStopped);
84 }
85
86 log_debug("TaskControl::start stopping");
87
88 state_.set(k_stateStopped);
89 }
90
91 void stop() override {
92 if (state_.exchange({k_stateInitialize, k_stateRunning, k_stateSuspended},
94 log_debug("TaskControl::stop");
95 T::stop();
96 }
97 }
98
99 private:
101};
102
103} // namespace helper
104
105#endif /* ROUTER_SRC_MYSQL_REST_SERVICE_SRC_HELPER_TASK_CONTROL_H_ */
Definition: wait_variable.h:34
Definition: task_control.h:45
void task_resume()
Definition: task_control.h:57
void stop() override
Definition: task_control.h:91
TaskControl(Args &&...args)
Definition: task_control.h:48
void start() override
Definition: task_control.h:64
void task_suspend()
Definition: task_control.h:50
Log log_debug(std::cout, "DEBUG")
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
#define T
Definition: jit_executor_value.cc:373
Logging interface for using and extending the logging subsystem.
#define IMPORT_LOG_FUNCTIONS()
convenience macro to avoid common boilerplate
Definition: logging.h:323
static void stop(mysql_harness::PluginFuncEnv *)
Definition: mysql_rest_service_plugin.cc:351
std::string HARNESS_EXPORT reset()
get 'reset attributes' ESC sequence.
Definition: vt100.cc:37
Definition: cache.h:33
State
Definition: task_control.h:37
@ k_stateInitialize
Definition: task_control.h:38
@ k_stateRunning
Definition: task_control.h:39
@ k_stateStopped
Definition: task_control.h:41
@ k_stateSuspended
Definition: task_control.h:40
Definition: gcs_xcom_synode.h:64