EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
ConcurrentList.h
1 #ifndef __CONCURRENTLIST_H__
2 #define __CONCURRENTLIST_H__
3 
4 // tools
5 #include "tools/Guard.h"
6 #include "tools/NoCopy.h"
7 
18 {
19 public:
22 
24  virtual ~ConcurrentPtrList();
25 
27  OrderedMutex &getMutex() { return mutex; }
28 
30  bool isEmpty(Guard &guard);
31 
33  size_t size(Guard &guard);
34 
41  void add(Guard &guard, void *item);
42 
47  bool removeIfFound(Guard &guard, void *item);
48 
53  void remove(Guard &guard, void *item);
54 
57 
58 private:
59  PROHIBIT_DEFAULT_COPY(ConcurrentPtrList);
60  OrderedMutex mutex;
61  class CPElement *list;
62 };
63 
69 {
70 public:
75  ConcurrentPtrList *list,
76  class CPElement *element);
77 
80 
83 
86 
88  OrderedMutex &getMutex() { return list->getMutex(); }
89 
91  void *next(Guard &guard);
92 private:
93  ConcurrentPtrList *list;
94  class CPElement *next_element;
95  void *item;
96 
97  void getNext(Guard &guard);
98 };
99 
104 template<class T> class ConcurrentListIterator
105 {
106 public:
107 
110 
112  ConcurrentListIterator(const ConcurrentListIterator &rhs) : iter(rhs.iter) { }
113 
116  {
117  iter = rhs.iter;
118  return *this;
119  }
120 
122  T *next()
123  {
124  Guard guard(__FILE__, __LINE__, iter.getMutex());
125  return (T *) iter.next(guard);
126  }
127 private:
129 };
130 
135 template<class T> class ConcurrentList
136  : public Guardable, private ConcurrentPtrList
137 {
138 public:
141  {}
142 
145  {
147  }
148 
150  bool isEmpty()
151  {
152  Guard guard(__FILE__, __LINE__, ConcurrentPtrList::getMutex());
153  return ConcurrentPtrList::isEmpty(guard);
154  }
155 
157  size_t size()
158  {
159  Guard guard(__FILE__, __LINE__, ConcurrentPtrList::getMutex());
160  return ConcurrentPtrList::size(guard);
161  }
162 
164  void add(T *item)
165  {
166  Guard guard(__FILE__, __LINE__, ConcurrentPtrList::getMutex());
167  ConcurrentPtrList::add(guard, item);
168  }
169 
171  bool removeIfFound(void *item)
172  {
173  Guard guard(__FILE__, __LINE__, ConcurrentPtrList::getMutex());
174  return ConcurrentPtrList::removeIfFound(guard, item);
175  }
176 
178  void remove(T *item)
179  {
180  Guard guard(__FILE__, __LINE__, ConcurrentPtrList::getMutex());
181  ConcurrentPtrList::remove(guard, item);
182  }
183 
186  {
187  Guard guard(__FILE__, __LINE__, ConcurrentPtrList::getMutex());
189  }
190 private:
191  PROHIBIT_DEFAULT_COPY(ConcurrentList);
192 };
193 
194 #endif
ConcurrentListIterator(ConcurrentPtrListIterator iter)
Constructor.
Definition: ConcurrentList.h:109
A mutex with informational name and lock order.
Definition: OrderedMutex.h:34
class ConcurrentPtrListIterator iterator(Guard &guard)
Obtain iterator, positioned at the start of the list.
size_t size()
Definition: ConcurrentList.h:157
Iterator for ConcurrentPtrList.
Definition: ConcurrentList.h:68
OrderedMutex & getMutex()
Definition: ConcurrentList.h:27
bool removeIfFound(Guard &guard, void *item)
Remove an item from the list.
OrderedMutex & getMutex()
Definition: ConcurrentList.h:144
T * next()
Definition: ConcurrentList.h:122
ConcurrentList()
Constructor.
Definition: ConcurrentList.h:140
ConcurrentPtrList()
Construct a new list.
OrderedMutex & getMutex()
Definition: ConcurrentList.h:88
Automatically takes and releases an epicsMutex.
Definition: Guard.h:63
ConcurrentListIterator< T > iterator()
Definition: ConcurrentList.h:185
Type-save wrapper for ConcurrentPtrListIterator.
Definition: ConcurrentList.h:104
ConcurrentListIterator(const ConcurrentListIterator &rhs)
Copy constructor.
Definition: ConcurrentList.h:112
void add(Guard &guard, void *item)
Add an item to the list.
A List that allows concurrent access.
Definition: ConcurrentList.h:17
Interface for something that can be protected by a Guard.
Definition: Guard.h:49
ConcurrentPtrListIterator & operator=(const ConcurrentPtrListIterator &)
Copy operator.
ConcurrentListIterator & operator=(const ConcurrentListIterator &rhs)
Copy operator.
Definition: ConcurrentList.h:115
bool isEmpty()
Definition: ConcurrentList.h:150
Type-save wrapper for ConcurrentPtrList.
Definition: ConcurrentList.h:135
virtual ~ConcurrentPtrListIterator()
Destructor.
void remove(Guard &guard, void *item)
Remove an item from the list.
void * next(Guard &guard)
void add(T *item)
Definition: ConcurrentList.h:164
size_t size(Guard &guard)
virtual ~ConcurrentPtrList()
Delete list and all its elements.
ConcurrentPtrListIterator(Guard &guard, ConcurrentPtrList *list, class CPElement *element)
Constructor.
bool isEmpty(Guard &guard)
bool removeIfFound(void *item)
Definition: ConcurrentList.h:171