Skip to content

Commit adee687

Browse files
committed
Fix compilation.
1 parent f10b293 commit adee687

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

library/std/src/sys/unix/freertos/condvar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub struct Condvar {
1010
waiter_list: UnsafeCell<Option<VecDeque<SemaphoreHandle_t>>>,
1111
}
1212

13+
pub type MovableCondvar = Condvar;
14+
1315
unsafe impl Send for Condvar {}
1416
unsafe impl Sync for Condvar {}
1517

library/std/src/sys/unix/freertos/mutex.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct Mutex {
99
initialized: AtomicU8,
1010
}
1111

12+
pub type MovableMutex = Mutex;
13+
1214
unsafe impl Send for Mutex {}
1315
unsafe impl Sync for Mutex {}
1416

@@ -31,14 +33,14 @@ impl Mutex {
3133
#[inline]
3234
unsafe fn atomic_init(&self) {
3335
loop {
34-
match self.initialized.compare_and_swap(UNINITIALIZED, INITIALIZING, SeqCst) {
35-
UNINITIALIZED => {
36+
match self.initialized.compare_exchange_weak(UNINITIALIZED, INITIALIZING, SeqCst, SeqCst) {
37+
Ok(UNINITIALIZED) => {
3638
*self.inner.get() = xSemaphoreCreateMutex();
3739
debug_assert!(!(*self.inner.get()).is_null());
3840
self.initialized.store(INITIALIZED, SeqCst);
3941
return;
4042
}
41-
INITIALIZED => return,
43+
Err(INITIALIZED) => return,
4244
_ => continue,
4345
}
4446
}
@@ -67,14 +69,14 @@ impl Mutex {
6769
#[inline]
6870
pub unsafe fn destroy(&self) {
6971
loop {
70-
match self.initialized.compare_and_swap(INITIALIZED, UNINITIALIZING, SeqCst) {
71-
INITIALIZED => {
72+
match self.initialized.compare_exchange_weak(INITIALIZED, UNINITIALIZING, SeqCst, SeqCst) {
73+
Ok(INITIALIZED) => {
7274
vSemaphoreDelete(*self.inner.get());
7375
*self.inner.get() = ptr::null_mut();
7476
self.initialized.store(UNINITIALIZED, SeqCst);
7577
return;
7678
}
77-
UNINITIALIZED => return,
79+
Err(UNINITIALIZED) => return,
7880
_ => continue,
7981
}
8082
}
@@ -111,14 +113,14 @@ impl ReentrantMutex {
111113
#[inline]
112114
unsafe fn atomic_init(&self) {
113115
loop {
114-
match self.initialized.compare_and_swap(UNINITIALIZED, INITIALIZING, SeqCst) {
115-
UNINITIALIZED => {
116+
match self.initialized.compare_exchange_weak(UNINITIALIZED, INITIALIZING, SeqCst, SeqCst) {
117+
Ok(UNINITIALIZED) => {
116118
*self.inner.get() = xSemaphoreCreateRecursiveMutex();
117119
debug_assert!(!(*self.inner.get()).is_null());
118120
self.initialized.store(INITIALIZED, SeqCst);
119121
return;
120122
}
121-
INITIALIZED => return,
123+
Err(INITIALIZED) => return,
122124
_ => continue,
123125
}
124126
}
@@ -145,14 +147,14 @@ impl ReentrantMutex {
145147

146148
pub unsafe fn destroy(&self) {
147149
loop {
148-
match self.initialized.compare_and_swap(INITIALIZED, UNINITIALIZING, SeqCst) {
149-
INITIALIZED => {
150+
match self.initialized.compare_exchange_weak(INITIALIZED, UNINITIALIZING, SeqCst, SeqCst) {
151+
Ok(INITIALIZED) => {
150152
vSemaphoreDelete(*self.inner.get());
151153
*self.inner.get() = ptr::null_mut();
152154
self.initialized.store(UNINITIALIZED, SeqCst);
153155
return;
154156
}
155-
UNINITIALIZED => return,
157+
Err(UNINITIALIZED) => return,
156158
_ => continue,
157159
}
158160
}

library/std/src/sys/unix/freertos/thread.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ impl Thread {
7777
*Box::from_raw(arg as *mut (Arc<Mutex>, Arc<AtomicU8>, Box<dyn FnOnce()>));
7878

7979
join_mutex.lock();
80-
state.compare_and_swap(PENDING, RUNNING, SeqCst);
80+
let _ = state.compare_exchange(PENDING, RUNNING, SeqCst, SeqCst);
8181

8282
main();
8383
thread_local_dtor::run_dtors();
8484

85-
let previous_state = state.compare_and_swap(RUNNING, EXITED, SeqCst);
85+
let previous_state = match state.compare_exchange(RUNNING, EXITED, SeqCst, SeqCst) {
86+
Ok(v) => v,
87+
Err(v) => v,
88+
};
8689

8790
join_mutex.unlock();
8891

library/std/src/sys/unix/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,8 @@ pub fn link(original: &Path, link: &Path) -> io::Result<()> {
11081108
let original = cstr(original)?;
11091109
let link = cstr(link)?;
11101110
cfg_if::cfg_if! {
1111-
if #[cfg(any(target_os = "vxworks", target_os = "redox", target_os = "android"))] {
1112-
// VxWorks, Redox, and old versions of Android lack `linkat`, so use
1111+
if #[cfg(any(target_os = "vxworks", target_os = "freertos", target_os = "redox", target_os = "android"))] {
1112+
// VxWorks, FreeRTOS, Redox, and old versions of Android lack `linkat`, so use
11131113
// `link` instead. POSIX leaves it implementation-defined whether
11141114
// `link` follows symlinks, so rely on the `symlink_hard_link` test
11151115
// in library/std/src/fs/tests.rs to check the behavior.

0 commit comments

Comments
 (0)