Skip to content

Commit 609c3a3

Browse files
authored
Merge pull request #46 from smaeul/up/no-sync
Fall back to Rc on targets without atomics
2 parents 3db1dd3 + 8f20e9b commit 609c3a3

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

src/mqtt/common/arc.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2025 Takatoshi Kondo
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
#[cfg(target_has_atomic = "ptr")]
24+
pub type Arc<T> = alloc::sync::Arc<T>;
25+
#[cfg(not(target_has_atomic = "ptr"))]
26+
pub type Arc<T> = alloc::rc::Rc<T>;

src/mqtt/common/arc_payload.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
use alloc::{string::String, sync::Arc, vec::Vec};
23+
use crate::mqtt::Arc;
24+
use alloc::{string::String, vec::Vec};
2425
use serde::{Serialize, Serializer};
2526

2627
// SSO buffer size configuration - priority-based selection for maximum size

src/mqtt/common/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22+
23+
mod arc;
24+
pub use arc::Arc;
25+
2226
mod arc_payload;
2327
pub use arc_payload::{ArcPayload, IntoPayload};
2428

src/mqtt/connection/packet_builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22-
use crate::mqtt::common::Cursor;
22+
23+
use crate::mqtt::common::{Arc, Cursor};
2324
use crate::mqtt::result_code::MqttError;
24-
use alloc::{sync::Arc, vec::Vec};
25+
use alloc::vec::Vec;
2526

2627
#[derive(Debug, Clone)]
2728
pub enum PacketData {

src/mqtt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ pub use connection::SendBehavior;
3030
pub use connection::Version;
3131

3232
pub mod common;
33-
pub use common::{ArcPayload, IntoPayload, ValueAllocator};
33+
pub use common::{Arc, ArcPayload, IntoPayload, ValueAllocator};
3434

3535
pub mod result_code;

src/mqtt/packet/v3_1_1/publish.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
use alloc::sync::Arc;
2423
use alloc::vec::Vec;
2524
use core::fmt;
2625
use core::mem;
@@ -42,7 +41,7 @@ use crate::mqtt::packet::GenericPacketDisplay;
4241
use crate::mqtt::packet::GenericPacketTrait;
4342
use crate::mqtt::packet::IsPacketId;
4443
use crate::mqtt::result_code::MqttError;
45-
use crate::mqtt::{ArcPayload, IntoPayload};
44+
use crate::mqtt::{Arc, ArcPayload, IntoPayload};
4645

4746
/// MQTT 3.1.1 PUBLISH packet representation
4847
///

src/mqtt/packet/v5_0/publish.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// SOFTWARE.
2222

2323
use alloc::string::String;
24-
use alloc::sync::Arc;
2524
use alloc::vec::Vec;
2625
use core::fmt;
2726
use core::mem;
@@ -48,7 +47,7 @@ use crate::mqtt::packet::IsPacketId;
4847
use crate::mqtt::packet::PropertiesToBuffers;
4948
use crate::mqtt::packet::{Properties, PropertiesParse, PropertiesSize, Property};
5049
use crate::mqtt::result_code::MqttError;
51-
use crate::mqtt::{ArcPayload, IntoPayload};
50+
use crate::mqtt::{Arc, ArcPayload, IntoPayload};
5251

5352
/// MQTT 5.0 PUBLISH packet representation
5453
///

0 commit comments

Comments
 (0)