| 1 | #ifndef _EVENT_QUEUE_H_ |
| 2 | #define _EVENT_QUEUE_H_ |
| 3 | /* Copyright (c) 2004, 2010, 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 | |
| 20 | @addtogroup Event_Scheduler |
| 21 | @{ |
| 22 | |
| 23 | @file event_queue.h |
| 24 | |
| 25 | Queue of events awaiting execution. |
| 26 | */ |
| 27 | |
| 28 | #ifdef HAVE_PSI_INTERFACE |
| 29 | extern PSI_mutex_key key_LOCK_event_queue; |
| 30 | extern PSI_cond_key key_COND_queue_state; |
| 31 | #endif /* HAVE_PSI_INTERFACE */ |
| 32 | |
| 33 | #include "queues.h" // QUEUE |
| 34 | #include "sql_string.h" /* LEX_CSTRING */ |
| 35 | #include "my_time.h" /* my_time_t, interval_type */ |
| 36 | |
| 37 | class Event_basic; |
| 38 | class Event_queue_element; |
| 39 | class Event_queue_element_for_exec; |
| 40 | |
| 41 | class THD; |
| 42 | |
| 43 | /** |
| 44 | Queue of active events awaiting execution. |
| 45 | */ |
| 46 | |
| 47 | class Event_queue |
| 48 | { |
| 49 | public: |
| 50 | Event_queue(); |
| 51 | ~Event_queue(); |
| 52 | |
| 53 | bool |
| 54 | init_queue(THD *thd); |
| 55 | |
| 56 | /* Methods for queue management follow */ |
| 57 | |
| 58 | bool |
| 59 | create_event(THD *thd, Event_queue_element *new_element, |
| 60 | bool *created); |
| 61 | |
| 62 | void |
| 63 | update_event(THD *thd, const LEX_CSTRING *dbname, const LEX_CSTRING *name, |
| 64 | Event_queue_element *new_element); |
| 65 | |
| 66 | void |
| 67 | drop_event(THD *thd, const LEX_CSTRING *dbname, const LEX_CSTRING *name); |
| 68 | |
| 69 | void |
| 70 | drop_schema_events(THD *thd, const LEX_CSTRING *schema); |
| 71 | |
| 72 | void |
| 73 | recalculate_activation_times(THD *thd); |
| 74 | |
| 75 | bool |
| 76 | get_top_for_execution_if_time(THD *thd, |
| 77 | Event_queue_element_for_exec **event_name); |
| 78 | |
| 79 | |
| 80 | void |
| 81 | dump_internal_status(); |
| 82 | |
| 83 | private: |
| 84 | void |
| 85 | empty_queue(); |
| 86 | |
| 87 | void |
| 88 | deinit_queue(); |
| 89 | /* helper functions for working with mutexes & conditionals */ |
| 90 | void |
| 91 | lock_data(const char *func, uint line); |
| 92 | |
| 93 | void |
| 94 | unlock_data(const char *func, uint line); |
| 95 | |
| 96 | void |
| 97 | cond_wait(THD *thd, struct timespec *abstime, const PSI_stage_info *stage, |
| 98 | const char *src_func, const char *src_file, uint src_line); |
| 99 | |
| 100 | void |
| 101 | find_n_remove_event(const LEX_CSTRING *db, const LEX_CSTRING *name); |
| 102 | |
| 103 | |
| 104 | void |
| 105 | drop_matching_events(THD *thd, const LEX_CSTRING *pattern, |
| 106 | bool (*)(const LEX_CSTRING*, Event_basic *)); |
| 107 | |
| 108 | |
| 109 | void |
| 110 | dbug_dump_queue(my_time_t now); |
| 111 | |
| 112 | /* LOCK_event_queue is the mutex which protects the access to the queue. */ |
| 113 | mysql_mutex_t LOCK_event_queue; |
| 114 | mysql_cond_t COND_queue_state; |
| 115 | |
| 116 | /* The sorted queue with the Event_queue_element objects */ |
| 117 | QUEUE queue; |
| 118 | |
| 119 | my_time_t next_activation_at; |
| 120 | |
| 121 | uint mutex_last_locked_at_line; |
| 122 | uint mutex_last_unlocked_at_line; |
| 123 | uint mutex_last_attempted_lock_at_line; |
| 124 | const char* mutex_last_locked_in_func; |
| 125 | const char* mutex_last_unlocked_in_func; |
| 126 | const char* mutex_last_attempted_lock_in_func; |
| 127 | bool mutex_queue_data_locked; |
| 128 | bool mutex_queue_data_attempting_lock; |
| 129 | bool waiting_on_cond; |
| 130 | }; |
| 131 | /** |
| 132 | @} (End of group Event_Scheduler) |
| 133 | */ |
| 134 | |
| 135 | #endif /* _EVENT_QUEUE_H_ */ |
| 136 | |