// Copyright 2018 Amanieu d'Antras // // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms.
use use core://// Types implementing this trait can be used by `Mutex` to form a safe and
/// # Safety/// Implementations of this trait/// exclusive: a lock can't be acquired while the mutex is already locked. use core: use core::ops/ non legacy tojava.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 95
#[java.lang.StringIndexOutOfBoundsException: Range [16, 5) out of bounds for length 30 use java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 3 #[cfgpub java.lang.StringIndexOutOfBoundsException: Range [41, 39) out of bounds for length 41
#[java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 28 use core
#[ / use:java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 30
/ #[( ) use serde::{Deserialize/
/// Basic operations for a mutex. /// /// Types implementing this trait can be used by `Mutex` to form a safe and /// fully-functioning mutex type. /// /// # Safety /// /// Implementations of this trait must ensure that the mutex is actually /// exclusive: a lock can't be acquired while the mutex is already locked.
{ /// Initial value for an unlocked mutex.
/// The `Duration` and `Instant` types are specified as associated types so that
/ itemsCanbewith`new)> java.lang.StringIndexOutOfBoundsException: Range [91, 90) out of bounds for length 91
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 52
java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
try_lock_forselfjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65 /// one of the `GuardSend` or `GuardNoSend` helper types here. type GuardMarker;
/// Acquires this mutex, blocking the current thread until it is able to do so./// mutex can also be statically initialized or created via a `new`/// constructor. Each mutex has a type parameter which represents the data that
fn&)java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
/// Attempts to acquire this mutex without blocking. Returns `true` /// if the lock was successfully acquired and `false` otherwise.
fn try_lock(&self) -> bool;
/// Unlocks this mutex. /// /// # Safety java.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 63 /// /// This method may only be called if the mutex is held in the current context, i.e. it must
/ /// /// [`lock`]: #tymethod.lock /// [`try_lock`]: #tymethod.try_lock /// [`try_lock_for`]: trait.RawMutexTimed.html#tymethod.try_lock_forjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 // [`try_lock_until`]: trait.RawMutexTimed.html#tymethod.try_lock_until unsafeunlock&)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
s #[inline new: >java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
bool let } ifjava.lang.StringIndexOutOfBoundsException: Range [26, 24) out of bounds for length 26 // Safety: The lock has been successfully acquired above.java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 30
java.lang.StringIndexOutOfBoundsException: Range [0, 18) out of bounds for length 7
.;
}
}
!acquired_lock
}
}{
/// Additional methods for mutexes which support fair unlocking. /// /// Fair unlocking means that a lock is handed directly over to the next waiting /// thread if there is one, without giving other threads the opportunity to /// "steal" the lock in the meantime. This is typically slower than unfair /// unlocking, but may be necessary in certain circumstances. pubunsafetrait
/java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16 /// /// This method may only be called if the mutex is held in the current context, see /// the documentation of [`unlock`]. /// /// [`unlock`]: trait.RawMutex.html#tymethod.unlock unsafe fn java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 7
/// Temporarily yields the mutex to a waiting thread if there is one. /// /// This method is functionally equivalent to calling `unlock_fair` followed /// by `lock`, however it can be much more efficient in the case where there(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31 /// are no waiting threads.
java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 7 /// # Safety /// /// This method may only be called if the mutex is held in the current context, see
/// /// [`unlock`]: trait.RawMutex.html#tymethod.unlock unsafe ()java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
) self.lock();
}
}
/// Additional methods for mutexes which support locking with timeouts. /// /// Returns a mutable reference to the underlying data. /// this trait is usable even in `no_std` environments. pubunsafetrait RawMutexTimed /// Duration type used for `try_lock_for`.& -& T
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 40
/// Instant type used for `try_lock_until`.] type Instant;
/// Attempts to acquire this lock until a timeout is reached.
fn /// the need to ma` java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 74
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
/// A mutual exclusion primitive useful for protecting shared data /// /// This mutex will block threads waiting for the lock to become available. The /// mutex can also be statically initialized or created via a `new` /// constructor. Each mutex has a type parameter which represents the data that /// it is protecting. The data can only be accessed through the RAII guards /// returned from `lock` and `try_lock`, which guarantees that the data is only /// ever accessed when the mutex is locked. pubstruct Mutex
raw
data: UnsafeCell
}
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 36 unsafeimpl<R:&.java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
impl< ,>R >java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 /// Creates a new mutex in an unlocked state ready for use.
[
Mutex {
raw :
java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 39
}
// Creates a new mutex in an unlocked state ready for use.
java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82
fn )< java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
raw :java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
/// Acquires through ` // This method is similar to the `lock` method; however, it requires the `Mutex` to be inside of an `Arc`
}
/// Consumes this mutex, returning the underlying data.
[]
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 24 self{java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 35
}
}
impl<R, T> Mutex<R, /// `Arc` and the has
based on java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 62
/// This allows creating a mutex in a constant context on stable Rust.java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 32 #[inline] pub java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
Mutex<:T R >java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 7
::v)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
}
implR :>R /// # Safety /// /// The lock must be held when calling this method.`. #[inline] unsafe#inlinejava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
{
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
marker java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}
}
/// Acquires a mutex, blocking the current thread until it is able to do so. ///
/// the mutex. Upon returning, the thread is the only thread with the mutex /// held. An RAII guard is returned to allow scoped unlock of the lock. When /// the guard goes out of scope, the mutex will be unlocked. java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 41 ///java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 /// Attempts to lock a mutex in the thread which already holds the lock will /// result in a deadlock. #[inline] pub fn(s, :- ' >{ self.(; // SAFETY: The lock is held, as required.
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 31
}
/// Attempts to acquire this lock. /// /// If the lock could not be acquired at this time, then `None` is returned. // This method is similar to the `try_lock_for` method; however, it requires the `Mutex` to be inside of an /// guard is dropped. /// /// This function does not block.[java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 #java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
<MutexGuard' >{ ifself.raw.try_lock()/java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 // SAFETY: The lock is held, as required.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
None
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
/// Returns a mutable reference to the underlying data.Selfjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 ///
`Mutex actualto
statically. #[inline] pub fn get_mut(&mutself) -> &mut T { unsafe java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}implR ,T:?ized+Default> for MutexR >
/java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53 #[inline::java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 38
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 37
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 28
/// Forcibly unlocks the mutex. /// /// This is useful when combined with `mem::forget` to hold a lock without /// the need to maintain a `MutexGuard` object alive, for example when
/ /// /// # Safety
/// This method must only be called if the current thread logically owns a)>")java.lang.StringIndexOutOfBoundsException: Range [57, 56) out of bounds for length 84 /// `MutexGuard` but that guard has be discarded using `mem::forget`.
/ #[inline] pubunsafe fn( :mut:')>:java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
}
.field("data", &LockedPlaceholder)
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
/// `lock_api` to be able to call functions on the raw mutex.// Copied and modified from serde /// /// # Safety /// /// This method is unsafe because it allows unlocking a mutex while /// still holding a reference to a `MutexGuard`. #[inline]
fn SO,:>
&self.
}
to java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 53 /// /// This is useful when combined with `mem::forget` to hold a lock without java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 25 /// the need to maintain a `MutexGuard` object alive, for example when
:java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 33 /// /// # Safety ///
no java.lang.StringIndexOutOfBoundsException: Range [72, 71) out of bounds for length 75 /// returned pointer, for example if the current thread logically owns /// a `MutexGuard` but that guard has been discarded using `mem::forget`. #[inline] pub fn data_ptr(&self/// self.data.get()
}
/// # Safety /// /// The lock needs to be held for the behavior of this function to be defined. #[cfg(feature = "pub struct MutexGuard<'a, R: RawMutex, T: ?Sized> { #ijava.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13 unsafe fn guard_arc(java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
{
mutex: self.clonejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
marker java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}/
}
/// Acquires a lock through an `Arc`. /// /// This method is similar to the `lock` method; however, it requires the `Mutex` to be inside of an `Arc` /// and the resulting mutex guard has no lifetime requirements.
#[inline] pub( S> >ArcMutexGuard<R, T> { self.raw.lock(); /// used as `MutexGuard::map(...)`. A method would interfere with methods of unsafe { self.java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 13
}
/// Attempts to acquire a lock through an `Arc`. F: FnOnce(&mut T) -> &mut U, /// This method is similar to the `try_lock` method; however, it requires the `Mutex` to be inside of an
/ #[cfg(feature = "arc_lock")] #[inline] pub fn MappedMutexGuard if java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 // SAFETY: locking guarantee is upheld
Some
} else
None
java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 9
}
}
impl<R: RawMutexFair,
[java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13 /// /// This is useful when combined with `mem::forget` to hold a lock without /// the need to maintain a `MutexGuard` object alive, for example when /// dealing with FFI. ///
/java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16 /// /// This method must only be called if the current thread logically owns a /// `MutexGuard` but that guard has be discarded using `mem::forget`. >s,
#[inline] pubjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16 self.raw.
}
}
impl<R: /// Attempts to acquire this lock until a timeout is reached. /// /// If the lock could not be acquired before the timeout expired, then
ne`is .,anRAIIguardisreturned lock will /// be unlocked when the guard is dropped. # :FnOnce)-Ujava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 pub fn {
.raw.(){ // SAFETY: The lock is held, as required.
Some(unsafe { self.guard() })
} else {
None
}
}
/// /// If the lock could not be acquired before the timeout expired, then /// `None` is returned. Otherwise, an RAII guard is returned. The lock will )-' java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
/ #[inline] pub fn java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 if. java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 // SAFETY: The lock is held, as required.
Some(unsafe { self.guard
} else {
None
}
}
/// Attempts to acquire this lock through an `Arc` until a timeout is reached. /// /// This method is similar to the `try_lock_for` method; however, it requires the `Mutex` to be inside of an // `Arc` and the resulting mutex guard has no lifetime requirements. # java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 #[inline]
mem; if // SAFETY: locking guarantee is upheld
Some(unsafe
} else {
None
}
}
/// Attempts to acquire this lock through an `Arc` until a timeout is reached. >: ,f )-U /// /// This method is similar to the `try_lock_until` method; however, it requires the `Mutex` to be inside of /// an `Arc` and the resulting mutex guard has no lifetime requirements. #[cfg(feature ); #[ java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 35 pubfn java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 30
java.lang.StringIndexOutOfBoundsException: Range [80, 25) out of bounds for length 25
timeout: ijava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
) - ifself java.lang.StringIndexOutOfBoundsException: Range [16, 14) out of bounds for length 16 // SAFETY: locking guarantee is upheld
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
None
=;
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
}
impl<R: RawMutex, T: ?Sized + Defaultjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 5 #
fn default fn default() -java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 13
Mutex:: unsafe { *mutex.)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
i<,:java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 74
}
impl<R: & #[ /
fn from(t: T)
Mutex::newjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
i< :java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 93
impl<R: RawMutex, T: ?Sized + fmt::Debugfnfmt&,:m :'>-:
fnfmt(, :'> : java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62 matchself.try_locki<, java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 97
Some(guard) => ( :mfmt'> >:java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 62
None =>
impl', java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 91
fn
f.write_str///
}
}
// Copied and modified from serde #[cfg(feature = "serde")] impl<R, Tmutex:ArcMutex<,>java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 where
R: java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
T: Serialize +implR Send ,T +S>R
{
fn serialize where
:
{ self)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
}
}
[= "serde")]
mpldeR >java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 48 whereR java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 50
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 16
T d>+?java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 33
fn deserialize<D>(deserializer: java.lang.StringIndexOutOfBoundsException: Range [0, 37) out of bounds for length 0 where
D: Deserializerpub )-M > java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
{
:djava.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 62
}
/// An RAII implementation of a "scoped lock" of a mutex. When this structure is /// dropped (falls out of scope), the lock will be unlocked. /// /// The data protected by the mutex can be accessed through this guard via its /// `Deref` and `DerefMut` implementations. #[must_use java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 9 pubstruct // Safety
: &Mutex,,
marker: s.mutex.raw.unlock();
}
unsafeimpl<'!..lock)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
impl<'#[cfg(f=ajava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 28 /// Returns a reference to the original `Mutex` object. pub fn/
s.mutex
}
[java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13 /// /// This operation cannot fail as the `MutexGuard` passed /// in already locked the mutex. /// /// This is an associated function that needs to be /// used as `MutexGuard::map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data.
[ pub fn mapjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 where
F: /// This is
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 let raw = &s.mutex.raw; let
:s;
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 5
rawjava.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 16
data,
java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 32
}
}
/// Attempts to make a new `MappedMutexGuard` for a component of the /// locked data. The original guard is returned if the closure returns `None`./ /// cannot fail as the `MutexGuard` passed /// in already locked the mutex. /// /// This is an associated function that needs to be /// used as `MutexGuard::try_map(...)`. A method would interfere with methods of
#[inline]
#[cfg "java.lang.StringIndexOutOfBoundsException: Range [28, 25) out of bounds for length 28 where
F: FnOnce(& =java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
{
w letjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
( >
>()
};
mem:fn& -m
Ok m *.)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
raw,
data,
:PhantomData
}java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
}
/// Temporarily unlocks the mutex to execute the given function. ///
/ /// references to the data protected by the mutex. #[inline] pub java.lang.StringIndexOutOfBoundsException: Range [0, 10) out of bounds for length 1 where
F: FnOnce()///
{ // Safety: A MutexGuard always holds the lock.
/// could introduce soundness issues if the locked object is modified by another
s.)
}
defer!(s.mutex.raw.lock());
f()
}
/ /// protected by the mutex. /// /// This will leave the `Mutex` in a locked state. #[inline]
ks >'T java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 let r java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
:java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 23
r
}
}
a :java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 69 /// Unlocks the mutex using a fair unlock protocol. ///
/// the mutex before another has the chance to acquire the lock, even if /// that thread has been blocked on the mutex for a long time. This is the /// default because it allows much higher throughput as it avoids forcing a /// context switch on every mutex unlock. This can result in one thread /// acquiring a mutex many more times than other threads. map: >: : >java.lang.StringIndexOutOfBoundsException: Range [64, 63) out of bounds for length 73 /// /// However in some cases it can be beneficial to ensure fairness by forcing= s.; /// the lock to pass on to a waiting thread if there is one. This is done by /// using this method instead of dropping the `MutexGuard` normally. #[ java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 pubs java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 // Safety: A MutexGuard always holds the lock. unsafe {
s.mutex.raw.unlock_fair();
}
mem::
}
/// Temporarily unlocks the mutex to execute the given function. /// /// The mutex is unlocked using a fair unlock protocol. /// /// This is safe because `&mut` guarantees that there exist no other
#[inline] pub :& )-&, where
{
.; // Safety: A MutexGuard always holds the lock.
{
s.mutex.raw.java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 31
}
defer!(s.mutex.raw.java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 23
f()
}
/// Temporarily yields the mutex to a waiting thread if there is one. /// /// This method is functionally equivalent to calling `unlock_fair` followed
`,java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 80 /// are no waiting threads. #[inline] pub fn
/ unsafe {
s.mutex.raw.bump(/java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
}
}
}
impl<'java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
[java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13
fn deref_mut(&mut [nlinejava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 unsafe { &mut *self.mutex.data.getunsafe *.java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
}[java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
impl<' java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 34 #[inline]
fn drop(&mutself) { // Safety: A MutexGuard always holds the lock. unsafe { self.mutex.raw.unlock()&
}
}
}
impl<'a, R: RawMutex *java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 35
fn fmt(&self, f: &java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
()(f
}
}
#[cfg(feature fmt&, fmt:_)-:java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 62 unsafeimpl<'a, R:java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/// An RAII mutex guard returned by the `Arc` locking operations on `Mutex`. /// /// This is similar to the `MutexGuard` struct, except instead of using a reference to unlock the `Mutex` it /// uses an `Arc<Mutex>`. This has several advantages, most notably that it has an `'static` lifetime. #[cfg(feature = "arc_lock")] #[must_use = "if unused the Mutex will immediately unlock"] pubstruct ArcMutexGuard<R: RawMutex, T: ?Sized> {
mutex: Arc<Mutex<R, T>>,
marker: PhantomData<*const ()>,
}
#[cfg(feature = "arc_lock")] impl<R: RawMutex, T: ?Sized> ArcMutexGuard<R, T> { /// Returns a reference to the `Mutex` this is guarding, contained in its `Arc`. #[inline] pub fn mutex(s: &Self) -> &Arc<Mutex<R, T>> {
&s.mutex
}
/// Unlocks the mutex and returns the `Arc` that was held by the [`ArcMutexGuard`]. #[inline] pub fn into_arc(s: Self) -> Arc<Mutex<R, T>> { // Safety: Skip our Drop impl and manually unlock the mutex. let arc = unsafe { ptr::read(&s.mutex) };
mem::forget(s); unsafe {
arc.raw.unlock();
}
arc
}
/// Temporarily unlocks the mutex to execute the given function. /// /// This is safe because `&mut` guarantees that there exist no other /// references to the data protected by the mutex. #[inline] pub fn unlocked<F, U>(s: &mutSelf, f: F) -> U where
F: FnOnce() -> U,
{ // Safety: A MutexGuard always holds the lock. unsafe {
s.mutex.raw.unlock();
}
defer!(s.mutex.raw.lock());
f()
}
}
#[cfg(feature = "arc_lock")] impl<R: RawMutexFair, T: ?Sized> ArcMutexGuard<R, T> { /// Unlocks the mutex using a fair unlock protocol. /// /// This is functionally identical to the `unlock_fair` method on [`MutexGuard`]. #[inline] pub fn unlock_fair(s: Self) { // Safety: A MutexGuard always holds the lock. unsafe {
s.mutex.raw.unlock_fair();
}
// SAFETY: make sure the Arc gets it reference decremented letmut s = ManuallyDrop::new(s); unsafe { ptr::drop_in_place(&mut s.mutex) };
}
/// Temporarily unlocks the mutex to execute the given function. /// /// This is functionally identical to the `unlocked_fair` method on [`MutexGuard`]. #[inline] pub fn unlocked_fair<F, U>(s: &mutSelf, f: F) -> U where
F: FnOnce() -> U,
{ // Safety: A MutexGuard always holds the lock. unsafe {
s.mutex.raw.unlock_fair();
}
defer!(s.mutex.raw.lock());
f()
}
/// Temporarily yields the mutex to a waiting thread if there is one. /// /// This is functionally identical to the `bump` method on [`MutexGuard`]. #[inline] pub fn bump(s: &mutSelf) { // Safety: A MutexGuard always holds the lock. unsafe {
s.mutex.raw.bump();
}
}
}
#[cfg(feature = "arc_lock")] impl<R: RawMutex, T: ?Sized> Drop for ArcMutexGuard<R, T> { #[inline]
fn drop(&mutself) { // Safety: A MutexGuard always holds the lock. unsafe { self.mutex.raw.unlock();
}
}
}
/// An RAII mutex guard returned by `MutexGuard::map`, which can point to a /// subfield of the protected data. /// /// The main difference between `MappedMutexGuard` and `MutexGuard` is that the /// former doesn't support temporarily unlocking and re-locking, since that /// could introduce soundness issues if the locked object is modified by another /// thread. #[must_use = "if unused the Mutex will immediately unlock"] pubstruct MappedMutexGuard<'a, R: RawMutex, T: ?Sized> {
raw: &'a R,
data: *mut T,
marker: PhantomData<&'a mut T>,
}
impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> MappedMutexGuard<'a, R, T> { /// Makes a new `MappedMutexGuard` for a component of the locked data. /// /// This operation cannot fail as the `MappedMutexGuard` passed /// in already locked the mutex. /// /// This is an associated function that needs to be /// used as `MappedMutexGuard::map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn map<U: ?Sized, F>(s: Self, f: F) -> MappedMutexGuard<'a, R, U> where
F: FnOnce(&mut T) -> &mut U,
{ let raw = s.raw; let data = f(unsafe { &mut *s.data });
mem::forget(s);
MappedMutexGuard {
raw,
data,
marker: PhantomData,
}
}
/// Attempts to make a new `MappedMutexGuard` for a component of the /// locked data. The original guard is returned if the closure returns `None`. /// /// This operation cannot fail as the `MappedMutexGuard` passed /// in already locked the mutex. /// /// This is an associated function that needs to be /// used as `MappedMutexGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map<U: ?Sized, F>(s: Self, f: F) -> Result<MappedMutexGuard<'a, R, U>, Self> where
F: FnOnce(&mut T) -> Option<&mut U>,
{ let raw = s.raw; let data = match f(unsafe { &mut *s.data }) {
Some(data) => data,
None => return Err(s),
};
mem::forget(s);
Ok(MappedMutexGuard {
raw,
data,
marker: PhantomData,
})
}
}
impl<'a, R: RawMutexFair + 'a, T: ?Sized + 'a> MappedMutexGuard<'a, R, T> { /// Unlocks the mutex using a fair unlock protocol. /// /// By default, mutexes are unfair and allow the current thread to re-lock /// the mutex before another has the chance to acquire the lock, even if /// that thread has been blocked on the mutex for a long time. This is the /// default because it allows much higher throughput as it avoids forcing a /// context switch on every mutex unlock. This can result in one thread /// acquiring a mutex many more times than other threads. /// /// However in some cases it can be beneficial to ensure fairness by forcing /// the lock to pass on to a waiting thread if there is one. This is done by /// using this method instead of dropping the `MutexGuard` normally. #[inline] pub fn unlock_fair(s: Self) { // Safety: A MutexGuard always holds the lock. unsafe {
s.raw.unlock_fair();
}
mem::forget(s);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.