summaryrefslogtreecommitdiff
path: root/sql/event_queue.cc
diff options
context:
space:
mode:
authorunknown <tsmith@siva.hindu.god>2007-01-18 08:30:35 -0700
committerunknown <tsmith@siva.hindu.god>2007-01-18 08:30:35 -0700
commit61430c77a43d2b9bf8f5a928ca7977e96df0d1da (patch)
tree43ed4a13aa6f4077a05dacedc68e38e0ace6b8be /sql/event_queue.cc
parent8ca95b84281bd50685e7437fca3b06085f9cea56 (diff)
parent1a0bd37c4d5741e7297f318da07d77767a537ca7 (diff)
downloadmariadb-git-61430c77a43d2b9bf8f5a928ca7977e96df0d1da.tar.gz
Merge siva.hindu.god:/home/tsmith/m/bk/mrg-jan17/51
into siva.hindu.god:/home/tsmith/m/bk/mrg-jan17/maint/51 BUILD/check-cpu: Auto merged configure.in: Auto merged include/my_global.h: Auto merged mysql-test/mysql-test-run.pl: Auto merged mysql-test/r/sp.result: Auto merged mysql-test/r/type_enum.result: Auto merged mysql-test/r/udf.result: Auto merged mysql-test/r/view.result: Auto merged mysql-test/t/mysqladmin.test: Auto merged mysql-test/t/sp.test: Auto merged mysql-test/t/type_enum.test: Auto merged mysql-test/t/view.test: Auto merged mysys/my_read.c: Auto merged scripts/make_binary_distribution.sh: Auto merged server-tools/instance-manager/Makefile.am: Auto merged sql/event_queue.cc: Auto merged sql/field.h: Auto merged sql/item_sum.h: Auto merged sql/log_event.cc: Auto merged sql/mysqld.cc: Auto merged sql/share/errmsg.txt: Auto merged sql/sql_class.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_show.cc: Auto merged sql/table.cc: Auto merged storage/federated/ha_federated.cc: Auto merged server-tools/instance-manager/instance.cc: Use remote (global 5.1 version) sql/unireg.cc: Use remote (5.1 global version) mysql-test/t/trigger.test: Manual merge server-tools/instance-manager/guardian.cc: Manual merge
Diffstat (limited to 'sql/event_queue.cc')
-rw-r--r--sql/event_queue.cc69
1 files changed, 29 insertions, 40 deletions
diff --git a/sql/event_queue.cc b/sql/event_queue.cc
index 9a740114193..45d354ea9b6 100644
--- a/sql/event_queue.cc
+++ b/sql/event_queue.cc
@@ -691,16 +691,11 @@ static const char *queue_wait_msg= "Waiting for next activation";
SYNOPSIS
Event_queue::get_top_for_execution_if_time()
thd [in] Thread
- now [in] Current timestamp
job_data [out] The object to execute
- abstime [out] Time to sleep
RETURN VALUE
FALSE No error. If *job_data==NULL then top not elligible for execution.
- Could be that there is no top. If abstime->tv_sec is set to value
- greater than zero then use abstime with pthread_cond_timedwait().
- If abstime->tv_sec is zero then sleep with pthread_cond_wait().
- abstime->tv_nsec is always zero.
+ Could be that there is no top.
TRUE Error
*/
@@ -710,56 +705,51 @@ Event_queue::get_top_for_execution_if_time(THD *thd, Event_job_data **job_data)
{
bool ret= FALSE;
struct timespec top_time;
- struct timespec *abstime;
Event_queue_element *top= NULL;
bool to_free= FALSE;
bool to_drop= FALSE;
*job_data= NULL;
DBUG_ENTER("Event_queue::get_top_for_execution_if_time");
- top_time.tv_nsec= 0;
LOCK_QUEUE_DATA();
for (;;)
{
int res;
- thd->end_time();
- time_t now= thd->query_start();
- abstime= NULL;
+ /* Break loop if thd has been killed */
+ if (thd->killed)
+ {
+ DBUG_PRINT("info", ("thd->killed=%d", thd->killed));
+ goto end;
+ }
- if (queue.elements)
+ if (!queue.elements)
{
- top= ((Event_queue_element*) queue_element(&queue, 0));
- top_time.tv_sec= sec_since_epoch_TIME(&top->execute_at);
+ /* There are no events in the queue */
+ set_zero_time(&next_activation_at, MYSQL_TIMESTAMP_DATETIME);
+
+ /* Wait on condition until signaled. Release LOCK_queue while waiting. */
+ cond_wait(thd, NULL, queue_empty_msg, SCHED_FUNC, __LINE__);
- abstime= &top_time;
+ continue;
}
- if (!abstime || abstime->tv_sec > now)
- {
- const char *msg;
- if (abstime)
- {
- next_activation_at= top->execute_at;
- msg= queue_wait_msg;
- }
- else
- {
- set_zero_time(&next_activation_at, MYSQL_TIMESTAMP_DATETIME);
- msg= queue_wait_msg;
- }
+ top= ((Event_queue_element*) queue_element(&queue, 0));
- cond_wait(thd, abstime, msg, SCHED_FUNC, __LINE__);
- if (thd->killed)
- {
- DBUG_PRINT("info", ("thd->killed=%d", thd->killed));
- goto end;
- }
+ thd->end_time(); /* Get current time */
+
+ time_t seconds_to_next_event=
+ sec_since_epoch_TIME(&top->execute_at) - thd->query_start();
+ next_activation_at= top->execute_at;
+ if (seconds_to_next_event > 0)
+ {
/*
- The queue could have been emptied. Therefore it's safe to start from
- the beginning. Moreover, this way we will get also the new top, if
- the element at the top has been changed.
+ Not yet time for top event, wait on condition with
+ time or until signaled. Release LOCK_queue while waiting.
*/
+ set_timespec(top_time, seconds_to_next_event);
+ cond_wait(thd, &top_time, queue_wait_msg, SCHED_FUNC, __LINE__);
+
continue;
}
@@ -801,7 +791,7 @@ Event_queue::get_top_for_execution_if_time(THD *thd, Event_job_data **job_data)
else
queue_replaced(&queue);
- dbug_dump_queue(now);
+ dbug_dump_queue(thd->query_start());
break;
}
end:
@@ -814,8 +804,7 @@ end:
if (to_free)
delete top;
- DBUG_PRINT("info", ("returning %d et_new: 0x%lx abstime.tv_sec: %ld ",
- ret, (long) *job_data, abstime ? abstime->tv_sec : 0));
+ DBUG_PRINT("info", ("returning %d et_new: 0x%lx ", ret, (long) *job_data));
if (*job_data)
DBUG_PRINT("info", ("db: %s name: %s definer=%s", (*job_data)->dbname.str,