1616//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
1717
1818use crate :: {
19- alloc:: { box_ext:: BoxExt , flags :: * } ,
19+ alloc:: { box_ext:: BoxExt , Flags } ,
2020 bindings,
2121 error:: { self , Error } ,
2222 init:: { self , InPlaceInit , Init , PinInit } ,
@@ -58,7 +58,7 @@ mod std_vendor;
5858/// }
5959///
6060/// // 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 )?;
6262///
6363/// // Get a new pointer to `obj` and increment the refcount.
6464/// let cloned = obj.clone();
@@ -97,7 +97,7 @@ mod std_vendor;
9797/// }
9898/// }
9999///
100- /// let obj = Arc::try_new (Example { a: 10, b: 20 })?;
100+ /// let obj = Arc::new (Example { a: 10, b: 20 }, GFP_KERNEL )?;
101101/// obj.use_reference();
102102/// obj.take_over();
103103/// # Ok::<(), Error>(())
@@ -120,7 +120,7 @@ mod std_vendor;
120120/// impl MyTrait for Example {}
121121///
122122/// // `obj` has type `Arc<Example>`.
123- /// let obj: Arc<Example> = Arc::try_new (Example)?;
123+ /// let obj: Arc<Example> = Arc::new (Example, GFP_KERNEL )?;
124124///
125125/// // `coerced` has type `Arc<dyn MyTrait>`.
126126/// let coerced: Arc<dyn MyTrait> = obj;
@@ -163,15 +163,15 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
163163
164164impl < T > Arc < T > {
165165 /// 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 > {
167167 // INVARIANT: The refcount is initialised to a non-zero value.
168168 let value = ArcInner {
169169 // SAFETY: There are no safety requirements for this FFI call.
170170 refcount : Opaque :: new ( unsafe { bindings:: REFCOUNT_INIT ( 1 ) } ) ,
171171 data : contents,
172172 } ;
173173
174- let inner = <Box < _ > as BoxExt < _ > >:: new ( value, GFP_KERNEL ) ?;
174+ let inner = <Box < _ > as BoxExt < _ > >:: new ( value, flags ) ?;
175175
176176 // SAFETY: We just created `inner` with a reference count of 1, which is owned by the new
177177 // `Arc` object.
@@ -388,7 +388,7 @@ impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> {
388388/// e.into()
389389/// }
390390///
391- /// let obj = Arc::try_new (Example)?;
391+ /// let obj = Arc::new (Example, GFP_KERNEL )?;
392392/// let cloned = do_something(obj.as_arc_borrow());
393393///
394394/// // 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> {
412412/// }
413413/// }
414414///
415- /// let obj = Arc::try_new (Example { a: 10, b: 20 })?;
415+ /// let obj = Arc::new (Example { a: 10, b: 20 }, GFP_KERNEL )?;
416416/// obj.as_arc_borrow().use_reference();
417417/// # Ok::<(), Error>(())
418418/// ```
@@ -500,7 +500,7 @@ impl<T: ?Sized> Deref for ArcBorrow<'_, T> {
500500/// }
501501///
502502/// 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 )?;
504504/// x.a += 1;
505505/// x.b += 1;
506506/// Ok(x.into())
@@ -523,7 +523,7 @@ impl<T: ?Sized> Deref for ArcBorrow<'_, T> {
523523/// }
524524///
525525/// fn test() -> Result<Arc<Example>> {
526- /// let x = UniqueArc::try_new_uninit( )?;
526+ /// let x = UniqueArc::new_uninit(GFP_KERNEL )?;
527527/// Ok(x.write(Example { a: 10, b: 20 }).into())
528528/// }
529529///
@@ -543,7 +543,7 @@ impl<T: ?Sized> Deref for ArcBorrow<'_, T> {
543543/// }
544544///
545545/// 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 )?);
547547/// // We can modify `pinned` because it is `Unpin`.
548548/// pinned.as_mut().a += 1;
549549/// Ok(pinned.into())
@@ -557,15 +557,15 @@ pub struct UniqueArc<T: ?Sized> {
557557
558558impl < T > UniqueArc < T > {
559559 /// 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 > {
561561 Ok ( Self {
562562 // INVARIANT: The newly-created object has a refcount of 1.
563- inner : Arc :: try_new ( value) ?,
563+ inner : Arc :: new ( value, flags ) ?,
564564 } )
565565 }
566566
567567 /// 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 > {
569569 // INVARIANT: The refcount is initialised to a non-zero value.
570570 let inner = Box :: try_init :: < AllocError > ( try_init ! ( ArcInner {
571571 // SAFETY: There are no safety requirements for this FFI call.
0 commit comments