-
Notifications
You must be signed in to change notification settings - Fork 106
Conversation
ESP-IDF returns EINVAL because - apparently - the condition variable is not actually initialized (that's a problem in my implementation of When the condition variable is created, it goes via the following route: pub const fn new() -> Condvar {
// Might be moved and address is changing it is better to avoid
// initialization of potentially opaque OS data before it landed
Condvar { inner: UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER) }
}
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "l4re",
target_os = "android",
target_os = "redox",
target_os = "none"
))]
pub unsafe fn init(&mut self) {} (NOTE: the "os" platform is set to "none" for the ESP-IDF case.) So the point is, the "init" method does nothing on the ESP and we rely on the libc::PTHREAD_COND_INITIALIZER to do its magic. However, I cannot even find the definition of this macro in the ESP-IDF source-code, so it is very likely that it is not doing anything meaningful for that platform. We should call pthread's #[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "l4re",
target_os = "android",
target_os = "redox",
target_os = "none"
)))]
pub unsafe fn init(&mut self) {
use crate::mem::MaybeUninit;
let mut attr = MaybeUninit::<libc::pthread_condattr_t>::uninit();
let r = libc::pthread_condattr_init(attr.as_mut_ptr());
assert_eq!(r, 0);
let r = libc::pthread_condattr_setclock(attr.as_mut_ptr(), libc::CLOCK_MONOTONIC);
assert_eq!(r, 0);
let r = libc::pthread_cond_init(self.inner.get(), attr.as_ptr());
assert_eq!(r, 0);
let r = libc::pthread_condattr_destroy(attr.as_mut_ptr());
assert_eq!(r, 0);
} Since all functions called in the above block are stubs on the ESP-IDF except the important But I think roughly that's the way forward. |
By the way - with my toolchain, you can try doing the fixes to std's |
THX! (I didn't really expected an answer, just wanted to document what I was doing somewhere. ^^) |
JFYI - the condvar issue is fixed in the latest STD Rust (branch "stable"). |
I'm currently not very active in esp rust stuff (surprising, I know ^^). |
I'm closing this in light of the discussion here. The thing is, I don't see how tokyo would work on the ESP-IDF given that ESP-IDF does not currently support neither kqueue nor epoll, which are a requirement for We might have a better luck with |
This example uses my Tokio fork, because Tokio doesn't know that xtensa doesn't support native atomic u64.
This example also currently still fails with:
(
r
isEINVAL
in ESP-IDFcomponents/pthread/pthread_cond_var.c:94
)I'm currently working on this from time to time, maybe someone want's to help?
(Also I don't have a Jtag debugger, so I'm doing print "debugging" on a microcontroller...)