Modify os_cond_reltimedwait to support long time wait (#461)
Modify the argument of os_cond_reltimedwait to uint64 type to support long time wait, and handle possible integer overflow.
This commit is contained in:
@ -171,7 +171,7 @@ void bh_free_msg(bh_queue_node *msg)
|
||||
bh_queue_free(msg);
|
||||
}
|
||||
|
||||
bh_message_t bh_get_msg(bh_queue *queue, int timeout)
|
||||
bh_message_t bh_get_msg(bh_queue *queue, uint64 timeout_us)
|
||||
{
|
||||
bh_queue_node *msg = NULL;
|
||||
bh_queue_mutex_lock(&queue->queue_lock);
|
||||
@ -180,13 +180,13 @@ bh_message_t bh_get_msg(bh_queue *queue, int timeout)
|
||||
bh_assert(queue->head == NULL);
|
||||
bh_assert(queue->tail == NULL);
|
||||
|
||||
if (timeout == 0) {
|
||||
if (timeout_us == 0) {
|
||||
bh_queue_mutex_unlock(&queue->queue_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bh_queue_cond_timedwait(&queue->queue_wait_cond, &queue->queue_lock,
|
||||
timeout);
|
||||
timeout_us);
|
||||
}
|
||||
|
||||
if (queue->cnt == 0) {
|
||||
@ -226,7 +226,7 @@ void bh_queue_enter_loop_run(bh_queue *queue,
|
||||
return;
|
||||
|
||||
while (!queue->exit_loop_run) {
|
||||
bh_queue_node * message = bh_get_msg(queue, (int)BHT_WAIT_FOREVER);
|
||||
bh_queue_node * message = bh_get_msg(queue, BHT_WAIT_FOREVER);
|
||||
|
||||
if (message) {
|
||||
handle_cb(message, arg);
|
||||
|
||||
@ -56,7 +56,7 @@ bool bh_post_msg(bh_queue *queue, unsigned short tag, void *body,
|
||||
unsigned int len);
|
||||
bool bh_post_msg2(bh_queue *queue, bh_message_t msg);
|
||||
|
||||
bh_message_t bh_get_msg(bh_queue *queue, int timeout);
|
||||
bh_message_t bh_get_msg(bh_queue *queue, uint64 timeout_us);
|
||||
|
||||
unsigned
|
||||
bh_queue_get_message_count(bh_queue *queue);
|
||||
|
||||
@ -396,7 +396,6 @@ handle_expired_timers(timer_ctx_t ctx, app_timer_t *expired)
|
||||
if (t->is_periodic) {
|
||||
/* if it is repeating, then reschedule it; */
|
||||
reschedule_timer(ctx, t);
|
||||
|
||||
}
|
||||
else {
|
||||
/* else move it to idle list */
|
||||
@ -423,10 +422,10 @@ get_expiry_ms(timer_ctx_t ctx)
|
||||
return ms_to_next_expiry;
|
||||
}
|
||||
|
||||
int
|
||||
uint32
|
||||
check_app_timers(timer_ctx_t ctx)
|
||||
{
|
||||
app_timer_t *t, *expired = NULL;
|
||||
app_timer_t *t, *expired = NULL, *expired_end = NULL;
|
||||
uint64 now = bh_get_tick_ms();
|
||||
|
||||
os_mutex_lock(&ctx->mutex);
|
||||
@ -436,8 +435,15 @@ check_app_timers(timer_ctx_t ctx)
|
||||
if (now >= t->expiry) {
|
||||
ctx->app_timers = t->next;
|
||||
|
||||
t->next = expired;
|
||||
expired = t;
|
||||
/* append t to the end of expired list */
|
||||
t->next = NULL;
|
||||
if (!expired_end) {
|
||||
expired = expired_end = t;
|
||||
}
|
||||
else {
|
||||
expired_end->next = t;
|
||||
expired_end = t;
|
||||
}
|
||||
|
||||
t = ctx->app_timers;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ bool sys_timer_destroy(timer_ctx_t ctx, uint32 timer_id);
|
||||
bool sys_timer_cancel(timer_ctx_t ctx, uint32 timer_id);
|
||||
bool sys_timer_restart(timer_ctx_t ctx, uint32 timer_id, int interval);
|
||||
void cleanup_app_timers(timer_ctx_t ctx);
|
||||
int check_app_timers(timer_ctx_t ctx);
|
||||
uint32 check_app_timers(timer_ctx_t ctx);
|
||||
uint32 get_expiry_ms(timer_ctx_t ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user