1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

Reorganize the wait for event to be scheduled loop

Only use "set_timespec" when there is a need to use it
This commit is contained in:
unknown
2006-12-18 12:00:35 +01:00
parent 68be191157
commit b52f52224a

View File

@@ -699,10 +699,7 @@ static const char *queue_wait_msg= "Waiting for next activation";
RETURN VALUE RETURN VALUE
FALSE No error. If *job_data==NULL then top not elligible for execution. 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 Could be that there is no top.
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.
TRUE Error TRUE Error
*/ */
@@ -712,7 +709,6 @@ Event_queue::get_top_for_execution_if_time(THD *thd, Event_job_data **job_data)
{ {
bool ret= FALSE; bool ret= FALSE;
struct timespec top_time; struct timespec top_time;
struct timespec *abstime;
Event_queue_element *top= NULL; Event_queue_element *top= NULL;
bool to_free= FALSE; bool to_free= FALSE;
bool to_drop= FALSE; bool to_drop= FALSE;
@@ -724,43 +720,40 @@ Event_queue::get_top_for_execution_if_time(THD *thd, Event_job_data **job_data)
{ {
int res; int res;
thd->end_time(); /* Break loop if thd has been killed */
time_t now= thd->query_start(); if (thd->killed)
abstime= NULL;
if (queue.elements)
{ {
top= ((Event_queue_element*) queue_element(&queue, 0)); DBUG_PRINT("info", ("thd->killed=%d", thd->killed));
set_timespec(top_time, sec_since_epoch_TIME(&top->execute_at)); goto end;
abstime= &top_time;
} }
if (!abstime || get_timespec_sec(*abstime) > now) if (!queue.elements)
{ {
const char *msg; /* There are no events in the queue */
if (abstime) set_zero_time(&next_activation_at, MYSQL_TIMESTAMP_DATETIME);
{
next_activation_at= top->execute_at;
msg= queue_wait_msg;
}
else
{
set_zero_time(&next_activation_at, MYSQL_TIMESTAMP_DATETIME);
msg= queue_wait_msg;
}
cond_wait(thd, abstime, msg, SCHED_FUNC, __LINE__); /* Wait on condition until signaled. Release LOCK_queue while waiting. */
if (thd->killed) cond_wait(thd, NULL, queue_empty_msg, SCHED_FUNC, __LINE__);
{
DBUG_PRINT("info", ("thd->killed=%d", thd->killed)); continue;
goto end; }
}
top= ((Event_queue_element*) queue_element(&queue, 0));
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 Not yet time for top event, wait on condition with
the beginning. Moreover, this way we will get also the new top, if time or until signaled. Release LOCK_queue while waiting.
the element at the top has been changed.
*/ */
set_timespec(top_time, seconds_to_next_event);
cond_wait(thd, &top_time, queue_wait_msg, SCHED_FUNC, __LINE__);
continue; continue;
} }
@@ -802,7 +795,7 @@ Event_queue::get_top_for_execution_if_time(THD *thd, Event_job_data **job_data)
else else
queue_replaced(&queue); queue_replaced(&queue);
dbug_dump_queue(now); dbug_dump_queue(thd->query_start());
break; break;
} }
end: end:
@@ -815,8 +808,7 @@ end:
if (to_free) if (to_free)
delete top; delete top;
DBUG_PRINT("info", ("returning %d et_new: 0x%lx get_timespec_sec(abstime): %ld ", DBUG_PRINT("info", ("returning %d et_new: 0x%lx ", ret, (long) *job_data));
ret, (long) *job_data, abstime ? get_timespec_sec(*abstime) : 0));
if (*job_data) if (*job_data)
DBUG_PRINT("info", ("db: %s name: %s definer=%s", (*job_data)->dbname.str, DBUG_PRINT("info", ("db: %s name: %s definer=%s", (*job_data)->dbname.str,