You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
3.1 KiB

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