Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create mutexes in heap memory #2202

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions esp-wifi/src/compat/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ unsafe extern "C" fn strnlen(chars: *const u8, maxlen: usize) -> usize {
}

pub fn sem_create(max: u32, init: u32) -> *mut c_void {
critical_section::with(|_| unsafe {
unsafe {
let ptr = malloc(4) as *mut u32;
ptr.write_volatile(init);

trace!("sem created res = {:?}", ptr);
ptr.cast()
})
}
}

pub fn sem_delete(semphr: *mut c_void) {
trace!(">>> sem delete");

critical_section::with(|_| unsafe {
unsafe {
free(semphr.cast());
})
}
}

pub fn sem_take(semphr: *mut c_void, tick: u32) -> i32 {
Expand Down Expand Up @@ -181,29 +181,27 @@ pub fn thread_sem_get() -> *mut c_void {
}

pub fn create_recursive_mutex() -> *mut c_void {
critical_section::with(|_| unsafe {
let mutex = Mutex {
locking_pid: 0xffff_ffff,
count: 0,
recursive: true,
};
let mutex = Mutex {
locking_pid: 0xffff_ffff,
count: 0,
recursive: true,
};

let ptr = unsafe { malloc(size_of_val(&mutex) as u32) as *mut Mutex };
unsafe {
ptr.write(mutex);
}
memory_fence();
let ptr = unsafe { malloc(size_of_val(&mutex) as u32) as *mut Mutex };
unsafe {
ptr.write(mutex);
}
memory_fence();
MabezDev marked this conversation as resolved.
Show resolved Hide resolved

trace!("recursive_mutex_create called {:?}", ptr);
ptr as *mut c_void
})
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;
critical_section::with(|_| unsafe {
unsafe {
free(mutex.cast());
});
}
}

/// Lock a mutex. Block until successful.
Expand Down
Loading