Centralized thread cancellation in processor_t

This ensures that no threads are active when plugins and the rest of the
daemon are unloaded.

callback_job_t was simplified a lot in the process as its main
functionality is now contained in processor_t.  The parent-child
relationships were abandoned as these were only needed to simplify job
cancellation.
This commit is contained in:
Tobias Brunner
2012-06-25 17:38:59 +02:00
parent 7fec83af28
commit 26d77eb3e6
31 changed files with 263 additions and 477 deletions
@@ -137,11 +137,6 @@ struct private_kernel_klips_ipsec_t
*/
linked_list_t *ipsec_devices;
/**
* job receiving PF_KEY events
*/
callback_job_t *job;
/**
* mutex to lock access to the PF_KEY socket
*/
@@ -2552,10 +2547,6 @@ METHOD(kernel_ipsec_t, bypass_socket, bool,
METHOD(kernel_ipsec_t, destroy, void,
private_kernel_klips_ipsec_t *this)
{
if (this->job)
{
this->job->cancel(this->job);
}
if (this->socket > 0)
{
close(this->socket);
@@ -2639,9 +2630,9 @@ kernel_klips_ipsec_t *kernel_klips_ipsec_create()
return NULL;
}
this->job = callback_job_create_with_prio((callback_job_cb_t)receive_events,
this, NULL, NULL, JOB_PRIO_CRITICAL);
lib->processor->queue_job(lib->processor, (job_t*)this->job);
lib->processor->queue_job(lib->processor,
(job_t*)callback_job_create_with_prio((callback_job_cb_t)receive_events,
this, NULL, (callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
return &this->public;
}
@@ -268,11 +268,6 @@ struct private_kernel_netlink_ipsec_t {
*/
hashtable_t *sas;
/**
* Job receiving netlink events
*/
callback_job_t *job;
/**
* Netlink xfrm socket (IPsec)
*/
@@ -2618,10 +2613,6 @@ METHOD(kernel_ipsec_t, destroy, void,
enumerator_t *enumerator;
policy_entry_t *policy;
if (this->job)
{
this->job->cancel(this->job);
}
if (this->socket_xfrm_events > 0)
{
close(this->socket_xfrm_events);
@@ -2730,9 +2721,10 @@ kernel_netlink_ipsec_t *kernel_netlink_ipsec_create()
destroy(this);
return NULL;
}
this->job = callback_job_create_with_prio((callback_job_cb_t)receive_events,
this, NULL, NULL, JOB_PRIO_CRITICAL);
lib->processor->queue_job(lib->processor, (job_t*)this->job);
lib->processor->queue_job(lib->processor,
(job_t*)callback_job_create_with_prio(
(callback_job_cb_t)receive_events, this, NULL,
(callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
}
return &this->public;
@@ -253,11 +253,6 @@ struct private_kernel_netlink_net_t {
*/
linked_list_t *ifaces;
/**
* job receiving netlink events
*/
callback_job_t *job;
/**
* netlink rt socket (routing)
*/
@@ -1794,10 +1789,6 @@ METHOD(kernel_net_t, destroy, void,
manage_rule(this, RTM_DELRULE, AF_INET6, this->routing_table,
this->routing_table_prio);
}
if (this->job)
{
this->job->cancel(this->job);
}
if (this->socket_events > 0)
{
close(this->socket_events);
@@ -1923,9 +1914,10 @@ kernel_netlink_net_t *kernel_netlink_net_create()
return NULL;
}
this->job = callback_job_create_with_prio((callback_job_cb_t)receive_events,
this, NULL, NULL, JOB_PRIO_CRITICAL);
lib->processor->queue_job(lib->processor, (job_t*)this->job);
lib->processor->queue_job(lib->processor,
(job_t*)callback_job_create_with_prio(
(callback_job_cb_t)receive_events, this, NULL,
(callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
}
if (init_address_list(this) != SUCCESS)
@@ -172,11 +172,6 @@ struct private_kernel_pfkey_ipsec_t
*/
bool install_routes;
/**
* job receiving PF_KEY events
*/
callback_job_t *job;
/**
* mutex to lock access to the PF_KEY socket
*/
@@ -2496,10 +2491,6 @@ METHOD(kernel_ipsec_t, bypass_socket, bool,
METHOD(kernel_ipsec_t, destroy, void,
private_kernel_pfkey_ipsec_t *this)
{
if (this->job)
{
this->job->cancel(this->job);
}
if (this->socket > 0)
{
close(this->socket);
@@ -2592,9 +2583,10 @@ kernel_pfkey_ipsec_t *kernel_pfkey_ipsec_create()
return NULL;
}
this->job = callback_job_create_with_prio((callback_job_cb_t)receive_events,
this, NULL, NULL, JOB_PRIO_CRITICAL);
lib->processor->queue_job(lib->processor, (job_t*)this->job);
lib->processor->queue_job(lib->processor,
(job_t*)callback_job_create_with_prio(
(callback_job_cb_t)receive_events, this, NULL,
(callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
}
return &this->public;
@@ -119,11 +119,6 @@ struct private_kernel_pfroute_net_t
*/
linked_list_t *ifaces;
/**
* job receiving PF_ROUTE events
*/
callback_job_t *job;
/**
* mutex to lock access to the PF_ROUTE socket
*/
@@ -648,10 +643,6 @@ static status_t init_address_list(private_kernel_pfroute_net_t *this)
METHOD(kernel_net_t, destroy, void,
private_kernel_pfroute_net_t *this)
{
if (this->job)
{
this->job->cancel(this->job);
}
if (this->socket > 0)
{
close(this->socket);
@@ -718,9 +709,10 @@ kernel_pfroute_net_t *kernel_pfroute_net_create()
return NULL;
}
this->job = callback_job_create_with_prio((callback_job_cb_t)receive_events,
this, NULL, NULL, JOB_PRIO_CRITICAL);
lib->processor->queue_job(lib->processor, (job_t*)this->job);
lib->processor->queue_job(lib->processor,
(job_t*)callback_job_create_with_prio(
(callback_job_cb_t)receive_events, this, NULL,
(callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
}
if (init_address_list(this) != SUCCESS)