diff options
Diffstat (limited to 'Source/charon/queues')
-rw-r--r-- | Source/charon/queues/event_queue.c | 92 | ||||
-rw-r--r-- | Source/charon/queues/event_queue.h | 23 | ||||
-rw-r--r-- | Source/charon/queues/job_queue.c | 43 | ||||
-rw-r--r-- | Source/charon/queues/job_queue.h | 22 | ||||
-rw-r--r-- | Source/charon/queues/jobs/delete_ike_sa_job.c | 6 | ||||
-rw-r--r-- | Source/charon/queues/send_queue.c | 45 | ||||
-rw-r--r-- | Source/charon/queues/send_queue.h | 32 |
7 files changed, 91 insertions, 172 deletions
diff --git a/Source/charon/queues/event_queue.c b/Source/charon/queues/event_queue.c index eb33330f0..6954bf2eb 100644 --- a/Source/charon/queues/event_queue.c +++ b/Source/charon/queues/event_queue.c @@ -1,7 +1,7 @@ /** * @file event_queue.c * - * @brief Event-Queue based on class linked_list_t + * @brief Implementation of event_queue_t * */ @@ -54,19 +54,17 @@ struct event_t{ * @brief Destroys a event_t object. * * @param event_t calling object - * @returns always SUCCESS */ - status_t (*destroy) (event_t *event); + void (*destroy) (event_t *event); }; /** - * @brief implements function destroy of event_t + * implements event_t.destroy */ -static status_t event_destroy(event_t *event) +static void event_destroy(event_t *event) { allocator_free(event); - return SUCCESS; } /** @@ -75,17 +73,11 @@ static status_t event_destroy(event_t *event) * @param time absolute time to fire the event * @param job job to add to job-queue at specific time * - * @returns - * - created event_t object - * - NULL if memory allocation failed + * @returns created event_t object */ static event_t *event_create(timeval_t time, job_t *job) { event_t *this = allocator_alloc_thing(event_t); - if (this == NULL) - { - return this; - } this->destroy = event_destroy; this->time = time; @@ -149,8 +141,7 @@ static long time_difference(struct timeval *end_time, struct timeval *start_time /** - * Implements function get_count of event_queue_t. - * See #event_queue_s.get_count for description. + * Implements event_queue_t.get_count */ static int get_count (private_event_queue_t *this) { @@ -162,14 +153,14 @@ static int get_count (private_event_queue_t *this) } /** - * Implements function get of event_queue_t. - * See #event_queue_s.get for description. + * Implements event_queue_t.get */ -static status_t get(private_event_queue_t *this, job_t **job) +static job_t *get(private_event_queue_t *this) { timespec_t timeout; timeval_t current_time; event_t * next_event; + job_t *job; int oldstate; pthread_mutex_lock(&(this->mutex)); @@ -205,7 +196,7 @@ static status_t get(private_event_queue_t *this, job_t **job) /* event available */ this->list->remove_first(this->list,(void **) &next_event); - *job = next_event->job; + job = next_event->job; next_event->destroy(next_event); break; @@ -216,23 +207,19 @@ static status_t get(private_event_queue_t *this, job_t **job) pthread_mutex_unlock(&(this->mutex)); - return SUCCESS; + return job; } /** * Implements function add_absolute of event_queue_t. * See #event_queue_s.add_absolute for description. */ -static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t time) +static void add_absolute(private_event_queue_t *this, job_t *job, timeval_t time) { event_t *event = event_create(time,job); event_t *current_event; status_t status; - if (event == NULL) - { - return FAILED; - } pthread_mutex_lock(&(this->mutex)); /* while just used to break out */ @@ -240,7 +227,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t { if (this->list->get_count(this->list) == 0) { - status = this->list->insert_first(this->list,event); + this->list->insert_first(this->list,event); break; } @@ -250,7 +237,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t if (time_difference(&(event->time), &(current_event->time)) >= 0) { /* my event has to be fired after the last event in list */ - status = this->list->insert_last(this->list,event); + this->list->insert_last(this->list,event); break; } @@ -260,18 +247,13 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t if (time_difference(&(event->time), &(current_event->time)) < 0) { /* my event has to be fired before the first event in list */ - status = this->list->insert_first(this->list,event); + this->list->insert_first(this->list,event); break; } iterator_t * iterator; - status = this->list->create_iterator(this->list,&iterator,TRUE); - if (status != SUCCESS) - { - break; - } - + this->list->create_iterator(this->list,&iterator,TRUE); iterator->has_next(iterator); /* first element has not to be checked (already done) */ @@ -283,7 +265,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t if (time_difference(&(event->time), &(current_event->time)) <= 0) { /* my event has to be fired before the current event in list */ - status = iterator->insert_before(iterator,event); + iterator->insert_before(iterator,event); break; } } @@ -293,19 +275,12 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t pthread_cond_signal( &(this->condvar)); pthread_mutex_unlock(&(this->mutex)); - - if (status != SUCCESS) - { - event->destroy(event); - } - return status; } /** - * Implements function add_relative of event_queue_t. - * See #event_queue_s.add_relative for description. + * Implements event_queue_t.add_relative. */ -static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms) +static void add_relative(event_queue_t *this, job_t *job, u_int32_t ms) { timeval_t current_time; timeval_t time; @@ -316,15 +291,14 @@ static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms) time.tv_usec = ((current_time.tv_usec + micros) % 1000000); time.tv_sec = current_time.tv_sec + ((current_time.tv_usec + micros)/ 1000000); - return this->add_absolute(this, job, time); + this->add_absolute(this, job, time); } /** - * Implements function destroy of event_queue_t. - * See #event_queue_s.destroy for description. + * Implements event_queue_t.destroy. */ -static status_t event_queue_destroy(private_event_queue_t *this) +static void event_queue_destroy(private_event_queue_t *this) { while (this->list->get_count(this->list) > 0) { @@ -345,7 +319,6 @@ static status_t event_queue_destroy(private_event_queue_t *this) pthread_cond_destroy(&(this->condvar)); allocator_free(this); - return SUCCESS; } /* @@ -353,26 +326,15 @@ static status_t event_queue_destroy(private_event_queue_t *this) */ event_queue_t *event_queue_create() { - linked_list_t *linked_list = linked_list_create(); - if (linked_list == NULL) - { - return NULL; - } - private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t); - if (this == NULL) - { - linked_list->destroy(linked_list); - return NULL; - } this->public.get_count = (int (*) (event_queue_t *event_queue)) get_count; - this->public.get = (status_t (*) (event_queue_t *event_queue, job_t **job)) get; - this->public.add_absolute = (status_t (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add_absolute; - this->public.add_relative = (status_t (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative; - this->public.destroy = (status_t (*) (event_queue_t *event_queue)) event_queue_destroy; + this->public.get = (job_t *(*) (event_queue_t *event_queue)) get; + this->public.add_absolute = (void (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add_absolute; + this->public.add_relative = (void (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative; + this->public.destroy = (void (*) (event_queue_t *event_queue)) event_queue_destroy; - this->list = linked_list; + this->list = linked_list_create();; pthread_mutex_init(&(this->mutex), NULL); pthread_cond_init(&(this->condvar), NULL); diff --git a/Source/charon/queues/event_queue.h b/Source/charon/queues/event_queue.h index 4f3d543d6..ed0a85869 100644 --- a/Source/charon/queues/event_queue.h +++ b/Source/charon/queues/event_queue.h @@ -1,7 +1,7 @@ /** * @file event_queue.h * - * @brief Event-Queue based on class linked_list_t + * @brief Interface of job_queue_t. * */ @@ -53,10 +53,9 @@ struct event_queue_t { * * @param event_queue calling object * @param[out] job pointer to a job pointer where to job is returned to - * @return - SUCCESS if succeeded - * - FAILED otherwisesa + * @return next job */ - status_t (*get) (event_queue_t *event_queue, job_t **job); + job_t *(*get) (event_queue_t *event_queue); /** * @brief Adds a event to the queue, using a relative time. @@ -68,11 +67,8 @@ struct event_queue_t { * @param event_queue calling object * @param[in] job job to add to the queue (job is not copied) * @param[in] time relative time, when the event has to get fired - * @returns - * - SUCCESS if succeeded - * - FAILED otherwise */ - status_t (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms); + void (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms); /** * @brief Adds a event to the queue, using an absolute time. @@ -84,11 +80,8 @@ struct event_queue_t { * @param event_queue calling object * @param[in] job job to add to the queue (job is not copied) * @param[in] absolute time time, when the event has to get fired - * @returns - * - SUCCESS if succeeded - * - FAILED otherwise */ - status_t (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time); + void (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time); /** * @brief Destroys a event_queue object. @@ -100,15 +93,13 @@ struct event_queue_t { * @param event_queue calling object * @returns always SUCCESS */ - status_t (*destroy) (event_queue_t *event_queue); + void (*destroy) (event_queue_t *event_queue); }; /** * @brief Creates an empty event_queue * - * @returns - * - Empty event_queue_t object - * - NULL if memory allocation failed + * @returns event_queue */ event_queue_t *event_queue_create(); #endif /*EVENT_QUEUE_H_*/ diff --git a/Source/charon/queues/job_queue.c b/Source/charon/queues/job_queue.c index bd11d0b26..d6e8f6b3f 100644 --- a/Source/charon/queues/job_queue.c +++ b/Source/charon/queues/job_queue.c @@ -1,7 +1,7 @@ /** * @file job_queue.c * - * @brief Job-Queue based on linked_list_t + * @brief Implementation of job_queue_t * */ @@ -56,7 +56,7 @@ struct private_job_queue_t { /** - * @brief implements function get_count of job_queue_t + * implements job_queue_t.get_count */ static int get_count(private_job_queue_t *this) { @@ -68,11 +68,12 @@ static int get_count(private_job_queue_t *this) } /** - * @brief implements function get of job_queue_t + * implements job_queue_t.get */ -static status_t get(private_job_queue_t *this, job_t **job) +static job_t *get(private_job_queue_t *this) { int oldstate; + job_t *job; pthread_mutex_lock(&(this->mutex)); /* go to wait while no jobs available */ while(this->list->get_count(this->list) == 0) @@ -87,28 +88,26 @@ static status_t get(private_job_queue_t *this, job_t **job) pthread_setcancelstate(oldstate, NULL); pthread_cleanup_pop(0); } - this->list->remove_first(this->list,(void **) job); + this->list->remove_first(this->list,(void **) &job); pthread_mutex_unlock(&(this->mutex)); - return SUCCESS; + return job; } /** - * @brief implements function add of job_queue_t + * implements function job_queue_t.add */ -static status_t add(private_job_queue_t *this, job_t *job) +static void add(private_job_queue_t *this, job_t *job) { pthread_mutex_lock(&(this->mutex)); this->list->insert_last(this->list,job); pthread_cond_signal( &(this->condvar)); pthread_mutex_unlock(&(this->mutex)); - return SUCCESS; } /** - * @brief implements function destroy of job_queue_t - * + * implements job_queue_t.destroy */ -static status_t job_queue_destroy (private_job_queue_t *this) +static void job_queue_destroy (private_job_queue_t *this) { while (this->list->get_count(this->list) > 0) { @@ -127,7 +126,6 @@ static status_t job_queue_destroy (private_job_queue_t *this) pthread_cond_destroy(&(this->condvar)); allocator_free(this); - return SUCCESS; } /* @@ -136,25 +134,14 @@ static status_t job_queue_destroy (private_job_queue_t *this) */ job_queue_t *job_queue_create() { - linked_list_t *linked_list = linked_list_create(); - if (linked_list == NULL) - { - return NULL; - } - private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t); - if (this == NULL) - { - linked_list->destroy(linked_list); - return NULL; - } this->public.get_count = (int(*)(job_queue_t*))get_count; - this->public.get = (status_t(*)(job_queue_t*, job_t**))get; - this->public.add = (status_t(*)(job_queue_t*, job_t*))add; - this->public.destroy = (status_t(*)(job_queue_t*))job_queue_destroy; + this->public.get = (job_t*(*)(job_queue_t*))get; + this->public.add = (void(*)(job_queue_t*, job_t*))add; + this->public.destroy = (void(*)(job_queue_t*))job_queue_destroy; - this->list = linked_list; + this->list = linked_list_create(); pthread_mutex_init(&(this->mutex), NULL); pthread_cond_init(&(this->condvar), NULL); diff --git a/Source/charon/queues/job_queue.h b/Source/charon/queues/job_queue.h index 4c7c12241..b0a3066db 100644 --- a/Source/charon/queues/job_queue.h +++ b/Source/charon/queues/job_queue.h @@ -1,7 +1,7 @@ /** * @file job_queue.h * - * @brief Job-Queue based on linked_list_t + * @brief Interface of job_queue_t- * */ @@ -39,8 +39,8 @@ struct job_queue_t { /** * @brief returns number of jobs in queue * - * @param job_queue_t calling object - * @returns number of items in queue + * @param job_queue_t calling object + * @returns number of items in queue */ int (*get_count) (job_queue_t *job_queue); @@ -48,14 +48,13 @@ struct job_queue_t { * @brief get the next job from the queue * * If the queue is empty, this function blocks until a job can be returned. - * * After using, the returned job has to get destroyed by the caller. * - * @param job_queue_t calling object - * @param[out] job pointer to a job pointer where to job is returned to - * @returns SUCCESS if succeeded, FAILED otherwise + * @param job_queue_t calling object + * @param[out] job pointer to a job pointer where to job is returned to + * @return job */ - status_t (*get) (job_queue_t *job_queue, job_t **job); + job_t *(*get) (job_queue_t *job_queue); /** * @brief adds a job to the queue @@ -66,9 +65,8 @@ struct job_queue_t { * * @param job_queue_t calling object * @param[in] job job to add to the queue (job is not copied) - * @returns SUCCESS if succeeded, FAILED otherwise */ - status_t (*add) (job_queue_t *job_queue, job_t *job); + void (*add) (job_queue_t *job_queue, job_t *job); /** * @brief destroys a job_queue object @@ -78,9 +76,8 @@ struct job_queue_t { * after calling this function. * * @param job_queue_t calling object - * @returns SUCCESS if succeeded, FAILED otherwise */ - status_t (*destroy) (job_queue_t *job_queue); + void (*destroy) (job_queue_t *job_queue); }; /** @@ -89,4 +86,5 @@ struct job_queue_t { * @return job_queue_t empty job_queue */ job_queue_t *job_queue_create(); + #endif /*JOB_QUEUE_H_*/ diff --git a/Source/charon/queues/jobs/delete_ike_sa_job.c b/Source/charon/queues/jobs/delete_ike_sa_job.c index b87c4dc7d..5041d1f16 100644 --- a/Source/charon/queues/jobs/delete_ike_sa_job.c +++ b/Source/charon/queues/jobs/delete_ike_sa_job.c @@ -96,11 +96,7 @@ delete_ike_sa_job_t *delete_ike_sa_job_create(ike_sa_id_t *ike_sa_id) this->public.destroy = (status_t (*)(delete_ike_sa_job_t *)) destroy; /* private variables */ - if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS) - { - allocator_free(this); - return NULL; - } + this->ike_sa_id = ike_sa_id->clone(ike_sa_id); return &(this->public); } diff --git a/Source/charon/queues/send_queue.c b/Source/charon/queues/send_queue.c index 5782ce151..af7240208 100644 --- a/Source/charon/queues/send_queue.c +++ b/Source/charon/queues/send_queue.c @@ -1,7 +1,7 @@ /** * @file send_queue.c * - * @brief Send-Queue based on linked_list_t + * @brief Implementation of send_queue_t. * */ @@ -59,7 +59,7 @@ struct private_send_queue_t { /** - * @brief implements function get_count of send_queue_t + * implements send_queue_t.get_count */ static int get_count(private_send_queue_t *this) { @@ -71,11 +71,12 @@ static int get_count(private_send_queue_t *this) } /** - * @brief implements function get of send_queue_t + * implements send_queue_t.get */ -static status_t get(private_send_queue_t *this, packet_t **packet) +static packet_t *get(private_send_queue_t *this) { int oldstate; + packet_t *packet; pthread_mutex_lock(&(this->mutex)); /* go to wait while no packets available */ @@ -90,28 +91,26 @@ static status_t get(private_send_queue_t *this, packet_t **packet) pthread_setcancelstate(oldstate, NULL); pthread_cleanup_pop(0); } - this->list->remove_first(this->list,(void **) packet); + this->list->remove_first(this->list,(void **)&packet); pthread_mutex_unlock(&(this->mutex)); - return SUCCESS; + return packet; } /** - * @brief implements function add of send_queue_t + * implements send_queue_t.add */ -static status_t add(private_send_queue_t *this, packet_t *packet) +static void add(private_send_queue_t *this, packet_t *packet) { pthread_mutex_lock(&(this->mutex)); this->list->insert_last(this->list,packet); pthread_cond_signal( &(this->condvar)); pthread_mutex_unlock(&(this->mutex)); - return SUCCESS; } /** - * @brief implements function destroy of send_queue_t - * + * implements send_queue_t.destroy */ -static status_t destroy (private_send_queue_t *this) +static void destroy (private_send_queue_t *this) { /* destroy all packets in list before destroying list */ @@ -132,7 +131,6 @@ static status_t destroy (private_send_queue_t *this) pthread_cond_destroy(&(this->condvar)); allocator_free(this); - return SUCCESS; } /* @@ -141,25 +139,14 @@ static status_t destroy (private_send_queue_t *this) */ send_queue_t *send_queue_create() { - linked_list_t *linked_list = linked_list_create(); - if (linked_list == NULL) - { - return NULL; - } - private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t); - if (this == NULL) - { - linked_list->destroy(linked_list); - return NULL; - } - + this->public.get_count = (int(*)(send_queue_t*)) get_count; - this->public.get = (status_t(*)(send_queue_t*, packet_t**)) get; - this->public.add = (status_t(*)(send_queue_t*, packet_t*)) add; - this->public.destroy = (status_t(*)(send_queue_t*)) destroy; + this->public.get = (packet_t*(*)(send_queue_t*)) get; + this->public.add = (void(*)(send_queue_t*, packet_t*)) add; + this->public.destroy = (void(*)(send_queue_t*)) destroy; - this->list = linked_list; + this->list = linked_list_create(); pthread_mutex_init(&(this->mutex), NULL); pthread_cond_init(&(this->condvar), NULL); diff --git a/Source/charon/queues/send_queue.h b/Source/charon/queues/send_queue.h index 572c40e62..f023f29af 100644 --- a/Source/charon/queues/send_queue.h +++ b/Source/charon/queues/send_queue.h @@ -1,7 +1,7 @@ /** * @file send_queue.h * - * @brief Send-Queue based on linked_list_t + * @brief Interface of send_queue_t. * */ @@ -40,40 +40,38 @@ struct send_queue_t { /** * @brief returns number of packets in queue * - * @param send_queue_t calling object - * @param[out] count integer pointer to store the count in - * @returns number of items in queue + * @param send_queue_t calling object + * @param[out] count integer pointer to store the count in + * @returns number of items in queue */ int (*get_count) (send_queue_t *send_queue); /** - * @brief get the next packet from the queue + * @brief get the next packet from the queue. * * If the queue is empty, this function blocks until a packet can be returned. * * After using, the returned packet has to get destroyed by the caller. * - * @param send_queue_t calling object - * @param[out] packet pointer to a packet_t pointer where to packet is returned to - * @returns SUCCESS if succeeded, FAILED otherwise + * @param send_queue_t calling object + * @param[out] packet pointer to a packet_t pointer where to packet is returned to */ - status_t (*get) (send_queue_t *send_queue, packet_t **packet); + packet_t *(*get) (send_queue_t *send_queue); /** - * @brief adds a packet to the queue + * @brief adds a packet to the queue. * * This function is non blocking and adds a packet_t to the list. * The specific packet object has to get destroyed by the thread which * removes the packet. * - * @param send_queue_t calling object - * @param[in] packet packet_t to add to the queue (packet is not copied) - * @returns SUCCESS if succeeded, FAILED otherwise + * @param send_queue_t calling object + * @param packet packet_t to add to the queue (packet is not copied) */ - status_t (*add) (send_queue_t *send_queue, packet_t *packet); + void (*add) (send_queue_t *send_queue, packet_t *packet); /** - * @brief destroys a send_queue object + * @brief destroys a send_queue object. * * @warning The caller of this function has to make sure * that no thread is going to add or get a packet from the send_queue @@ -82,11 +80,11 @@ struct send_queue_t { * @param send_queue_t calling object * @returns SUCCESS if succeeded, FAILED otherwise */ - status_t (*destroy) (send_queue_t *send_queue); + void (*destroy) (send_queue_t *send_queue); }; /** - * @brief Creates an empty send_queue_t + * @brief Creates an empty send_queue_t. * * @return send_queue_t empty send_queue_t */ |