264 |
} |
} |
265 |
|
|
266 |
/** |
/** |
267 |
|
* Prefix decrement operator, for reducing NonVolatileReader's |
268 |
|
* read position by one. |
269 |
|
*/ |
270 |
|
inline void operator--() { |
271 |
|
if (read_ptr == atomic_read(&pBuf->read_ptr)) return; //TODO: or should we react oh this case (e.g. force segfault), as this is a very odd case? |
272 |
|
--read_ptr & pBuf->size_mask; |
273 |
|
} |
274 |
|
|
275 |
|
/** |
276 |
|
* Postfix decrement operator, for reducing NonVolatileReader's |
277 |
|
* read position by one. |
278 |
|
*/ |
279 |
|
inline void operator--(int) { |
280 |
|
--*this; |
281 |
|
} |
282 |
|
|
283 |
|
/** |
284 |
|
* Returns pointer to the RingBuffer data of current |
285 |
|
* NonVolatileReader's read position and increments |
286 |
|
* NonVolatileReader's read position by one. |
287 |
|
* |
288 |
|
* @returns pointer to element of current read position |
289 |
|
*/ |
290 |
|
T* pop() { |
291 |
|
if (!read_space()) return NULL; |
292 |
|
T* pData = &pBuf->buf[read_ptr]; |
293 |
|
read_ptr++; |
294 |
|
read_ptr &= pBuf->size_mask; |
295 |
|
return pData; |
296 |
|
} |
297 |
|
|
298 |
|
/** |
299 |
* Reads one element from the NonVolatileReader's current read |
* Reads one element from the NonVolatileReader's current read |
300 |
* position and copies it to the variable pointed by \a dst and |
* position and copies it to the variable pointed by \a dst and |
301 |
* finally increments the NonVolatileReader's read position by |
* finally increments the NonVolatileReader's read position by |
350 |
this->read_ptr = priv_read_ptr; |
this->read_ptr = priv_read_ptr; |
351 |
return to_read; |
return to_read; |
352 |
} |
} |
353 |
|
|
354 |
|
/** |
355 |
|
* Finally when the read data is not needed anymore, this method |
356 |
|
* should be called to free the data in the RingBuffer up to the |
357 |
|
* current read position of this NonVolatileReader. |
358 |
|
* |
359 |
|
* @see RingBuffer::increment_read_ptr() |
360 |
|
*/ |
361 |
|
void free() { |
362 |
|
atomic_set(&pBuf->read_ptr, read_ptr); |
363 |
|
} |
364 |
|
|
365 |
protected: |
protected: |
366 |
_NonVolatileReader(RingBuffer<_T>* pBuf) { |
_NonVolatileReader(RingBuffer<_T>* pBuf) { |
367 |
this->pBuf = pBuf; |
this->pBuf = pBuf; |