MySQL 8.3.0
Source Code Documentation
mysql_scheduler.h
Go to the documentation of this file.
1/* Copyright (c) 2023, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is also distributed with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MYSQL_SCHEDULER_H
24#define MYSQL_SCHEDULER_H
25
28
29/**
30 @ingroup group_components_services_inventory
31
32 The Scheduler queueing interface.
33
34 This is a service that will allow registering a callback to be called
35 every X seconds.
36
37 Each callback has a name. And a comment for the DBA to check.
38
39 A caller registers a callback together with its argument and gets a handle
40 back. The callback will be put in rotation immediately and will be called
41 after the defined interval. And it will keep being called until it's
42 unregisterered using the handle.
43
44 Passing an argument is useful if you are to reuse the callback function
45 to operate on many different states through registering it in multiple
46 scheduled events.
47 Having the argument passed down from the registering code to the callback
48 saves the need of the callback to consult a global structure in a multi-
49 thread safe fashion.
50
51 @warning Keep the runnable function *SHORT*! Or design a way for it to be
52 graciously shut down through a flag inside the argument.
53
54 To use it one would do something like this:
55
56 @code
57 bool sheduled_callback(mysql_scheduler_runnable_handle handle, void *arg) {
58 int *ctr = reinterpret_cast<std::atomic<int> *>(arg);
59 *ctr++;
60 }
61
62 REQUIRES_SERVICE(mysql_scheduler);
63
64 int caller() {
65 std::atomic<int> data= 0;
66 mysql_scheduler_runnable_handle handle = nullptr;
67 mysql_service_mysql_scheduler->create(
68 &handle, sheduled_callback,
69 (void *)&data,
70 "gizmo", "This is a sheduled task to call gizmo",
71 10);
72
73 ....
74
75 mysql_service_mysql_scheduler->destroy(handle);
76 handle = nullptr;
77 }
78 @endcode
79
80 @sa @ref mysql_scheduler_runnable_handle,
81 @ref mysql_scheduler_runnable_function
82
83*/
85
86/**
87 Schedule a runnable task
88
89 @param[out] out_handle The context of the newly scheduled task. To be kept
90 as an interaction vector with the running task.
91 @param runnable The function to call
92 @param arg An argument to pass to the runnable.
93 Must be valid until unregistered.
94 @param name The name of the runnable in UTF8.
95 @param comment A free form comment in UTF8. No more than 1024 bytes.
96 @param interval_secs How frequently to schedule the task (in seconds).
97 Must be greater than 1 since this is the resolution.
98 @retval false success
99 @retval true failure
100*/
103 mysql_scheduler_runnable_function runnable, void *arg,
104 const char *name, const char *comment, int interval_secs));
105
106/**
107 End a scheduled task/subtask
108
109 This will:
110 * unschedule the task
111 * wait for the scheduled task runnable to end, if running currently
112
113 @param handle The context of the task to end
114 @retval false success
115 @retval true failure
116*/
118
120
121#endif /* MYSQL_SCHEDULER_H */
int destroy(azio_stream *s)
Definition: azio.cc:371
#define comment
Definition: lexyy.cc:959
struct mysql_scheduler_runnable_handle_imp * mysql_scheduler_runnable_handle
The hande to the runnable, to use in deregistration.
Definition: mysql_scheduler_bits.h:29
bool(* mysql_scheduler_runnable_function)(mysql_scheduler_runnable_handle handle, void *arg)
the callback function pointer signature
Definition: mysql_scheduler_bits.h:32
static mysql_service_status_t create(const char *service_names[], reference_caching_channel *out_channel) noexcept
Definition: component.cc:44
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:63
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:90
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:111
case opt name
Definition: sslopt-case.h:32