summaryrefslogtreecommitdiff
path: root/src/charon/processing/jobs/callback_job.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/charon/processing/jobs/callback_job.c')
-rw-r--r--src/charon/processing/jobs/callback_job.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/charon/processing/jobs/callback_job.c b/src/charon/processing/jobs/callback_job.c
index e8892ee82..f0cebd473 100644
--- a/src/charon/processing/jobs/callback_job.c
+++ b/src/charon/processing/jobs/callback_job.c
@@ -12,12 +12,15 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: callback_job.c 3742 2008-04-03 09:19:12Z tobias $
+ * $Id: callback_job.c 4579 2008-11-05 11:29:56Z martin $
*/
#include "callback_job.h"
+#include <pthread.h>
+
#include <daemon.h>
+#include <utils/mutex.h>
typedef struct private_callback_job_t private_callback_job_t;
@@ -49,12 +52,12 @@ struct private_callback_job_t {
* thread ID of the job, if running
*/
pthread_t thread;
-
+
/**
* mutex to access jobs interna
*/
- pthread_mutex_t mutex;
-
+ mutex_t *mutex;
+
/**
* list of asociated child jobs
*/
@@ -76,6 +79,7 @@ static void destroy(private_callback_job_t *this)
this->cleanup(this->data);
}
this->children->destroy(this->children);
+ this->mutex->destroy(this->mutex);
free(this);
}
@@ -89,7 +93,7 @@ static void unregister(private_callback_job_t *this)
iterator_t *iterator;
private_callback_job_t *child;
- pthread_mutex_lock(&this->parent->mutex);
+ this->parent->mutex->lock(this->parent->mutex);
iterator = this->parent->children->create_iterator(this->parent->children, TRUE);
while (iterator->iterate(iterator, (void**)&child))
{
@@ -100,7 +104,7 @@ static void unregister(private_callback_job_t *this)
}
}
iterator->destroy(iterator);
- pthread_mutex_unlock(&this->parent->mutex);
+ this->parent->mutex->unlock(this->parent->mutex);
}
}
@@ -111,12 +115,12 @@ static void cancel(private_callback_job_t *this)
{
pthread_t thread;
- pthread_mutex_lock(&this->mutex);
+ this->mutex->lock(this->mutex);
thread = this->thread;
/* terminate its children */
this->children->invoke_offset(this->children, offsetof(callback_job_t, cancel));
- pthread_mutex_unlock(&this->mutex);
+ this->mutex->unlock(this->mutex);
/* terminate thread */
if (thread)
@@ -133,9 +137,9 @@ static void execute(private_callback_job_t *this)
{
bool cleanup = FALSE;
- pthread_mutex_lock(&this->mutex);
+ this->mutex->lock(this->mutex);
this->thread = pthread_self();
- pthread_mutex_unlock(&this->mutex);
+ this->mutex->unlock(this->mutex);
pthread_cleanup_push((void*)destroy, this);
while (TRUE)
@@ -180,7 +184,7 @@ callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
this->public.cancel = (void(*)(callback_job_t*))cancel;
/* private variables */
- pthread_mutex_init(&this->mutex, NULL);
+ this->mutex = mutex_create(MUTEX_DEFAULT);
this->callback = cb;
this->data = data;
this->cleanup = cleanup;
@@ -191,9 +195,9 @@ callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
/* register us at parent */
if (parent)
{
- pthread_mutex_lock(&this->parent->mutex);
+ this->parent->mutex->lock(this->parent->mutex);
this->parent->children->insert_last(this->parent->children, this);
- pthread_mutex_unlock(&this->parent->mutex);
+ this->parent->mutex->unlock(this->parent->mutex);
}
return &this->public;