Make task managers flush_queue() method public

This commit is contained in:
Martin Willi
2012-05-21 14:02:35 +02:00
parent 9e19cb912d
commit a5c799602f
3 changed files with 62 additions and 20 deletions
+25 -11
View File
@@ -212,11 +212,10 @@ struct private_task_manager_t {
u_int32_t dpd_recv; u_int32_t dpd_recv;
}; };
/** METHOD(task_manager_t, flush_queue, void,
* Flush a single task queue private_task_manager_t *this, task_queue_t queue)
*/
static void flush_queue(private_task_manager_t *this, linked_list_t *list)
{ {
linked_list_t *list;
task_t *task; task_t *task;
if (this->queued) if (this->queued)
@@ -224,6 +223,20 @@ static void flush_queue(private_task_manager_t *this, linked_list_t *list)
this->queued->destroy(this->queued); this->queued->destroy(this->queued);
this->queued = NULL; this->queued = NULL;
} }
switch (queue)
{
case TASK_QUEUE_ACTIVE:
list = this->active_tasks;
break;
case TASK_QUEUE_PASSIVE:
list = this->passive_tasks;
break;
case TASK_QUEUE_QUEUED:
list = this->queued_tasks;
break;
default:
return;
}
while (list->remove_last(list, (void**)&task) == SUCCESS) while (list->remove_last(list, (void**)&task) == SUCCESS)
{ {
task->destroy(task); task->destroy(task);
@@ -235,9 +248,9 @@ static void flush_queue(private_task_manager_t *this, linked_list_t *list)
*/ */
static void flush(private_task_manager_t *this) static void flush(private_task_manager_t *this)
{ {
flush_queue(this, this->queued_tasks); flush_queue(this, TASK_QUEUE_QUEUED);
flush_queue(this, this->passive_tasks); flush_queue(this, TASK_QUEUE_PASSIVE);
flush_queue(this, this->active_tasks); flush_queue(this, TASK_QUEUE_ACTIVE);
} }
/** /**
@@ -498,7 +511,7 @@ METHOD(task_manager_t, initiate, status_t,
/* processed, but task needs another exchange */ /* processed, but task needs another exchange */
continue; continue;
case ALREADY_DONE: case ALREADY_DONE:
flush_queue(this, this->active_tasks); flush_queue(this, TASK_QUEUE_ACTIVE);
flushed = TRUE; flushed = TRUE;
break; break;
case FAILED: case FAILED:
@@ -625,7 +638,7 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
} }
continue; continue;
case ALREADY_DONE: case ALREADY_DONE:
flush_queue(this, this->passive_tasks); flush_queue(this, TASK_QUEUE_PASSIVE);
flushed = TRUE; flushed = TRUE;
break; break;
case FAILED: case FAILED:
@@ -874,7 +887,7 @@ static status_t process_request(private_task_manager_t *this,
continue; continue;
case ALREADY_DONE: case ALREADY_DONE:
send_response = FALSE; send_response = FALSE;
flush_queue(this, this->passive_tasks); flush_queue(this, TASK_QUEUE_PASSIVE);
break; break;
case FAILED: case FAILED:
default: default:
@@ -947,7 +960,7 @@ static status_t process_response(private_task_manager_t *this,
/* processed, but task needs another exchange */ /* processed, but task needs another exchange */
continue; continue;
case ALREADY_DONE: case ALREADY_DONE:
flush_queue(this, this->active_tasks); flush_queue(this, TASK_QUEUE_ACTIVE);
break; break;
case FAILED: case FAILED:
default: default:
@@ -1542,6 +1555,7 @@ task_manager_v1_t *task_manager_v1_create(ike_sa_t *ike_sa)
.adopt_tasks = _adopt_tasks, .adopt_tasks = _adopt_tasks,
.busy = _busy, .busy = _busy,
.create_task_enumerator = _create_task_enumerator, .create_task_enumerator = _create_task_enumerator,
.flush_queue = _flush_queue,
.destroy = _destroy, .destroy = _destroy,
}, },
}, },
+30 -9
View File
@@ -157,20 +157,40 @@ struct private_task_manager_t {
double retransmit_base; double retransmit_base;
}; };
METHOD(task_manager_t, flush_queue, void,
private_task_manager_t *this, task_queue_t queue)
{
linked_list_t *list;
task_t *task;
switch (queue)
{
case TASK_QUEUE_ACTIVE:
list = this->active_tasks;
break;
case TASK_QUEUE_PASSIVE:
list = this->passive_tasks;
break;
case TASK_QUEUE_QUEUED:
list = this->queued_tasks;
break;
default:
return;
}
while (list->remove_last(list, (void**)&task) == SUCCESS)
{
task->destroy(task);
}
}
/** /**
* flush all tasks in the task manager * flush all tasks in the task manager
*/ */
static void flush(private_task_manager_t *this) static void flush(private_task_manager_t *this)
{ {
this->passive_tasks->destroy_offset(this->passive_tasks, flush_queue(this, TASK_QUEUE_QUEUED);
offsetof(task_t, destroy)); flush_queue(this, TASK_QUEUE_PASSIVE);
this->passive_tasks = linked_list_create(); flush_queue(this, TASK_QUEUE_ACTIVE);
this->active_tasks->destroy_offset(this->active_tasks,
offsetof(task_t, destroy));
this->active_tasks = linked_list_create();
this->queued_tasks->destroy_offset(this->queued_tasks,
offsetof(task_t, destroy));
this->queued_tasks = linked_list_create();
} }
/** /**
@@ -1465,6 +1485,7 @@ task_manager_v2_t *task_manager_v2_create(ike_sa_t *ike_sa)
.adopt_tasks = _adopt_tasks, .adopt_tasks = _adopt_tasks,
.busy = _busy, .busy = _busy,
.create_task_enumerator = _create_task_enumerator, .create_task_enumerator = _create_task_enumerator,
.flush_queue = _flush_queue,
.destroy = _destroy, .destroy = _destroy,
}, },
}, },
+7
View File
@@ -253,6 +253,13 @@ struct task_manager_t {
enumerator_t* (*create_task_enumerator)(task_manager_t *this, enumerator_t* (*create_task_enumerator)(task_manager_t *this,
task_queue_t queue); task_queue_t queue);
/**
* Flush a queue, cancelling all tasks.
*
* @param queue queue to flush
*/
void (*flush_queue)(task_manager_t *this, task_queue_t queue);
/** /**
* Destroy the task_manager_t. * Destroy the task_manager_t.
*/ */