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, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 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, version 2.0, 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 Foundation, 23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 24 25 /** 26 @addtogroup Event_Scheduler 27 @{ 28 */ 29 /** 30 @file 31 32 Declarations of the scheduler thread class 33 and related functionality. 34 35 This file is internal to Event_Scheduler module. Please do not 36 include it directly. All public declarations of Event_Scheduler 37 module are in events.h and event_data_objects.h. 38 */ 39 40 41 class Event_queue; 42 class Event_job_data; 43 class Event_db_repository; 44 class Event_queue_element_for_exec; 45 class Events; 46 class THD; 47 48 void 49 pre_init_event_thread(THD* thd); 50 51 bool 52 post_init_event_thread(THD* thd); 53 54 void 55 deinit_event_thread(THD *thd); 56 57 58 class Event_worker_thread 59 { 60 public: 61 static void init(Event_db_repository * db_repository_arg)62 init(Event_db_repository *db_repository_arg) 63 { 64 db_repository= db_repository_arg; 65 } 66 67 void 68 run(THD *thd, Event_queue_element_for_exec *event); 69 70 private: 71 void 72 print_warnings(THD *thd, Event_job_data *et); 73 74 static Event_db_repository *db_repository; 75 }; 76 77 78 class Event_scheduler 79 { 80 public: 81 Event_scheduler(Event_queue *event_queue_arg); 82 ~Event_scheduler(); 83 84 85 /* State changing methods follow */ 86 87 bool 88 start(int *err_no); 89 90 bool 91 stop(); 92 93 /* 94 Need to be public because has to be called from the function 95 passed to pthread_create. 96 */ 97 bool 98 run(THD *thd); 99 100 101 /* Information retrieving methods follow */ 102 bool 103 is_running(); 104 105 void 106 dump_internal_status(); 107 108 private: 109 uint 110 workers_count(); 111 112 /* helper functions */ 113 bool 114 execute_top(Event_queue_element_for_exec *event_name); 115 116 /* helper functions for working with mutexes & conditionals */ 117 void 118 lock_data(const char *func, uint line); 119 120 void 121 unlock_data(const char *func, uint line); 122 123 void 124 cond_wait(THD *thd, struct timespec *abstime, const PSI_stage_info *stage, 125 const char *src_func, const char *src_file, uint src_line); 126 127 mysql_mutex_t LOCK_scheduler_state; 128 129 enum enum_state 130 { 131 INITIALIZED = 0, 132 RUNNING, 133 STOPPING 134 }; 135 136 /* This is the current status of the life-cycle of the scheduler. */ 137 enum enum_state state; 138 139 THD *scheduler_thd; 140 141 mysql_cond_t COND_state; 142 143 Event_queue *queue; 144 145 uint mutex_last_locked_at_line; 146 uint mutex_last_unlocked_at_line; 147 const char* mutex_last_locked_in_func; 148 const char* mutex_last_unlocked_in_func; 149 bool mutex_scheduler_data_locked; 150 bool waiting_on_cond; 151 152 ulonglong started_events; 153 154 private: 155 /* Prevent use of these */ 156 Event_scheduler(const Event_scheduler &); 157 void operator=(Event_scheduler &); 158 }; 159 160 /** 161 @} (End of group Event_Scheduler) 162 */ 163 164 #endif /* _EVENT_SCHEDULER_H_ */ 165