This is Unofficial EPICS BASE Doxygen Site
epics::pvAccess::ReferenceCountingLock Class Reference

#include "referenceCountingLock.h"

Public Member Functions

 POINTER_DEFINITIONS (ReferenceCountingLock)
 
 ReferenceCountingLock ()
 
virtual ~ReferenceCountingLock ()
 
bool acquire (epics::pvData::int64 msecs)
 
void release ()
 
int increment ()
 
int decrement ()
 

Detailed Description

Reference counting mutex implementation w/ deadlock detection. Synchronization helper class used (intended for use) for activation/deactivation synchronization. This class enforces attempt method of acquiring the locks to prevent deadlocks. Class also offers reference counting. (NOTE: automatic lock counting was not implemented due to imperfect usage.)

Definition at line 35 of file referenceCountingLock.h.

Constructor & Destructor Documentation

epics::pvAccess::ReferenceCountingLock::ReferenceCountingLock ( )

Constructor of ReferenceCountingLock. After construction lock is free and reference count equals 1.

Definition at line 15 of file referenceCountingLock.cpp.

15  : _references(1)
16 {
17  /* pthread_mutexattr_t mutexAttribute;
18  int32 retval = pthread_mutexattr_init(&mutexAttribute);
19  if(retval != 0)
20  {
21  //string errMsg = "Error: pthread_mutexattr_init failed: " + string(strerror(retval));
22  assert(false);
23  }
24  retval = pthread_mutexattr_settype(&mutexAttribute, PTHREAD_MUTEX_RECURSIVE);
25  if(retval == 0)
26  {
27  retval = pthread_mutex_init(_mutex, &mutexAttribute);
28  if(retval != 0)
29  {
30  //string errMsg = "Error: pthread_mutex_init failed: " + string(strerror(retval));
31  assert(false);
32  }
33  }
34  else
35  {
36  //string errMsg = "Error: pthread_mutexattr_settype failed: " + string(strerror(retval));
37  assert(false);
38  }
39 
40  pthread_mutexattr_destroy(&mutexAttribute);*/
41 }
epics::pvAccess::ReferenceCountingLock::~ReferenceCountingLock ( )
virtual

Destructor of ReferenceCountingLock.

Definition at line 43 of file referenceCountingLock.cpp.

44 {
45 // pthread_mutex_destroy(_mutex);
46 }

Member Function Documentation

bool epics::pvAccess::ReferenceCountingLock::acquire ( epics::pvData::int64  msecs)

Attempt to acquire lock.

NOTE: Argument msecs is currently not supported due to Darwin OS not supporting pthread_mutex_timedlock. May be changed in the future.

Parameters
msecsthe number of milleseconds to wait. An argument less than or equal to zero means not to wait at all.
Returns
true if acquired, false otherwise. NOTE: currently this routine always returns true. Look above for explanation.

Definition at line 48 of file referenceCountingLock.cpp.

49 {
50  _mutex.lock();
51  return true;
52  /* struct timespec deltatime;
53  if(msecs > 0)
54  {
55  deltatime.tv_sec = msecs / 1000;
56  deltatime.tv_nsec = (msecs % 1000) * 1000;
57  }
58  else
59  {
60  deltatime.tv_sec = 0;
61  deltatime.tv_nsec = 0;
62  }
63 
64  int32 retval = pthread_mutex_timedlock(_mutex, &deltatime);
65  if(retval == 0)
66  {
67  return true;
68  }
69  return false;
70  */
71 }
int epics::pvAccess::ReferenceCountingLock::decrement ( )

Decrement number of references.

Returns
number of references.

Definition at line 92 of file referenceCountingLock.cpp.

93 {
94  Lock guard(_countMutex);
95  --_references;
96  return _references;
97 }
A lock for multithreading.
Definition: lock.h:36
int epics::pvAccess::ReferenceCountingLock::increment ( )

Increment number of references.

Returns
number of references.

Definition at line 85 of file referenceCountingLock.cpp.

86 {
87  Lock guard(_countMutex);
88  ++_references;
89  return _references;
90 }
A lock for multithreading.
Definition: lock.h:36
epics::pvAccess::ReferenceCountingLock::POINTER_DEFINITIONS ( ReferenceCountingLock  )
void epics::pvAccess::ReferenceCountingLock::release ( )

Release previously acquired lock.

Definition at line 73 of file referenceCountingLock.cpp.

74 {
75  _mutex.unlock();
76  /* int retval = pthread_mutex_unlock(_mutex);
77  if(retval != 0)
78  {
79  //string errMsg = "Error: pthread_mutex_unlock failed: " + string(strerror(retval));
80  //TODO do something?
81  }*/
82 }

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