Skip to content

Commit

Permalink
Merge pull request eclipse-iceoryx#495 from elfenpiff/iox2-3-fix-nigh…
Browse files Browse the repository at this point in the history
…tly-pipeline

[eclipse-iceoryx#3] fix nightly pipeline
  • Loading branch information
elfenpiff authored Oct 30, 2024
2 parents 336513d + 980189b commit 29c71af
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 87 deletions.
16 changes: 15 additions & 1 deletion iceoryx2-bb/log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,21 @@ pub fn get_logger() -> &'static dyn Log {
unsafe { LOGGER = Some(&DEFAULT_LOGGER) };
});

unsafe { *LOGGER.as_ref().unwrap() }
// # From The Compiler
//
// shared references to mutable statics are dangerous; it's undefined behavior
// 1. if the static is mutated or
// 2. if a mutable reference is created for it while the shared reference lives
//
// # Safety
//
// 1. The logger is always an immutable threadsafe object with only interior mutability.
// 2. [`std::sync::Once`] is used to ensure it can only mutated on initialization and the
// lifetime is `'static`.
#[allow(static_mut_refs)]
unsafe {
*LOGGER.as_ref().unwrap()
}
}

#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/posix/src/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'a> Barrier<'a> {
}

impl<'a> IpcConstructible<'a, BarrierHandle> for Barrier<'a> {
fn new(handle: &'a BarrierHandle) -> Barrier {
fn new(handle: &BarrierHandle) -> Barrier {
Barrier { handle }
}
}
Expand Down
10 changes: 0 additions & 10 deletions iceoryx2-bb/posix/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ enum_gen! {
FailedToSetAffinity <= ThreadSetAffinityError
}

/// Terminates the callers thread
pub fn thread_exit() -> ! {
unsafe { posix::pthread_exit(std::ptr::null_mut::<posix::void>()) }
}

/// Describes the scope in which a thread is competing with other threads for CPU time.
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
#[repr(i32)]
Expand Down Expand Up @@ -803,11 +798,6 @@ impl<'thread> Thread<'thread> {
v => (UnknownError(v as i32), "{} {:?} since an unknown error occurred ({})", msg, signal, v)
);
}

/// Terminates the current thread.
pub fn cancel(&mut self) -> bool {
unsafe { posix::pthread_cancel(self.handle.handle) != 0 }
}
}

impl<'thread> ThreadProperties for Thread<'thread> {
Expand Down
41 changes: 0 additions & 41 deletions iceoryx2-bb/posix/tests/thread_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,44 +198,3 @@ fn thread_destructor_does_block_on_busy_thread() {
drop(thread);
assert_that!(start.elapsed(), time_at_least SLEEP_DURATION);
}

#[test]
fn thread_cancel_works() {
let barrier = Arc::new(Barrier::new(2));
let mut thread = {
let barrier = barrier.clone();
ThreadBuilder::new()
.affinity(0)
.spawn(move || {
barrier.wait();
loop {
// NOTE we have to use 'sleep' instead of 'barrier.wait()' since the latter blocks cancellation
std::thread::sleep(Duration::from_millis(100));
}
})
.unwrap()
};

// if the thread is not executed we observe a deadlock here
barrier.wait();
thread.cancel();
}

#[test]
fn thread_exit_works() {
let _thread = {
ThreadBuilder::new()
.affinity(0)
.spawn(move || {
// TODO: [#258] This sleep prevents a 'SIGABRT' on Linux with release builds with rustc v1.81.0-nightly!
#[cfg(target_os = "linux")]
std::thread::sleep(Duration::from_nanos(1));
thread_exit();
#[allow(unreachable_code)]
{
panic!("This should not happen when 'thread_exit' works as intended");
}
})
.unwrap()
};
}
8 changes: 0 additions & 8 deletions iceoryx2-pal/posix/src/freebsd/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,6 @@ pub unsafe fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: size
internal::pthread_getname_np(thread, name, len)
}

pub unsafe fn pthread_cancel(thread: pthread_t) -> int {
crate::internal::pthread_cancel(thread)
}

pub unsafe fn pthread_exit(value_ptr: *mut void) -> ! {
crate::internal::pthread_exit(value_ptr)
}

pub unsafe fn pthread_kill(thread: pthread_t, sig: int) -> int {
internal::pthread_kill(thread, sig)
}
Expand Down
8 changes: 0 additions & 8 deletions iceoryx2-pal/posix/src/linux/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,6 @@ pub unsafe fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: size
internal::pthread_getname_np(thread, name, len)
}

pub unsafe fn pthread_cancel(thread: pthread_t) -> int {
crate::internal::pthread_cancel(thread)
}

pub unsafe fn pthread_exit(value_ptr: *mut void) -> ! {
crate::internal::pthread_exit(value_ptr)
}

pub unsafe fn pthread_kill(thread: pthread_t, sig: int) -> int {
internal::pthread_kill(thread, sig)
}
Expand Down
8 changes: 0 additions & 8 deletions iceoryx2-pal/posix/src/macos/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,6 @@ pub unsafe fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: size
Errno::ESUCCES as _
}

pub unsafe fn pthread_cancel(thread: pthread_t) -> int {
crate::internal::pthread_cancel(thread)
}

pub unsafe fn pthread_exit(value_ptr: *mut void) -> ! {
crate::internal::pthread_exit(value_ptr)
}

pub unsafe fn pthread_kill(_thread: pthread_t, _sig: int) -> int {
todo!()
}
Expand Down
11 changes: 1 addition & 10 deletions iceoryx2-pal/posix/src/windows/pthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use windows_sys::Win32::{
System::{
Memory::LocalFree,
Threading::{
CreateThread, ExitThread, GetCurrentThread, GetCurrentThreadId, GetExitCodeThread,
CreateThread, GetCurrentThread, GetCurrentThreadId, GetExitCodeThread,
GetThreadDescription, GetThreadId, SetThreadAffinityMask, SetThreadDescription,
SetThreadPriority, TerminateThread, WaitForSingleObject, WaitOnAddress,
WakeByAddressAll, WakeByAddressSingle, INFINITE, THREAD_PRIORITY_ABOVE_NORMAL,
Expand Down Expand Up @@ -396,15 +396,6 @@ pub unsafe fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: size
Errno::ESUCCES as int
}

pub unsafe fn pthread_cancel(thread: pthread_t) -> int {
TerminateThread(thread.handle, 0);
Errno::ESUCCES as int
}

pub unsafe fn pthread_exit(value_ptr: *mut void) -> ! {
ExitThread(0);
}

pub unsafe fn pthread_kill(thread: pthread_t, sig: int) -> int {
TerminateThread(thread.handle, 0);
Errno::ESUCCES as int
Expand Down

0 comments on commit 29c71af

Please sign in to comment.