My Project
event_scheduler.h
Go to the documentation of this file.
00001 #ifndef _EVENT_SCHEDULER_H_
00002 #define _EVENT_SCHEDULER_H_
00003 /* Copyright (c) 2004, 2013, 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 
00034 class Event_queue;
00035 class Event_job_data;
00036 class Event_db_repository;
00037 class Event_queue_element_for_exec;
00038 class Events;
00039 class THD;
00040 
00041 void
00042 pre_init_event_thread(THD* thd);
00043 
00044 bool
00045 post_init_event_thread(THD* thd);
00046 
00047 void
00048 deinit_event_thread(THD *thd);
00049 
00050 
00051 class Event_worker_thread
00052 {
00053 public:
00054   static void
00055   init(Event_db_repository *db_repository_arg)
00056   {
00057     db_repository= db_repository_arg;
00058   }
00059 
00060   void
00061   run(THD *thd, Event_queue_element_for_exec *event);
00062 
00063 private:
00064   void
00065   print_warnings(THD *thd, Event_job_data *et);
00066 
00067   static Event_db_repository *db_repository;
00068 };
00069 
00070 
00071 class Event_scheduler
00072 {
00073 public:
00074   Event_scheduler(Event_queue *event_queue_arg);
00075   ~Event_scheduler();
00076 
00077 
00078   /* State changing methods follow */
00079 
00080   bool
00081   start(int *err_no);
00082 
00083   bool
00084   stop();
00085 
00086   /*
00087     Need to be public because has to be called from the function
00088     passed to pthread_create.
00089   */
00090   bool
00091   run(THD *thd);
00092 
00093 
00094   /* Information retrieving methods follow */
00095   bool
00096   is_running();
00097 
00098   void
00099   dump_internal_status();
00100 
00101 private:
00102   uint
00103   workers_count();
00104 
00105   /* helper functions */
00106   bool
00107   execute_top(Event_queue_element_for_exec *event_name);
00108 
00109   /* helper functions for working with mutexes & conditionals */
00110   void
00111   lock_data(const char *func, uint line);
00112 
00113   void
00114   unlock_data(const char *func, uint line);
00115 
00116   void
00117   cond_wait(THD *thd, struct timespec *abstime, const PSI_stage_info *stage,
00118             const char *src_func, const char *src_file, uint src_line);
00119 
00120   mysql_mutex_t LOCK_scheduler_state;
00121 
00122   enum enum_state
00123   {
00124     INITIALIZED = 0,
00125     RUNNING,
00126     STOPPING
00127   };
00128 
00129   /* This is the current status of the life-cycle of the scheduler. */
00130   enum enum_state state;
00131 
00132   THD *scheduler_thd;
00133 
00134   mysql_cond_t COND_state;
00135 
00136   Event_queue *queue;
00137 
00138   uint mutex_last_locked_at_line;
00139   uint mutex_last_unlocked_at_line;
00140   const char* mutex_last_locked_in_func;
00141   const char* mutex_last_unlocked_in_func;
00142   bool mutex_scheduler_data_locked;
00143   bool waiting_on_cond;
00144 
00145   ulonglong started_events;
00146 
00147 private:
00148   /* Prevent use of these */
00149   Event_scheduler(const Event_scheduler &);
00150   void operator=(Event_scheduler &);
00151 };
00152 
00157 #endif /* _EVENT_SCHEDULER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines