1#ifndef _EVENT_SCHEDULER_H_
2#define _EVENT_SCHEDULER_H_
3/* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
17
18/**
19 @addtogroup Event_Scheduler
20 @{
21*/
22/**
23 @file
24
25 Declarations of the scheduler thread class
26 and related functionality.
27
28 This file is internal to Event_Scheduler module. Please do not
29 include it directly. All public declarations of Event_Scheduler
30 module are in events.h and event_data_objects.h.
31*/
32
33
34class Event_queue;
35class Event_job_data;
36class Event_db_repository;
37class Event_queue_element_for_exec;
38class Events;
39class THD;
40
41void
42pre_init_event_thread(THD* thd);
43
44bool
45post_init_event_thread(THD* thd);
46
47void
48deinit_event_thread(THD *thd);
49
50
51class Event_worker_thread
52{
53public:
54 static void
55 init(Event_db_repository *db_repository_arg)
56 {
57 db_repository= db_repository_arg;
58 }
59
60 void
61 run(THD *thd, Event_queue_element_for_exec *event);
62
63private:
64 void
65 print_warnings(THD *thd, Event_job_data *et);
66
67 static Event_db_repository *db_repository;
68};
69
70
71class Event_scheduler
72{
73public:
74 Event_scheduler(Event_queue *event_queue_arg);
75 ~Event_scheduler();
76
77
78 /* State changing methods follow */
79
80 bool
81 start(int *err_no);
82
83 bool
84 stop();
85
86 /*
87 Need to be public because has to be called from the function
88 passed to pthread_create.
89 */
90 bool
91 run(THD *thd);
92
93
94 /* Information retrieving methods follow */
95 bool
96 is_running();
97
98 void
99 dump_internal_status();
100
101private:
102 uint
103 workers_count();
104
105 /* helper functions */
106 bool
107 execute_top(Event_queue_element_for_exec *event_name);
108
109 /* helper functions for working with mutexes & conditionals */
110 void
111 lock_data(const char *func, uint line);
112
113 void
114 unlock_data(const char *func, uint line);
115
116 void
117 cond_wait(THD *thd, struct timespec *abstime, const PSI_stage_info *stage,
118 const char *src_func, const char *src_file, uint src_line);
119
120 mysql_mutex_t LOCK_scheduler_state;
121
122 enum enum_state
123 {
124 INITIALIZED = 0,
125 RUNNING,
126 STOPPING
127 };
128
129 /* This is the current status of the life-cycle of the scheduler. */
130 enum enum_state state;
131
132 THD *scheduler_thd;
133
134 mysql_cond_t COND_state;
135
136 Event_queue *queue;
137
138 uint mutex_last_locked_at_line;
139 uint mutex_last_unlocked_at_line;
140 const char* mutex_last_locked_in_func;
141 const char* mutex_last_unlocked_in_func;
142 bool mutex_scheduler_data_locked;
143 bool waiting_on_cond;
144
145 ulonglong started_events;
146
147private:
148 /* Prevent use of these */
149 Event_scheduler(const Event_scheduler &);
150 void operator=(Event_scheduler &);
151};
152
153/**
154 @} (End of group Event_Scheduler)
155*/
156
157#endif /* _EVENT_SCHEDULER_H_ */
158