event_queue.h 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#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
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   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 */

19
class Event_basic;
20
class Event_db_repository;
21
class Event_job_data;
22
class Event_queue_element;
23 24

class THD;
25
class Event_scheduler;
26 27 28 29 30 31

class Event_queue
{
public:
  Event_queue();

32
  void
33
  init_mutexes();
34

35 36
  void
  deinit_mutexes();
37

38
  bool
39
  init_queue(THD *thd, Event_db_repository *db_repo);
40 41
  
  void
42
  deinit_queue();
43 44 45 46

  /* Methods for queue management follow */

  int
47
  create_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
48 49

  int
50 51
  update_event(THD *thd, LEX_STRING dbname, LEX_STRING name,
               LEX_STRING *new_schema, LEX_STRING *new_name);
52

53 54
  void
  drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
55

56
  void
57 58 59
  drop_schema_events(THD *thd, LEX_STRING schema);

  void
60
  recalculate_activation_times(THD *thd);
61

62
  bool
63
  get_top_for_execution_if_time(THD *thd, Event_job_data **job_data);
64 65 66

  void
  dump_internal_status();
67

unknown's avatar
unknown committed
68 69 70
  int
  load_events_from_db(THD *thd);

71
protected:
72
  void
73
  find_n_remove_event(LEX_STRING db, LEX_STRING name);
74 75 76 77


  void
  drop_matching_events(THD *thd, LEX_STRING pattern,
78
                       bool (*)(LEX_STRING, Event_basic *));
79 80 81

  void
  empty_queue();
82

unknown's avatar
unknown committed
83 84 85
  void
  dbug_dump_queue(time_t now);

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

  Event_db_repository *db_repository;

unknown's avatar
unknown committed
92 93 94 95 96
  Event_scheduler *scheduler;

  /* The sorted queue with the Event_job_data objects */
  QUEUE queue;

97 98
  TIME next_activation_at;

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

109 110 111 112 113 114
  /* helper functions for working with mutexes & conditionals */
  void
  lock_data(const char *func, uint line);

  void
  unlock_data(const char *func, uint line);
115 116 117 118

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

121
#endif /* _EVENT_QUEUE_H_ */