- renamed add method to add_absolute
- added add_relative method
This commit is contained in:
@@ -221,7 +221,7 @@ static status_t get(private_event_queue_t *this, job_t **job)
|
|||||||
/**
|
/**
|
||||||
* @brief implements function add of event_queue_t
|
* @brief implements function add of event_queue_t
|
||||||
*/
|
*/
|
||||||
static status_t add(private_event_queue_t *this, job_t *job, timeval_t time)
|
static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t time)
|
||||||
{
|
{
|
||||||
event_t *event = event_create(time,job);
|
event_t *event = event_create(time,job);
|
||||||
linked_list_element_t * current_list_element;
|
linked_list_element_t * current_list_element;
|
||||||
@@ -319,6 +319,23 @@ static status_t add(private_event_queue_t *this, job_t *job, timeval_t time)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief implements function add of event_queue_t
|
||||||
|
*/
|
||||||
|
static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
|
||||||
|
{
|
||||||
|
timeval_t current_time;
|
||||||
|
timeval_t time;
|
||||||
|
int micros = ms * 1000;
|
||||||
|
|
||||||
|
gettimeofday(¤t_time, NULL);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief implements function destroy of event_queue_t
|
* @brief implements function destroy of event_queue_t
|
||||||
@@ -371,7 +388,8 @@ event_queue_t *event_queue_create()
|
|||||||
|
|
||||||
this->public.get_count = (status_t (*) (event_queue_t *event_queue, int *count)) get_count;
|
this->public.get_count = (status_t (*) (event_queue_t *event_queue, int *count)) get_count;
|
||||||
this->public.get = (status_t (*) (event_queue_t *event_queue, job_t **job)) get;
|
this->public.get = (status_t (*) (event_queue_t *event_queue, job_t **job)) get;
|
||||||
this->public.add = (status_t (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add;
|
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.destroy = (status_t (*) (event_queue_t *event_queue)) event_queue_destroy;
|
||||||
|
|
||||||
this->list = linked_list;
|
this->list = linked_list;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ struct event_queue_s {
|
|||||||
status_t (*get) (event_queue_t *event_queue, job_t **job);
|
status_t (*get) (event_queue_t *event_queue, job_t **job);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief adds a event to the queue
|
* @brief adds a event to the queue, using a relative time
|
||||||
*
|
*
|
||||||
* This function is non blocking and adds a job_t at a specific time to the list.
|
* This function is non blocking and adds a job_t at a specific time to the list.
|
||||||
* The specific job-object has to get destroyed by the thread which
|
* The specific job-object has to get destroyed by the thread which
|
||||||
@@ -70,7 +70,21 @@ struct event_queue_s {
|
|||||||
* @param[in] time time, when the event has to get fired
|
* @param[in] time time, when the event has to get fired
|
||||||
* @returns SUCCESS if succeeded, FAILED otherwise
|
* @returns SUCCESS if succeeded, FAILED otherwise
|
||||||
*/
|
*/
|
||||||
status_t (*add) (event_queue_t *event_queue, job_t *job, timeval_t time);
|
status_t (*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
|
||||||
|
*
|
||||||
|
* This function is non blocking and adds a job_t at a specific time to the list.
|
||||||
|
* The specific job-object has to get destroyed by the thread which
|
||||||
|
* removes the job.
|
||||||
|
*
|
||||||
|
* @param event_queue calling object
|
||||||
|
* @param[in] job job to add to the queue (job is not copied)
|
||||||
|
* @param[in] 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief destroys a event_queue object
|
* @brief destroys a event_queue object
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ static void event_queue_insert_thread(event_queue_test_t * testinfos)
|
|||||||
time.tv_usec = 0;
|
time.tv_usec = 0;
|
||||||
time.tv_sec = current_time.tv_sec + i;
|
time.tv_sec = current_time.tv_sec + i;
|
||||||
|
|
||||||
tester->assert_true(tester,(testinfos->event_queue->add(testinfos->event_queue,job,time) == SUCCESS), "add call check");
|
tester->assert_true(tester,(testinfos->event_queue->add_absolute(testinfos->event_queue,job,time) == SUCCESS), "add call check");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user