OpenImageIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | List of all members
spin_mutex Class Reference

#include <thread.h>

Classes

class  lock_guard
 

Public Member Functions

 spin_mutex (void)
 
 spin_mutex (const spin_mutex &)
 
const spin_mutexoperator= (const spin_mutex &)
 
void lock ()
 
void unlock ()
 
bool try_lock ()
 

Detailed Description

A spin_mutex is semantically equivalent to a regular mutex, except for the following:

The bottom line is that mutex is the usual choice, but in cases where you need to acquire locks very frequently, but only need to hold the lock for a very short period of time, you may save runtime by using a spin_mutex, even though it's non-blocking.

N.B. A spin_mutex is only the size of an int. To avoid "false sharing", be careful not to put two spin_mutex objects on the same cache line (within 128 bytes of each other), or the two mutexes may effectively (and wastefully) lock against each other.

Constructor & Destructor Documentation

spin_mutex::spin_mutex ( void  )
inline

Default constructor – initialize to unlocked.

spin_mutex::spin_mutex ( const spin_mutex )
inline

Copy constructor – initialize to unlocked.

Member Function Documentation

void spin_mutex::lock ( )
inline

Acquire the lock, spin until we have it.

const spin_mutex& spin_mutex::operator= ( const spin_mutex )
inline

Assignment does not do anything, since lockedness should not transfer.

bool spin_mutex::try_lock ( )
inline

Try to acquire the lock. Return true if we have it, false if somebody else is holding the lock.

void spin_mutex::unlock ( )
inline

Release the lock that we hold.


The documentation for this class was generated from the following file: