mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / server-tools / instance-manager / guardian.h
blobc188075487dca42e7b8410a132dda6af8bbd54a4
1 #ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_GUARDIAN_H
2 #define INCLUDES_MYSQL_INSTANCE_MANAGER_GUARDIAN_H
3 /* Copyright (c) 2004-2006 MySQL AB
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
19 #include <my_global.h>
20 #include <my_sys.h>
21 #include <my_list.h>
23 #include "thread_registry.h"
25 #if defined(__GNUC__) && defined(USE_PRAGMA_INTERFACE)
26 #pragma interface
27 #endif
29 class Instance;
30 class Instance_map;
31 class Thread_registry;
33 /**
34 The guardian thread is responsible for monitoring and restarting of guarded
35 instances.
38 class Guardian: public Thread
40 public:
41 Guardian(Thread_registry *thread_registry_arg,
42 Instance_map *instance_map_arg);
43 ~Guardian();
45 void init();
47 public:
48 void request_shutdown();
50 bool is_stopped();
52 void lock();
53 void unlock();
55 void ping();
57 protected:
58 virtual void run();
60 private:
61 void stop_instances();
63 void process_instance(Instance *instance);
65 private:
67 LOCK_guardian protectes the members in this section:
68 - shutdown_requested;
69 - stopped;
71 Also, it is used for COND_guardian.
73 pthread_mutex_t LOCK_guardian;
76 Guardian's main loop waits on this condition. So, it should be signalled
77 each time, when instance state has been changed and we want Guardian to
78 wake up.
80 TODO: Change this to having data-scoped conditions, i.e. conditions,
81 which indicate that some data has been changed.
83 pthread_cond_t COND_guardian;
86 This variable is set to TRUE, when Manager thread is shutting down.
87 The flag is used by Guardian thread to understand that it's time to
88 finish.
90 bool shutdown_requested;
93 This flag is set to TRUE on shutdown by Guardian thread, when all guarded
94 mysqlds are stopped.
96 The flag is used in the Manager thread to wait for Guardian to stop all
97 mysqlds.
99 bool stopped;
101 Thread_info thread_info;
102 Thread_registry *thread_registry;
103 Instance_map *instance_map;
105 private:
106 Guardian(const Guardian &);
107 Guardian&operator =(const Guardian &);
110 #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_GUARDIAN_H */