13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#include <drizzled/server_includes.h>
17
17
#include <drizzled/gettext.h>
18
18
#include <drizzled/error.h>
19
19
#include <drizzled/unireg.h>
20
#include <drizzled/plugin/storage_engine.h>
21
#include <drizzled/cursor.h> /* for refresh_version */
22
#include "drizzled/pthread_globals.h"
23
#include "drizzled/internal/my_pthread.h"
24
#include "drizzled/internal/my_sys.h"
25
#include "drizzled/plugin/daemon.h"
31
21
static bool kill_in_progress= false;
32
22
static bool volatile signal_thread_in_use= false;
23
extern int cleanup_done;
33
24
extern "C" pthread_handler_t signal_hand(void *);
37
extern int cleanup_done;
38
extern bool volatile abort_loop;
39
extern bool volatile shutdown_in_progress;
40
extern char pidfile_name[FN_REFLEN];
41
27
/* Prototypes -> all of these should be factored out into a propper shutdown */
42
28
extern void close_connections(void);
43
extern std::bitset<12> test_flags;
46
using namespace drizzled;
29
bool reload_cache(Session *session, ulong options, TableList *tables);
186
drizzled::plugin::StorageEngine::flushLogs(NULL);
174
reload_cache(NULL, (REFRESH_LOG | REFRESH_TABLES | REFRESH_FAST ), NULL); // Flush logs
177
break; /* purecov: tested */
195
class SignalHandler :
196
public drizzled::plugin::Daemon
183
static int init(PluginRegistry&)
198
SignalHandler(const SignalHandler &);
199
SignalHandler& operator=(const SignalHandler &);
202
: drizzled::plugin::Daemon("Signal Handler")
186
pthread_attr_t thr_attr;
187
size_t my_thread_stack_size= 65536;
189
(void) pthread_attr_init(&thr_attr);
190
pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
191
(void) pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
205
pthread_attr_t thr_attr;
206
size_t my_thread_stack_size= 65536;
208
(void) pthread_attr_init(&thr_attr);
209
pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
210
(void) pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
212
struct sched_param tmp_sched_param;
214
memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
215
tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
216
(void)pthread_attr_setschedparam(&thr_attr, &tmp_sched_param);
193
struct sched_param tmp_sched_param;
195
memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
196
tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
197
(void)pthread_attr_setschedparam(&thr_attr, &tmp_sched_param);
218
199
#if defined(__ia64__) || defined(__ia64)
220
Peculiar things with ia64 platforms - it seems we only have half the
221
stack size in reality, so we have to double it here
223
pthread_attr_setstacksize(&thr_attr, my_thread_stack_size*2);
201
Peculiar things with ia64 platforms - it seems we only have half the
202
stack size in reality, so we have to double it here
204
pthread_attr_setstacksize(&thr_attr, my_thread_stack_size*2);
225
pthread_attr_setstacksize(&thr_attr, my_thread_stack_size);
206
pthread_attr_setstacksize(&thr_attr, my_thread_stack_size);
228
(void) pthread_mutex_lock(&LOCK_thread_count);
229
if ((error=pthread_create(&signal_thread, &thr_attr, signal_hand, 0)))
231
errmsg_printf(ERRMSG_LVL_ERROR,
232
_("Can't create interrupt-thread (error %d, errno: %d)"),
209
(void) pthread_mutex_lock(&LOCK_thread_count);
210
if ((error=pthread_create(&signal_thread, &thr_attr, signal_hand, 0)))
212
errmsg_printf(ERRMSG_LVL_ERROR, _("Can't create interrupt-thread (error %d, errno: %d)"),
236
(void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
237
pthread_mutex_unlock(&LOCK_thread_count);
239
(void) pthread_attr_destroy(&thr_attr);
243
This is mainly needed when running with purify, but it's still nice to
244
know that all child threads have died when drizzled exits.
216
(void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
217
pthread_mutex_unlock(&LOCK_thread_count);
219
(void) pthread_attr_destroy(&thr_attr);
225
This is mainly needed when running with purify, but it's still nice to
226
know that all child threads have died when drizzled exits.
228
static int deinit(PluginRegistry&)
232
Wait up to 10 seconds for signal thread to die. We use this mainly to
233
avoid getting warnings that my_thread_end has not been called
235
for (i= 0 ; i < 100 && signal_thread_in_use; i++)
250
Wait up to 10 seconds for signal thread to die. We use this mainly to
251
avoid getting warnings that internal::my_thread_end has not been called
253
for (i= 0 ; i < 100 && signal_thread_in_use; i++)
255
if (pthread_kill(signal_thread, SIGTERM) != ESRCH)
257
usleep(100); // Give it time to die
237
if (pthread_kill(signal_thread, SIGTERM) != ESRCH)
239
usleep(100); // Give it time to die
263
static int init(drizzled::plugin::Context& context)
265
SignalHandler *handler= new SignalHandler;
266
context.add(handler);
271
static drizzle_sys_var* system_variables[]= {
245
static struct st_mysql_sys_var* system_variables[]= {
275
DRIZZLE_DECLARE_PLUGIN
249
drizzle_declare_plugin(signal_handler)
278
251
"signal_handler",
281
254
"Default Signal Handler",
282
255
PLUGIN_LICENSE_GPL,
283
256
init, /* Plugin Init */
257
deinit, /* Plugin Deinit */
258
NULL, /* status variables */
284
259
system_variables, /* system variables */
285
260
NULL /* config options */
287
DRIZZLE_DECLARE_PLUGIN_END;
262
drizzle_declare_plugin_end;