1
/* Copyright (C) 2000, 2002, 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
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.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
* This thread manages various maintenance tasks.
20
* o Flushing the tables every flush_time seconds.
21
* o Berkeley DB: removing unneeded log files.
24
#include "mysql_priv.h"
26
ulong volatile manager_status;
27
bool volatile manager_thread_in_use;
29
pthread_t manager_thread;
30
pthread_mutex_t LOCK_manager;
31
pthread_cond_t COND_manager;
34
struct handler_cb *next;
38
static struct handler_cb * volatile cb_list;
40
bool mysql_manager_submit(void (*action)())
43
struct handler_cb * volatile *cb;
44
pthread_mutex_lock(&LOCK_manager);
46
while (*cb && (*cb)->action != action)
50
*cb= (struct handler_cb *)my_malloc(sizeof(struct handler_cb), MYF(MY_WME));
56
(*cb)->action= action;
59
pthread_mutex_unlock(&LOCK_manager);
63
pthread_handler_t handle_manager(void *arg __attribute__((unused)))
67
struct timespec abstime;
68
bool reset_flush_time = true;
69
struct handler_cb *cb= NULL;
72
pthread_detach_this_thread();
73
manager_thread = pthread_self();
75
manager_thread_in_use = 1;
79
pthread_mutex_lock(&LOCK_manager);
80
/* XXX: This will need to be made more general to handle different
86
set_timespec(abstime, flush_time);
87
reset_flush_time= false;
89
while (!manager_status && (!error || error == EINTR) && !abort_loop)
90
error= pthread_cond_timedwait(&COND_manager, &LOCK_manager, &abstime);
94
while (!manager_status && (!error || error == EINTR) && !abort_loop)
95
error= pthread_cond_wait(&COND_manager, &LOCK_manager);
97
status = manager_status;
104
pthread_mutex_unlock(&LOCK_manager);
109
if (error == ETIMEDOUT || error == ETIME)
113
reset_flush_time = true;
118
struct handler_cb *next= cb->next;
120
my_free((uchar*)cb, MYF(0));
124
manager_thread_in_use = 0;