My Project
event_queue.h
Go to the documentation of this file.
00001 #ifndef _EVENT_QUEUE_H_
00002 #define _EVENT_QUEUE_H_
00003 /* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; version 2 of the License.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software Foundation,
00016    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
00017 
00028 #ifdef HAVE_PSI_INTERFACE
00029 extern PSI_mutex_key key_LOCK_event_queue;
00030 extern PSI_cond_key key_COND_queue_state;
00031 #endif /* HAVE_PSI_INTERFACE */
00032 
00033 #include "queues.h"                             // QUEUE
00034 #include "sql_string.h"                         /* LEX_STRING */
00035 #include "my_time.h"                    /* my_time_t, interval_type */
00036 
00037 class Event_basic;
00038 class Event_queue_element;
00039 class Event_queue_element_for_exec;
00040 
00041 class THD;
00042 
00047 class Event_queue
00048 {
00049 public:
00050   Event_queue();
00051   ~Event_queue();
00052 
00053   bool
00054   init_queue(THD *thd);
00055 
00056   /* Methods for queue management follow */
00057 
00058   bool
00059   create_event(THD *thd, Event_queue_element *new_element,
00060                bool *created);
00061 
00062   void
00063   update_event(THD *thd, LEX_STRING dbname, LEX_STRING name,
00064                Event_queue_element *new_element);
00065 
00066   void
00067   drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
00068 
00069   void
00070   drop_schema_events(THD *thd, LEX_STRING schema);
00071 
00072   void
00073   recalculate_activation_times(THD *thd);
00074 
00075   bool
00076   get_top_for_execution_if_time(THD *thd,
00077                                 Event_queue_element_for_exec **event_name);
00078 
00079 
00080   void
00081   dump_internal_status();
00082 
00083 private:
00084   void
00085   empty_queue();
00086 
00087   void
00088   deinit_queue();
00089   /* helper functions for working with mutexes & conditionals */
00090   void
00091   lock_data(const char *func, uint line);
00092 
00093   void
00094   unlock_data(const char *func, uint line);
00095 
00096   void
00097   cond_wait(THD *thd, struct timespec *abstime, const PSI_stage_info *stage,
00098             const char *src_func, const char *src_file, uint src_line);
00099 
00100   void
00101   find_n_remove_event(LEX_STRING db, LEX_STRING name);
00102 
00103 
00104   void
00105   drop_matching_events(THD *thd, LEX_STRING pattern,
00106                        bool (*)(LEX_STRING, Event_basic *));
00107 
00108 
00109   void
00110   dbug_dump_queue(time_t now);
00111 
00112   /* LOCK_event_queue is the mutex which protects the access to the queue. */
00113   mysql_mutex_t LOCK_event_queue;
00114   mysql_cond_t COND_queue_state;
00115 
00116   /* The sorted queue with the Event_queue_element objects */
00117   QUEUE queue;
00118 
00119   my_time_t next_activation_at;
00120 
00121   uint mutex_last_locked_at_line;
00122   uint mutex_last_unlocked_at_line;
00123   uint mutex_last_attempted_lock_at_line;
00124   const char* mutex_last_locked_in_func;
00125   const char* mutex_last_unlocked_in_func;
00126   const char* mutex_last_attempted_lock_in_func;
00127   bool mutex_queue_data_locked;
00128   bool mutex_queue_data_attempting_lock;
00129   bool waiting_on_cond;
00130 };
00135 #endif /* _EVENT_QUEUE_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines