Skip to content

Commit

Permalink
Assemble queue element outside the critical section
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 10, 2023
1 parent 152c8c7 commit faa1c11
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions esp-wifi/src/compat/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,15 @@ pub fn send_queued(
// handle the WIFI_QUEUE
unsafe {
if queue == &mut REAL_WIFI_QUEUE as *mut _ as *mut crate::binary::c_types::c_void {
critical_section::with(|_| {
// assume the size is 8 - shouldn't rely on that
let message = item as *const u8;
let mut data = [0u8; 8];
for i in 0..8 as usize {
data[i] = *(message.offset(i as isize));
}
trace!("queue posting {:?}", data);
// assume the size is 8 - shouldn't rely on that
let message = item as *const u8;
let mut data = [0u8; 8];
for i in 0..8 as usize {
data[i] = *(message.offset(i as isize));
}
trace!("queue posting {:?}", data);

critical_section::with(|_| {
REAL_WIFI_QUEUE.enqueue(data);
memory_fence();
});
Expand Down Expand Up @@ -476,24 +476,21 @@ pub fn receive_queued(
}

loop {
let res = critical_section::with(|_| {
let message = critical_section::with(|_| {
memory_fence();
if let Some(message) = REAL_WIFI_QUEUE.dequeue() {
let item = item as *mut u8;
for i in 0..8 {
item.offset(i).write_volatile(message[i as usize]);
}
trace!("received {:?}", message);
1
} else {
0
}
REAL_WIFI_QUEUE.dequeue()
});

if res == 1 {
if let Some(message) = REAL_WIFI_QUEUE.dequeue() {
let item = item as *mut u8;
for i in 0..8 {
item.offset(i).write_volatile(message[i as usize]);
}
trace!("received {:?}", message);

trace!("queue_recv returns");
return res;
}
return 1;
};

if block_time_tick != OSI_FUNCS_TIME_BLOCKING
&& crate::timer::get_systimer_count() > end_time
Expand Down

0 comments on commit faa1c11

Please sign in to comment.