101 useconds_t pushSleepUsecs = 1000)
102 : _length(0), _maxLength(maxLength),
103 _pushSleepUsecs(pushSleepUsecs)
105 _front = _back =
new Entry(T());
106 _pushingLocked = _poppingLocked =
false;
114 while (_front !=
nullptr) {
128 while (_poppingLocked.exchange(
true));
129 if (_front->next !=
nullptr) {
131 Entry *oldFirst = _front;
132 _front = _front->next;
133 result = _front->value;
134 _poppingLocked =
false;
141 _poppingLocked =
false;
148 bool PopFront(std::vector<T> & result)
150 typename std::vector<T>::size_type numEntries = 0;
152 while (_poppingLocked.exchange(
true));
153 if (_front->next !=
nullptr) {
155 Entry *oldFront = _front;
159 while (_front->next !=
nullptr) {
160 _front = _front->next;
163 _length -= numEntries;
167 Entry *newFront = _front;
169 _poppingLocked =
false;
171 result.resize(numEntries);
173 typename std::vector<T>::size_type i = 0;
174 Entry *entry = oldFront->next;
175 while (entry != newFront) {
176 Entry *delEntry = entry;
177 result[i] = entry->value;
186 _poppingLocked =
false;
196 while (_length > _maxLength) { usleep(_pushSleepUsecs); };
197 Entry *tmp =
new Entry(t);
198 while (_pushingLocked.exchange(
true));
201 _pushingLocked =
false;
209 bool PushBack(
const std::vector<T> & t)
211 while (_length > _maxLength) { usleep(_pushSleepUsecs); }
212 std::vector<Entry *> newEntries(t.size());
213 typename std::vector<T>::size_type i = 0;
214 newEntries[i] =
new Entry(t[i]);
216 for (; i < t.size(); ++i) {
217 newEntries[i] =
new Entry(t[i]);
218 newEntries[i-1]->next = newEntries[i];
220 while (_pushingLocked.exchange(
true));
221 _back->next = newEntries[0];
222 _back = newEntries[t.size() - 1];
223 _pushingLocked =
false;
236 : value(val), next(nullptr)
239 std::atomic<Entry *> next;
243 std::atomic<bool> _poppingLocked;
245 std::atomic<bool> _pushingLocked;
246 std::atomic<uint64_t> _length;
248 useconds_t _pushSleepUsecs;
bool PushBack(const T &t)
Waits for the queue to not be full (see the Queue constructor), then pushes t onto the back of the qu...
Definition DwmConcurrentQueue.hh:194