ScopedLockPair Class Reference

#include <spinlock.h>

Detailed Description

A ScopedLockPair acquires locks to two specified mutexes upon creation and releases them upon destruction (usually at the end of a code block). You should use this instead of two ScopedLock objects to avoid deadlocks: With two separate ScopedLock objects one thread could lock A and then try to lock B, while another thread could lock B and then try to lock A, resulting in a deadlock. ScopedLockPair avoids this by always locking the mutex with lower memory address at first.

See also
SpinLock
ScopedLock

Public Member Functions

 ScopedLockPair (Spinlock &lock1, Spinlock &lock2)
 
 ScopedLockPair (ScopedLockPair &&src)
 
 ~ScopedLockPair ()
 

Private Member Functions

 MAXON_DISALLOW_COPY_AND_ASSIGN (ScopedLockPair)
 

Private Attributes

Spinlock_lock1
 
Spinlock_lock2
 

Constructor & Destructor Documentation

◆ ScopedLockPair() [1/2]

ScopedLockPair ( Spinlock lock1,
Spinlock lock2 
)

◆ ScopedLockPair() [2/2]

◆ ~ScopedLockPair()

Member Function Documentation

◆ MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( ScopedLockPair  )
private

Member Data Documentation

◆ _lock1

Spinlock* _lock1
private

◆ _lock2

Spinlock* _lock2
private