16
16
//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
17
17
18
18
use crate :: {
19
- alloc:: { box_ext:: BoxExt , flags :: * } ,
19
+ alloc:: { box_ext:: BoxExt , Flags } ,
20
20
bindings,
21
21
error:: { self , Error } ,
22
22
init:: { self , InPlaceInit , Init , PinInit } ,
@@ -58,7 +58,7 @@ mod std_vendor;
58
58
/// }
59
59
///
60
60
/// // Create a refcounted instance of `Example`.
61
- /// let obj = Arc::try_new (Example { a: 10, b: 20 })?;
61
+ /// let obj = Arc::new (Example { a: 10, b: 20 }, GFP_KERNEL )?;
62
62
///
63
63
/// // Get a new pointer to `obj` and increment the refcount.
64
64
/// let cloned = obj.clone();
@@ -97,7 +97,7 @@ mod std_vendor;
97
97
/// }
98
98
/// }
99
99
///
100
- /// let obj = Arc::try_new (Example { a: 10, b: 20 })?;
100
+ /// let obj = Arc::new (Example { a: 10, b: 20 }, GFP_KERNEL )?;
101
101
/// obj.use_reference();
102
102
/// obj.take_over();
103
103
/// # Ok::<(), Error>(())
@@ -120,7 +120,7 @@ mod std_vendor;
120
120
/// impl MyTrait for Example {}
121
121
///
122
122
/// // `obj` has type `Arc<Example>`.
123
- /// let obj: Arc<Example> = Arc::try_new (Example)?;
123
+ /// let obj: Arc<Example> = Arc::new (Example, GFP_KERNEL )?;
124
124
///
125
125
/// // `coerced` has type `Arc<dyn MyTrait>`.
126
126
/// let coerced: Arc<dyn MyTrait> = obj;
@@ -163,15 +163,15 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
163
163
164
164
impl < T > Arc < T > {
165
165
/// Constructs a new reference counted instance of `T`.
166
- pub fn try_new ( contents : T ) -> Result < Self , AllocError > {
166
+ pub fn new ( contents : T , flags : Flags ) -> Result < Self , AllocError > {
167
167
// INVARIANT: The refcount is initialised to a non-zero value.
168
168
let value = ArcInner {
169
169
// SAFETY: There are no safety requirements for this FFI call.
170
170
refcount : Opaque :: new ( unsafe { bindings:: REFCOUNT_INIT ( 1 ) } ) ,
171
171
data : contents,
172
172
} ;
173
173
174
- let inner = <Box < _ > as BoxExt < _ > >:: new ( value, GFP_KERNEL ) ?;
174
+ let inner = <Box < _ > as BoxExt < _ > >:: new ( value, flags ) ?;
175
175
176
176
// SAFETY: We just created `inner` with a reference count of 1, which is owned by the new
177
177
// `Arc` object.
@@ -388,7 +388,7 @@ impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> {
388
388
/// e.into()
389
389
/// }
390
390
///
391
- /// let obj = Arc::try_new (Example)?;
391
+ /// let obj = Arc::new (Example, GFP_KERNEL )?;
392
392
/// let cloned = do_something(obj.as_arc_borrow());
393
393
///
394
394
/// // Assert that both `obj` and `cloned` point to the same underlying object.
@@ -412,7 +412,7 @@ impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> {
412
412
/// }
413
413
/// }
414
414
///
415
- /// let obj = Arc::try_new (Example { a: 10, b: 20 })?;
415
+ /// let obj = Arc::new (Example { a: 10, b: 20 }, GFP_KERNEL )?;
416
416
/// obj.as_arc_borrow().use_reference();
417
417
/// # Ok::<(), Error>(())
418
418
/// ```
@@ -500,7 +500,7 @@ impl<T: ?Sized> Deref for ArcBorrow<'_, T> {
500
500
/// }
501
501
///
502
502
/// fn test() -> Result<Arc<Example>> {
503
- /// let mut x = UniqueArc::try_new (Example { a: 10, b: 20 })?;
503
+ /// let mut x = UniqueArc::new (Example { a: 10, b: 20 }, GFP_KERNEL )?;
504
504
/// x.a += 1;
505
505
/// x.b += 1;
506
506
/// Ok(x.into())
@@ -523,7 +523,7 @@ impl<T: ?Sized> Deref for ArcBorrow<'_, T> {
523
523
/// }
524
524
///
525
525
/// fn test() -> Result<Arc<Example>> {
526
- /// let x = UniqueArc::try_new_uninit( )?;
526
+ /// let x = UniqueArc::new_uninit(GFP_KERNEL )?;
527
527
/// Ok(x.write(Example { a: 10, b: 20 }).into())
528
528
/// }
529
529
///
@@ -543,7 +543,7 @@ impl<T: ?Sized> Deref for ArcBorrow<'_, T> {
543
543
/// }
544
544
///
545
545
/// fn test() -> Result<Arc<Example>> {
546
- /// let mut pinned = Pin::from(UniqueArc::try_new (Example { a: 10, b: 20 })?);
546
+ /// let mut pinned = Pin::from(UniqueArc::new (Example { a: 10, b: 20 }, GFP_KERNEL )?);
547
547
/// // We can modify `pinned` because it is `Unpin`.
548
548
/// pinned.as_mut().a += 1;
549
549
/// Ok(pinned.into())
@@ -557,15 +557,15 @@ pub struct UniqueArc<T: ?Sized> {
557
557
558
558
impl < T > UniqueArc < T > {
559
559
/// Tries to allocate a new [`UniqueArc`] instance.
560
- pub fn try_new ( value : T ) -> Result < Self , AllocError > {
560
+ pub fn new ( value : T , flags : Flags ) -> Result < Self , AllocError > {
561
561
Ok ( Self {
562
562
// INVARIANT: The newly-created object has a refcount of 1.
563
- inner : Arc :: try_new ( value) ?,
563
+ inner : Arc :: new ( value, flags ) ?,
564
564
} )
565
565
}
566
566
567
567
/// Tries to allocate a new [`UniqueArc`] instance whose contents are not initialised yet.
568
- pub fn try_new_uninit ( ) -> Result < UniqueArc < MaybeUninit < T > > , AllocError > {
568
+ pub fn new_uninit ( _flags : Flags ) -> Result < UniqueArc < MaybeUninit < T > > , AllocError > {
569
569
// INVARIANT: The refcount is initialised to a non-zero value.
570
570
let inner = Box :: try_init :: < AllocError > ( try_init ! ( ArcInner {
571
571
// SAFETY: There are no safety requirements for this FFI call.
0 commit comments