Create mutexes in heap memory (#2202)
* Create mutexes in heap memory * CHANGELOG.md * Remove unnecessary CS usage
This commit is contained in:
parent
5324bce815
commit
370f54119f
@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Feature `sys-logs` doesn't break the build anymore (#2117)
|
- Feature `sys-logs` doesn't break the build anymore (#2117)
|
||||||
- Fixed a panic when overflow-checks are enabled (#2164)
|
- Fixed a panic when overflow-checks are enabled (#2164)
|
||||||
|
- Create mutexes in heap memory, fixes running out of mutexes when connecting and disconnecting to a WPA2-ENTERPRISE ap multiple times (#2202)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|||||||
@ -26,13 +26,6 @@ struct Mutex {
|
|||||||
recursive: bool,
|
recursive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut MUTEXES: [Mutex; 10] = [Mutex {
|
|
||||||
locking_pid: 0xffff_ffff,
|
|
||||||
count: 0,
|
|
||||||
recursive: false,
|
|
||||||
}; 10];
|
|
||||||
static mut MUTEX_IDX_CURRENT: usize = 0;
|
|
||||||
|
|
||||||
/// A naive and pretty much unsafe queue to back the queues used in drivers and
|
/// A naive and pretty much unsafe queue to back the queues used in drivers and
|
||||||
/// supplicant code
|
/// supplicant code
|
||||||
struct RawQueue {
|
struct RawQueue {
|
||||||
@ -117,33 +110,21 @@ unsafe extern "C" fn strnlen(chars: *const u8, maxlen: usize) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn sem_create(max: u32, init: u32) -> *mut c_void {
|
pub fn sem_create(max: u32, init: u32) -> *mut c_void {
|
||||||
critical_section::with(|_| unsafe {
|
unsafe {
|
||||||
let ptr = malloc(4) as *mut u32;
|
let ptr = malloc(4) as *mut u32;
|
||||||
ptr.write_volatile(init);
|
ptr.write_volatile(init);
|
||||||
|
|
||||||
trace!("sem created res = {:?}", ptr);
|
trace!("sem created res = {:?}", ptr);
|
||||||
ptr.cast()
|
ptr.cast()
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sem_delete(semphr: *mut c_void) {
|
pub fn sem_delete(semphr: *mut c_void) {
|
||||||
trace!(">>> sem delete");
|
trace!(">>> sem delete");
|
||||||
|
|
||||||
// TODO remove this once fixed in esp_supplicant AND we updated to the fixed -
|
|
||||||
// JIRA: WIFI-6676
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if semphr as usize > addr_of!(MUTEXES) as usize
|
|
||||||
&& semphr as usize
|
|
||||||
<= unsafe { addr_of!(MUTEXES).byte_add(size_of_val(&*addr_of!(MUTEXES))) } as usize
|
|
||||||
{
|
|
||||||
warn!("trying to remove a mutex via sem_delete");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
critical_section::with(|_| unsafe {
|
|
||||||
free(semphr.cast());
|
free(semphr.cast());
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sem_take(semphr: *mut c_void, tick: u32) -> i32 {
|
pub fn sem_take(semphr: *mut c_void, tick: u32) -> i32 {
|
||||||
@ -200,14 +181,27 @@ pub fn thread_sem_get() -> *mut c_void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_recursive_mutex() -> *mut c_void {
|
pub fn create_recursive_mutex() -> *mut c_void {
|
||||||
critical_section::with(|_| unsafe {
|
let mutex = Mutex {
|
||||||
let ptr = &mut MUTEXES[MUTEX_IDX_CURRENT] as *mut Mutex;
|
locking_pid: 0xffff_ffff,
|
||||||
(*ptr).recursive = true;
|
count: 0,
|
||||||
MUTEX_IDX_CURRENT += 1;
|
recursive: true,
|
||||||
memory_fence();
|
};
|
||||||
trace!("recursive_mutex_create called {:?}", ptr);
|
|
||||||
ptr as *mut c_void
|
let ptr = unsafe { malloc(size_of_val(&mutex) as u32) as *mut Mutex };
|
||||||
})
|
unsafe {
|
||||||
|
ptr.write(mutex);
|
||||||
|
}
|
||||||
|
memory_fence();
|
||||||
|
|
||||||
|
trace!("recursive_mutex_create called {:?}", ptr);
|
||||||
|
ptr as *mut c_void
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mutex_delete(mutex: *mut c_void) {
|
||||||
|
let ptr = mutex as *mut Mutex;
|
||||||
|
unsafe {
|
||||||
|
free(mutex.cast());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lock a mutex. Block until successful.
|
/// Lock a mutex. Block until successful.
|
||||||
|
|||||||
@ -326,8 +326,8 @@ pub unsafe extern "C" fn recursive_mutex_create() -> *mut crate::binary::c_types
|
|||||||
/// None
|
/// None
|
||||||
///
|
///
|
||||||
/// *************************************************************************
|
/// *************************************************************************
|
||||||
pub unsafe extern "C" fn mutex_delete(_mutex: *mut crate::binary::c_types::c_void) {
|
pub unsafe extern "C" fn mutex_delete(mutex: *mut crate::binary::c_types::c_void) {
|
||||||
todo!("mutex_delete")
|
crate::compat::common::mutex_delete(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// **************************************************************************
|
/// **************************************************************************
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user