aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/threads/scheduler.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-25 13:42:58 +0000
committerMartin Willi <martin@strongswan.org>2005-11-25 13:42:58 +0000
commitca76df97365ec3421719bfbf9ecd3f33939ad108 (patch)
tree98f14e2944590fd642f3bfab0e03000ed64cde65 /Source/charon/threads/scheduler.c
parent2a336de4cd0d2f9cbb2547dbe7b4ff278446b89a (diff)
downloadstrongswan-ca76df97365ec3421719bfbf9ecd3f33939ad108.tar.bz2
strongswan-ca76df97365ec3421719bfbf9ecd3f33939ad108.tar.xz
- documentation and cleanup of threads package
Diffstat (limited to 'Source/charon/threads/scheduler.c')
-rw-r--r--Source/charon/threads/scheduler.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/Source/charon/threads/scheduler.c b/Source/charon/threads/scheduler.c
index 789e39aa6..8349d3611 100644
--- a/Source/charon/threads/scheduler.c
+++ b/Source/charon/threads/scheduler.c
@@ -1,7 +1,7 @@
/**
* @file scheduler.c
*
- * @brief implements the scheduler, looks for jobs in event-queue
+ * @brief Implementation of scheduler_t.
*
*/
@@ -41,6 +41,16 @@ struct private_scheduler_t {
* Public part of a scheduler object
*/
scheduler_t public;
+
+
+ /**
+ * @brief Get events from the event queue and add them to to job queue.
+ *
+ * Thread function started at creation of the scheduler object.
+ *
+ * @param this assigned scheduler object
+ */
+ void (*get_events) (private_scheduler_t *this);
/**
* Assigned thread to the scheduler_t object
@@ -55,12 +65,9 @@ struct private_scheduler_t {
};
/**
- * Thread function started at creation of the scheduler object
- *
- * @param this assigned scheduler object
- * @return SUCCESS if thread_function ended successfully, FAILED otherwise
+ * implements private_scheduler_t.get_events
*/
-static void scheduler_thread_function(private_scheduler_t * this)
+static void get_events(private_scheduler_t * this)
{
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
@@ -73,7 +80,8 @@ static void scheduler_thread_function(private_scheduler_t * this)
global_event_queue->get(global_event_queue, &current_job);
/* queue the job in the job queue, workers will eat them */
global_job_queue->add(global_job_queue, current_job);
- this->logger->log(this->logger, CONTROL, "got event, added job %s to job-queue.", mapping_find(job_type_m, current_job->get_type(current_job)));
+ this->logger->log(this->logger, CONTROL, "got event, added job %s to job-queue.",
+ mapping_find(job_type_m, current_job->get_type(current_job)));
}
}
@@ -100,6 +108,7 @@ scheduler_t * scheduler_create()
private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t);
this->public.destroy = (status_t(*)(scheduler_t*)) destroy;
+ this->get_events = get_events;
this->logger = global_logger_manager->create_logger(global_logger_manager, SCHEDULER, NULL);
if (this->logger == NULL)
@@ -108,9 +117,10 @@ scheduler_t * scheduler_create()
return NULL;
}
- if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))scheduler_thread_function, this) != 0)
+ if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->get_events, this) != 0)
{
/* thread could not be created */
+ this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!");
global_logger_manager->destroy_logger(global_logger_manager, this->logger);
allocator_free(this);
return NULL;