This is Unofficial EPICS BASE Doxygen Site
epics::pvData::Lock Class Reference

A lock for multithreading. More...

#include "lock.h"

Public Member Functions

 Lock (Mutex &m)
 
 ~Lock ()
 
void lock ()
 
void unlock ()
 
bool tryLock ()
 
bool ownsLock () const
 

Detailed Description

A lock for multithreading.

This is based on item 14 of

  • Effective C++, Third Edition, Scott Meyers

Definition at line 36 of file lock.h.

Constructor & Destructor Documentation

epics::pvData::Lock::Lock ( Mutex m)
inlineexplicit

Constructor

Parameters
mThe mutex for the facility being locked.

Definition at line 43 of file lock.h.

44  : mutexPtr(m), locked(true)
45  { mutexPtr.lock();}
epics::pvData::Lock::~Lock ( )
inline

Destructor Note that destructor does an automatic unlock.

Definition at line 50 of file lock.h.

50 {unlock();}
void unlock()
Definition: lock.h:66

Member Function Documentation

void epics::pvData::Lock::lock ( )
inline

Take the lock Recursive locks are supported but each lock must be matched with an unlock.

Definition at line 55 of file lock.h.

56  {
57  if(!locked)
58  {
59  mutexPtr.lock();
60  locked = true;
61  }
62  }
bool epics::pvData::Lock::ownsLock ( ) const
inline

See if caller has the lock,

Returns
(false,true) if caller (does not have, has) the lock.

Definition at line 91 of file lock.h.

91 {return locked;}
bool epics::pvData::Lock::tryLock ( )
inline

If lock is not held take the lock.

Returns
(false,true) if caller (does not have, has) the lock.

Definition at line 78 of file lock.h.

79  {
80  if(locked) return true;
81  if(mutexPtr.tryLock()) {
82  locked = true;
83  return true;
84  }
85  return false;
86  }
void epics::pvData::Lock::unlock ( )
inline

release the lock.

Definition at line 66 of file lock.h.

67  {
68  if(locked)
69  {
70  mutexPtr.unlock();
71  locked=false;
72  }
73  }

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