1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2025 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! The [`ArcSyncPolicy`] can make types threadsafe in a configurable manner. Depending on what
//! implementation is used, the contained type can become threadsafe and implement [`Send`] and
//! [`Sync`] or when the implementation does not support it the resulting type will implement
//! neither [`Send`] nor [`Sync`].
//!
//! It can be used like a mutex and is not inter-process capable.
//!
//! # Example
//!
//! ## Generic Case
//!
//! ```
//! # extern crate iceoryx2_bb_loggers;
//!
//! use iceoryx2_cal::arc_sync_policy::ArcSyncPolicy;
//! use iceoryx2_bb_elementary_traits::testing::abandonable::Abandonable;
//!
//! # use core::ptr::NonNull;
//!
//! struct Data(u64);
//!
//! impl Abandonable for Data {
//! unsafe fn abandon_in_place(this: NonNull<Self>) {}
//! }
//!
//! fn example<Policy: ArcSyncPolicy<Data>>() {
//! let my_thing = Policy::new(Data(1234)).unwrap();
//! assert!(my_thing.lock().0 == 1234);
//! }
//! ```
//!
//! ## Mutex-Protected Version, implement [`Send`] and [`Sync`]
//!
//! ```
//! # extern crate iceoryx2_bb_loggers;
//!
//! use iceoryx2_cal::arc_sync_policy::ArcSyncPolicy;
//! use iceoryx2_bb_elementary_traits::testing::abandonable::Abandonable;
//!
//! # use core::ptr::NonNull;
//!
//! #[derive(Debug)]
//! struct Data(u64);
//!
//! impl Abandonable for Data {
//! unsafe fn abandon_in_place(this: NonNull<Self>) {}
//! }
//!
//! type Policy = iceoryx2_cal::arc_sync_policy::mutex_protected::MutexProtected<Data>;
//!
//! fn my_concurrent_function<T: ArcSyncPolicy<Data> + Send + Sync>(value: &T) {}
//!
//! let my_thing = Policy::new(Data(1234)).unwrap();
//! my_concurrent_function(&my_thing);
//! ```
//!
//! ## SingleThreaded Version, does not implement [`Send`] and [`Sync`]
//!
//! ```compile_fail
//! # extern crate iceoryx2_bb_loggers;
//! use iceoryx2_bb_elementary_traits::testing::abandonable::Abandonable;
//!
//! # use core::ptr::NonNull;
//!
//! struct Data(u64);
//!
//! impl Abandonable for Data {
//! unsafe fn abandon_in_place(this: NonNull<Self>) {}
//! }
//!
//! use iceoryx2_cal::arc_sync_policy::ArcSyncPolicy;
//! type Policy = iceoryx2_cal::arc_sync_policy::single_threaded::SingleThreaded<Data>;
//!
//! fn my_concurrent_function<T: ArcSyncPolicy<Data> + Send + Sync>(value: &T) {}
//!
//! let my_thing = Policy::new(1234).unwrap();
//! // fails here since this policy does not implement `Send` or `Sync`
//! my_concurrent_function(&my_thing);
//! ```
use ;
use Abandonable;
/// The [`LockGuard`] provides access to the underlying object.
/// The actual [`ArcSyncPolicy`] concept trait.