From 2f7f59687217e31eab05eabbcab654914e7902a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 3 Jul 2024 10:45:44 +0200 Subject: [PATCH] Fix compilation on targets without atomics --- src/storage.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/storage.rs b/src/storage.rs index 09b0ae75a7..65540887a2 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -2,14 +2,24 @@ use core::borrow::{Borrow, BorrowMut}; +#[cfg(any( + feature = "portable-atomic", + all(feature = "mpmc_large", target_has_atomic = "ptr"), + all(not(feature = "mpmc_large"), target_has_atomic = "8") +))] +use crate::mpmc::{MpMcQueueInner, MpMcQueueView}; +#[cfg(any( + feature = "portable-atomic", + target_has_atomic = "ptr", + has_atomic_load_store +))] +use crate::spsc::{QueueInner, QueueView}; use crate::{ binary_heap::{BinaryHeapInner, BinaryHeapView}, deque::{DequeInner, DequeView}, histbuf::{HistoryBufferInner, HistoryBufferView}, linear_map::{LinearMapInner, LinearMapView}, - mpmc::{MpMcQueueInner, MpMcQueueView}, sorted_linked_list::{SortedLinkedListIndex, SortedLinkedListInner, SortedLinkedListView}, - spsc::{QueueInner, QueueView}, string::{StringInner, StringView}, vec::VecInner, VecView, @@ -40,10 +50,20 @@ pub(crate) trait SealedStorage: Sized { fn as_mut_histbuf_view(this: &mut HistoryBufferInner) -> &mut HistoryBufferView where Self: Storage; + #[cfg(any( + feature = "portable-atomic", + all(feature = "mpmc_large", target_has_atomic = "ptr"), + all(not(feature = "mpmc_large"), target_has_atomic = "8") + ))] /// Convert a `MpMcQueue` to a `MpMcQueueView` fn as_mpmc_queue_view(this: &MpMcQueueInner) -> &MpMcQueueView where Self: Storage; + #[cfg(any( + feature = "portable-atomic", + all(feature = "mpmc_large", target_has_atomic = "ptr"), + all(not(feature = "mpmc_large"), target_has_atomic = "8") + ))] /// Convert a `MpMcQueue` to a `MpMcQueueView` fn as_mut_mpmc_queue_view(this: &mut MpMcQueueInner) -> &mut MpMcQueueView where @@ -68,10 +88,20 @@ pub(crate) trait SealedStorage: Sized { ) -> &mut BinaryHeapView where Self: Storage; + #[cfg(any( + feature = "portable-atomic", + target_has_atomic = "ptr", + has_atomic_load_store + ))] /// Convert a `Queue` to a `QueueView` fn as_queue_view(this: &QueueInner) -> &QueueView where Self: Storage; + #[cfg(any( + feature = "portable-atomic", + target_has_atomic = "ptr", + has_atomic_load_store + ))] /// Convert a `Queue` to a `QueueView` fn as_mut_queue_view(this: &mut QueueInner) -> &mut QueueView where @@ -159,10 +189,20 @@ impl SealedStorage for OwnedStorage { ) -> &mut SortedLinkedListView { this } + #[cfg(any( + feature = "portable-atomic", + target_has_atomic = "ptr", + has_atomic_load_store + ))] /// Convert a `Queue` to a `QueueView` fn as_queue_view(this: &QueueInner) -> &QueueView { this } + #[cfg(any( + feature = "portable-atomic", + target_has_atomic = "ptr", + has_atomic_load_store + ))] /// Convert a `Queue` to a `QueueView` fn as_mut_queue_view(this: &mut QueueInner) -> &mut QueueView { this @@ -193,10 +233,20 @@ impl SealedStorage for OwnedStorage { ) -> &mut LinearMapView { this } + #[cfg(any( + feature = "portable-atomic", + all(feature = "mpmc_large", target_has_atomic = "ptr"), + all(not(feature = "mpmc_large"), target_has_atomic = "8") + ))] /// Convert a `MpMcQueue` to a `MpMcQueueView` fn as_mpmc_queue_view(this: &MpMcQueueInner) -> &MpMcQueueView { this } + #[cfg(any( + feature = "portable-atomic", + all(feature = "mpmc_large", target_has_atomic = "ptr"), + all(not(feature = "mpmc_large"), target_has_atomic = "8") + ))] /// Convert a `MpMcQueue` to a `MpMcQueueView` fn as_mut_mpmc_queue_view(this: &mut MpMcQueueInner) -> &mut MpMcQueueView { this @@ -252,10 +302,20 @@ impl SealedStorage for ViewStorage { ) -> &mut SortedLinkedListView { this } + #[cfg(any( + feature = "portable-atomic", + target_has_atomic = "ptr", + has_atomic_load_store + ))] /// Convert a `Queue` to a `QueueView` fn as_queue_view(this: &QueueInner) -> &QueueView { this } + #[cfg(any( + feature = "portable-atomic", + target_has_atomic = "ptr", + has_atomic_load_store + ))] /// Convert a `Queue` to a `QueueView` fn as_mut_queue_view(this: &mut QueueInner) -> &mut QueueView { this @@ -286,10 +346,20 @@ impl SealedStorage for ViewStorage { ) -> &mut LinearMapView { this } + #[cfg(any( + feature = "portable-atomic", + all(feature = "mpmc_large", target_has_atomic = "ptr"), + all(not(feature = "mpmc_large"), target_has_atomic = "8") + ))] /// Convert a `MpMcQueue` to a `MpMcQueueView` fn as_mpmc_queue_view(this: &MpMcQueueInner) -> &MpMcQueueView { this } + #[cfg(any( + feature = "portable-atomic", + all(feature = "mpmc_large", target_has_atomic = "ptr"), + all(not(feature = "mpmc_large"), target_has_atomic = "8") + ))] /// Convert a `MpMcQueue` to a `MpMcQueueView` fn as_mut_mpmc_queue_view(this: &mut MpMcQueueInner) -> &mut MpMcQueueView { this