1
by brian
clean slate |
1 |
/* Copyright (C) 2000, 2002, 2005 MySQL AB
|
2 |
||
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.
|
|
6 |
||
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.
|
|
11 |
||
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 */
|
|
15 |
||
16 |
/*
|
|
17 |
* sql_manager.cc
|
|
18 |
* This thread manages various maintenance tasks.
|
|
19 |
*
|
|
20 |
* o Flushing the tables every flush_time seconds.
|
|
21 |
* o Berkeley DB: removing unneeded log files.
|
|
22 |
*/
|
|
23 |
||
24 |
#include "mysql_priv.h" |
|
25 |
||
26 |
ulong volatile manager_status; |
|
27 |
bool volatile manager_thread_in_use; |
|
28 |
||
29 |
pthread_t manager_thread; |
|
30 |
pthread_mutex_t LOCK_manager; |
|
31 |
pthread_cond_t COND_manager; |
|
32 |
||
33 |
struct handler_cb { |
|
34 |
struct handler_cb *next; |
|
35 |
void (*action)(void); |
|
36 |
};
|
|
37 |
||
38 |
static struct handler_cb * volatile cb_list; |
|
39 |
||
40 |
bool mysql_manager_submit(void (*action)()) |
|
41 |
{
|
|
55
by brian
Update for using real bool types. |
42 |
bool result= false; |
1
by brian
clean slate |
43 |
struct handler_cb * volatile *cb; |
44 |
pthread_mutex_lock(&LOCK_manager); |
|
45 |
cb= &cb_list; |
|
46 |
while (*cb && (*cb)->action != action) |
|
47 |
cb= &(*cb)->next; |
|
48 |
if (!*cb) |
|
49 |
{
|
|
50 |
*cb= (struct handler_cb *)my_malloc(sizeof(struct handler_cb), MYF(MY_WME)); |
|
51 |
if (!*cb) |
|
55
by brian
Update for using real bool types. |
52 |
result= true; |
1
by brian
clean slate |
53 |
else
|
54 |
{
|
|
55 |
(*cb)->next= NULL; |
|
56 |
(*cb)->action= action; |
|
57 |
}
|
|
58 |
}
|
|
59 |
pthread_mutex_unlock(&LOCK_manager); |
|
60 |
return result; |
|
61 |
}
|
|
62 |
||
63 |
pthread_handler_t handle_manager(void *arg __attribute__((unused))) |
|
64 |
{
|
|
65 |
int error = 0; |
|
66 |
ulong status; |
|
67 |
struct timespec abstime; |
|
55
by brian
Update for using real bool types. |
68 |
bool reset_flush_time = true; |
1
by brian
clean slate |
69 |
struct handler_cb *cb= NULL; |
70 |
my_thread_init(); |
|
71 |
||
72 |
pthread_detach_this_thread(); |
|
73 |
manager_thread = pthread_self(); |
|
74 |
manager_status = 0; |
|
75 |
manager_thread_in_use = 1; |
|
76 |
||
77 |
for (;;) |
|
78 |
{
|
|
79 |
pthread_mutex_lock(&LOCK_manager); |
|
80 |
/* XXX: This will need to be made more general to handle different
|
|
81 |
* polling needs. */
|
|
82 |
if (flush_time) |
|
83 |
{
|
|
84 |
if (reset_flush_time) |
|
85 |
{
|
|
86 |
set_timespec(abstime, flush_time); |
|
55
by brian
Update for using real bool types. |
87 |
reset_flush_time= false; |
1
by brian
clean slate |
88 |
}
|
89 |
while (!manager_status && (!error || error == EINTR) && !abort_loop) |
|
90 |
error= pthread_cond_timedwait(&COND_manager, &LOCK_manager, &abstime); |
|
91 |
}
|
|
92 |
else
|
|
93 |
{
|
|
94 |
while (!manager_status && (!error || error == EINTR) && !abort_loop) |
|
95 |
error= pthread_cond_wait(&COND_manager, &LOCK_manager); |
|
96 |
}
|
|
97 |
status = manager_status; |
|
98 |
manager_status = 0; |
|
99 |
if (cb == NULL) |
|
100 |
{
|
|
101 |
cb= cb_list; |
|
102 |
cb_list= NULL; |
|
103 |
}
|
|
104 |
pthread_mutex_unlock(&LOCK_manager); |
|
105 |
||
106 |
if (abort_loop) |
|
107 |
break; |
|
108 |
||
109 |
if (error == ETIMEDOUT || error == ETIME) |
|
110 |
{
|
|
111 |
flush_tables(); |
|
112 |
error = 0; |
|
55
by brian
Update for using real bool types. |
113 |
reset_flush_time = true; |
1
by brian
clean slate |
114 |
}
|
115 |
||
116 |
while (cb) |
|
117 |
{
|
|
118 |
struct handler_cb *next= cb->next; |
|
119 |
cb->action(); |
|
120 |
my_free((uchar*)cb, MYF(0)); |
|
121 |
cb= next; |
|
122 |
}
|
|
123 |
}
|
|
124 |
manager_thread_in_use = 0; |
|
125 |
my_thread_end(); |
|
51.1.59
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
126 |
return(NULL); |
1
by brian
clean slate |
127 |
}
|