This is Unofficial EPICS BASE Doxygen Site
timerQueueActiveMgr.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE Versions 3.13.7
7 * and higher are distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 /*
11  * Author Jeffrey O. Hill
12  * johill@lanl.gov
13  * 505 665 1831
14  */
15 
16 #include <limits.h>
17 
18 #include "epicsGuard.h"
19 #include "timerPrivate.h"
20 
22  :mutex(__FILE__, __LINE__)
23 {
24 }
25 
27 {
28  epicsGuard < epicsMutex > locker ( this->mutex );
29 }
30 
32  allocate ( RefThis & refThis, bool okToShare, unsigned threadPriority )
33 {
34  epicsGuard < epicsMutex > locker ( this->mutex );
35  if ( okToShare ) {
36  tsDLIter < epicsTimerQueueActiveForC > iter = this->sharedQueueList.firstIter ();
37  while ( iter.valid () ) {
38  if ( iter->threadPriority () == threadPriority ) {
39  assert ( iter->timerQueueActiveMgrPrivate::referenceCount < UINT_MAX );
40  iter->timerQueueActiveMgrPrivate::referenceCount++;
41  return *iter;
42  }
43  iter++;
44  }
45  }
46 
48  * new epicsTimerQueueActiveForC ( refThis, okToShare, threadPriority );
49  queue.timerQueueActiveMgrPrivate::referenceCount = 1u;
50  if ( okToShare ) {
51  this->sharedQueueList.add ( queue );
52  }
53  return queue;
54 }
55 
58 {
59  {
60  epicsGuard < epicsMutex > locker ( this->mutex );
61  assert ( queue.timerQueueActiveMgrPrivate::referenceCount > 0u );
62  queue.timerQueueActiveMgrPrivate::referenceCount--;
63  if ( queue.timerQueueActiveMgrPrivate::referenceCount > 0u ) {
64  return;
65  }
66  else if ( queue.sharingOK () ) {
67  this->sharedQueueList.remove ( queue );
68  }
69  }
70  // delete only after we release the guard in case the embedded
71  // reference is the last one and this object is destroyed
72  // as a side effect
73  timerQueueActiveMgrPrivate * pPriv = & queue;
74  delete pPriv;
75 }
76 
78  referenceCount ( 0u )
79 {
80 }
81 
83 {
84 }
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
void add(T &item)
Definition: tsDLList.h:313
tsDLIterConst< T > firstIter() const
Definition: tsDLList.h:459
unsigned threadPriority() const
Definition: timerPrivate.h:233
bool valid() const
Definition: tsDLList.h:607
epicsMutex mutex
Definition: pvAccess.cpp:71
epicsTimerQueueActiveForC & allocate(RefThis &, bool okToShare, unsigned threadPriority=epicsThreadPriorityMin+10)
void remove(T &item)
Definition: tsDLList.h:219
void release(epicsTimerQueueActiveForC &)
bool sharingOK() const
Definition: timerPrivate.h:228
epicsSingleton< timerQueueActiveMgr >::reference RefThis
Definition: timerPrivate.h:165