Skip to content

Commit

Permalink
Fix early timeout when counter overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 29, 2023
1 parent 9509060 commit 178ba88
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions esp-wifi/src/compat/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ pub fn sem_take(semphr: *mut c_void, tick: u32) -> i32 {
trace!(">>>> semphr_take {:?} block_time_tick {}", semphr, tick);

let forever = tick == OSI_FUNCS_TIME_BLOCKING;
let tick = if tick == 0 { 1 } else { tick };
let end_time = crate::timer::get_systimer_count() + tick as u64;
let timeout = tick as u64;
let start = crate::timer::get_systimer_count();

let sem_idx = semphr as usize - 1;

Expand All @@ -299,10 +299,8 @@ pub fn sem_take(semphr: *mut c_void, tick: u32) -> i32 {
return 1;
}

if !forever {
if crate::timer::get_systimer_count() > end_time {
break 'outer;
}
if !forever && crate::timer::get_systimer_count().wrapping_sub(start) > timeout {
break 'outer;
}

yield_task();
Expand Down Expand Up @@ -449,15 +447,12 @@ pub fn send_queued(queue: *mut c_void, item: *mut c_void, block_time_tick: u32)
})
}

pub fn receive_queued(queue: *mut c_void, item: *mut c_void, block_time_tick: u32) -> i32 {
trace!(
"queue_recv {:?} item {:?} block_time_tick {}",
queue,
item,
block_time_tick
);
pub fn receive_queued(queue: *mut c_void, item: *mut c_void, tick: u32) -> i32 {
trace!("queue_recv {:?} item {:?} tick {}", queue, item, tick);

let end_time = crate::timer::get_systimer_count() + block_time_tick as u64;
let forever = tick == OSI_FUNCS_TIME_BLOCKING;
let timeout = tick as u64;
let start = crate::timer::get_systimer_count();

// handle the WIFI_QUEUE
if queue != unsafe { addr_of_mut!(REAL_WIFI_QUEUE).cast() } {
Expand All @@ -479,9 +474,7 @@ pub fn receive_queued(queue: *mut c_void, item: *mut c_void, block_time_tick: u3
return 1;
};

if block_time_tick != OSI_FUNCS_TIME_BLOCKING
&& crate::timer::get_systimer_count() > end_time
{
if !forever && crate::timer::get_systimer_count().wrapping_sub(start) > timeout {
trace!("queue_recv returns with timeout");
return 0;
}
Expand Down

0 comments on commit 178ba88

Please sign in to comment.