Struct sgx_tstd::sync::SgxMutex[][src]

pub struct SgxMutex<T: ?Sized> { /* fields omitted */ }

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.

Poisoning

The mutexes in this module implement a strategy called "poisoning" where a mutex is considered poisoned whenever a thread panics while holding the mutex. Once a mutex is poisoned, all other threads are unable to access the data by default as it is likely tainted (some invariant is not being upheld).

For a mutex, this means that the lock and try_lock methods return a Result which indicates whether a mutex has been poisoned or not. Most usage of a mutex will simply unwrap() these results, propagating panics among threads to ensure that a possibly invalid invariant is not witnessed.

A poisoned mutex, however, does not prevent all access to the underlying data. The PoisonError type has an into_inner method which will return the guard that would have otherwise been returned on a successful lock. This allows access to the data, despite the lock being poisoned.

Methods

impl<T> SgxMutex<T>
[src]

Creates a new mutex in an unlocked state ready for use.

impl<T: ?Sized> SgxMutex<T>
[src]

The function locks a trusted mutex object within an enclave.

Acquires a mutex, blocking the current thread until it is able to do so.

This function will block the local thread until it is available to acquire the mutex. Upon returning, the thread is the only thread with the lock 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.

The exact behavior on locking a mutex in the thread which already holds the lock is left unspecified. However, this function will not return on the second call (it might panic or deadlock, for example).

Errors

If another user of this mutex panicked while holding the mutex, then this call will return an error once the mutex is acquired.

Panics

This function might panic when called if the lock is already held by the current thread.

The function tries to lock a trusted mutex object within an enclave.

Attempts to acquire this lock.

If the lock could not be acquired at this time, then Err is returned. Otherwise, an RAII guard is returned. The lock will be unlocked when the guard is dropped.

This function does not block.

Errors

If another user of this mutex panicked while holding the mutex, then this call will return failure if the mutex would otherwise be acquired.

Determines whether the mutex is poisoned.

If another thread is active, the mutex can still become poisoned at any time. You should not trust a false value for program correctness without additional synchronization.

Consumes this mutex, returning the underlying data.

Errors

If another user of this mutex panicked while holding the mutex, then this call will return an error instead.

Returns a mutable reference to the underlying data.

Since this call borrows the Mutex mutably, no actual locking needs to take place---the mutable borrow statically guarantees no locks exist.

Errors

If another user of this mutex panicked while holding the mutex, then this call will return an error instead.

Trait Implementations

impl<T: ?Sized + Send> Send for SgxMutex<T>
[src]

impl<T: ?Sized + Send> Sync for SgxMutex<T>
[src]

impl<T: ?Sized> UnwindSafe for SgxMutex<T>
[src]

impl<T: ?Sized> RefUnwindSafe for SgxMutex<T>
[src]

impl<T: ?Sized> Drop for SgxMutex<T>
[src]

Executes the destructor for this type. Read more

impl<T> From<T> for SgxMutex<T>
[src]

Creates a new mutex in an unlocked state ready for use. This is equivalent to Mutex::new.

impl<T: ?Sized + Default> Default for SgxMutex<T>
[src]

Creates a SgxMutex<T>, with the Default value for T.

impl<T: ?Sized + Debug> Debug for SgxMutex<T>
[src]

Formats the value using the given formatter. Read more