This is Unofficial EPICS BASE Doxygen Site
referenceCountingLock.cpp
Go to the documentation of this file.
1 
7 #define epicsExportSharedSymbols
9 
10 namespace epics {
11 namespace pvAccess {
12 
13 using namespace epics::pvData;
14 
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 }
42 
44 {
45 // pthread_mutex_destroy(_mutex);
46 }
47 
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 }
72 
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 }
83 
84 // TODO use atomic primitive impl.
86 {
87  Lock guard(_countMutex);
88  ++_references;
89  return _references;
90 }
91 
93 {
94  Lock guard(_countMutex);
95  --_references;
96  return _references;
97 }
98 
99 }
100 }
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
A lock for multithreading.
Definition: lock.h:36
pvData
Definition: monitor.h:428
int64_t int64
Definition: pvType.h:87
bool acquire(epics::pvData::int64 msecs)