Expand description
§MobileCoin: Synchronization primitives for SGX enclaves
Synchronization primitives for SGX enclaves.
The available primitives are meant to mimic the behavior of std::sync. Only the primitives whose behavior can be supported in SGX enclaves are supported.
§Examples
To have code that works with both std::sync and mc-sgx-sync.
#[cfg(feature = "sgx")]
use mc_sgx_sync::Mutex;
#[cfg(not(feature = "sgx"))]
use std::sync::Mutex;
let mutex = Mutex::new(5);
{
let mut data = lock.lock().unwrap();
*data += 1;
assert_eq!(*data, 6);
} // lock is dropped here
§Developer Notes
The modules are implemented to mimic the layout of std::sync.
-
The modules that define the public API are more or less copies from the rust source at commit 606c3907 with unsupported behavior removed. This ensures that clients can jump back and forth between the std::sync types and the supported mc-sgx-sync types.
-
The
mc-sgx-sync::sys
modules mimic the modules in the rust source. Thesys
modules in the rust source are per operating system or platform. mc-sgx-sync only supports SGX enclaves, but maintaining thesys
layout reduces modifications to the public API modules. -
mc-sgx-tstdc provides rust wrappers around the C implementation of the synchronization primitives.
mc-sgx-sync could depend on
mc-sgx-tstdc-sys
and call the C implementation directly. This is how many of the sys
modules in
the rust source are implemented. The
choice to depend on
mc-sgx-tstdc was made to be
consistent with the use of other mc-sgx-<lib_wrapper>-sys
crates. The
mc-sgx-<lib_wrapper>
crates provides idiomatic rust interfaces over the C API
and are usually the only crates that directly depend on the
mc-sgx-<lib_wrapper>-sys
crates.
Structs§
- Condvar
- A Condition Variable
- Mutex
- A mutual exclusion primitive useful for protecting shared data
- Mutex
Guard - An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
- Poison
Error - A type of error which can be returned whenever a lock is acquired.
- RwLock
- A reader-writer lock
- RwLock
Read Guard - RAII structure used to release the shared read access of a lock when dropped.
- RwLock
Write Guard - RAII structure used to release the exclusive write access of a lock when dropped.
Enums§
- TryLock
Error - An enumeration of possible errors associated with a
TryLockResult
which can occur while trying to acquire a lock, from thetry_lock
method on aMutex
or thetry_read
andtry_write
methods on anRwLock
.
Type Aliases§
- Lock
Result - A type alias for the result of a lock method which can be poisoned.
- TryLock
Result - A type alias for the result of a nonblocking locking method.