event_queue.h 2.68 KB
Newer Older
1 2 3 4 5 6
#ifndef _EVENT_QUEUE_H_
#define _EVENT_QUEUE_H_
/* Copyright (C) 2004-2006 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
unknown's avatar
unknown committed
7
   the Free Software Foundation; version 2 of the License.
8 9 10 11 12 13 14 15 16 17

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

18 19
class Event_basic;
class Event_queue_element;
20
class Event_queue_element_for_exec;
21 22 23 24 25 26 27

class THD;

class Event_queue
{
public:
  Event_queue();
28
  ~Event_queue();
29

30
  bool
31
  init_queue(THD *thd);
32

33 34
  /* Methods for queue management follow */

35 36 37
  bool
  create_event(THD *thd, Event_queue_element *new_element,
               bool *created);
38

39
  void
40
  update_event(THD *thd, LEX_STRING dbname, LEX_STRING name,
41
               Event_queue_element *new_element);
42

43 44
  void
  drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
45

46
  void
47 48 49
  drop_schema_events(THD *thd, LEX_STRING schema);

  void
50
  recalculate_activation_times(THD *thd);
51

52
  bool
53 54 55
  get_top_for_execution_if_time(THD *thd,
                                Event_queue_element_for_exec **event_name);

56 57 58

  void
  dump_internal_status();
59

60
private:
61 62
  void
  empty_queue();
63 64 65 66 67 68 69 70 71 72 73 74 75 76

  void
  deinit_queue();
  /* helper functions for working with mutexes & conditionals */
  void
  lock_data(const char *func, uint line);

  void
  unlock_data(const char *func, uint line);

  void
  cond_wait(THD *thd, struct timespec *abstime, const char* msg,
            const char *func, uint line);

77
  void
78
  find_n_remove_event(LEX_STRING db, LEX_STRING name);
79 80 81 82


  void
  drop_matching_events(THD *thd, LEX_STRING pattern,
83
                       bool (*)(LEX_STRING, Event_basic *));
84

85

unknown's avatar
unknown committed
86 87 88
  void
  dbug_dump_queue(time_t now);

89 90
  /* LOCK_event_queue is the mutex which protects the access to the queue. */
  pthread_mutex_t LOCK_event_queue;
91
  pthread_cond_t COND_queue_state;
92

93
  /* The sorted queue with the Event_queue_element objects */
unknown's avatar
unknown committed
94 95
  QUEUE queue;

96
  my_time_t next_activation_at;
97

98 99
  uint mutex_last_locked_at_line;
  uint mutex_last_unlocked_at_line;
100
  uint mutex_last_attempted_lock_at_line;
101 102
  const char* mutex_last_locked_in_func;
  const char* mutex_last_unlocked_in_func;
103
  const char* mutex_last_attempted_lock_in_func;
104
  bool mutex_queue_data_locked;
105
  bool mutex_queue_data_attempting_lock;
106
  bool waiting_on_cond;
107

108 109
};

110
#endif /* _EVENT_QUEUE_H_ */