Skip to main content

lock_device

Function lock_device 

Source
pub fn lock_device<T>(
    device: &Mutex<T>,
) -> Result<MutexGuard<'_, T>, BackendError>
Expand description

Lock the handle of a device that is not Sync.

Backend is Send + Sync, and a hardware handle (a PC/SC card, a PKCS#11 session) is not, so a hardware backend keeps it behind a Mutex. The lock is poisoned when an operation panics while holding it, which leaves the device in an unknown state; the backend then refuses further use rather than carry that state into the next step.

ยงErrors

Returns BackendError::DeviceStateUnknown if the lock is poisoned.