OSDN Git Service

[COMMON][FIFO_BASE] Fix FIFO_BASE::UNLOCKED_FIFO::left() .
[csp-qt/common_source_project-fm7.git] / source / src / fifo_templates.h
1 /*
2  * Templates of FIFO and RING-BUFFER.
3  * (C) 2022-07-16 K.Ohta <whatisthis.sowhat@gmail.com>
4  * LICENSE: GPLv2
5  *
6  * Description:
7  *  This presents reference FIFO and RING-BUFFER,
8  *  both
9  *    unmutexed (faster; using from same thread)
10  *  and
11  *    mutexed (slower;  using from another threads, i.e: mailbox)
12  *  This aims to be skelton of FIFO:: class and RINGBUFFER:: class.
13
14  * ToDo:
15  *  * Will support alignment for inrernal buffer.
16  */
17
18 #pragma once
19
20 //#include "fileio.h"
21 #include <mutex>
22 #include <limits.h>
23 #include "./common.h"
24
25
26 namespace FIFO_BASE {
27         template <class T >
28         class UNLOCKED_FIFO {
29         protected:
30                 T* m_buf;
31                 unsigned int m_bufSize;
32                 unsigned int m_rptr;
33                 unsigned int m_wptr;
34                 int m_low_warning;
35                 int m_high_warning;
36                 int m_dataCount;
37         public:
38                 UNLOCKED_FIFO(int _size) :
39                         m_rptr(0), m_wptr(0), m_dataCount(0),
40                         m_high_warning(INT_MAX - 1), m_low_warning(INT_MIN + 1)
41                 {
42                         bool is_legal = true;
43                         m_buf = nullptr;
44                         if((_size <= 0) || (_size == INT_MAX)) {
45                                 is_legal = false;
46                         } else {
47                                 m_bufSize = _size;
48                                 try {
49                                         m_buf = new T[_size];
50                                 } catch (std::bad_alloc& e) {
51                                         m_buf = nullptr;
52                                         m_bufSize = 0;
53                                         is_legal = false;
54                                 }
55                         }
56                         if(!(is_legal)) {
57                                 m_buf = nullptr;
58                                 m_high_warning = INT_MIN;
59                                 m_low_warning = INT_MAX;
60                                 m_bufSize = 0;
61                         }
62                 }
63                 ~UNLOCKED_FIFO()
64                 {
65                         release();
66                 }
67                 //!< Read one data
68                 virtual void initialize()
69                 {
70                 }
71                 virtual void release()
72                 {
73                         if(m_buf != nullptr) {
74                                 delete[] m_buf;
75                                 m_buf = nullptr;
76                         }
77                 }
78                 virtual void clear()
79                 {
80                         m_rptr = 0;
81                         m_wptr = 0;
82                         m_dataCount = 0;
83                         __UNLIKELY_IF((m_buf == nullptr) || (m_bufSize == 0)) {
84                                 return;
85                         }
86                         for(int i = 0; i < m_bufSize; i++) {
87                                 m_buf[i] = (T)0;
88                         }
89                 }
90
91                 virtual T read(bool& success)
92                 {
93                         __UNLIKELY_IF((m_buf == nullptr) || (m_dataCount < 1)
94                                                   || (m_bufSize == 0)) {
95                                 success = false;
96                                 return (T)0;
97                         }
98                         T tmpval;
99                         tmpval = m_buf[m_rptr++];
100                         __UNLIKELY_IF(m_rptr >= m_bufSize) {
101                                 m_rptr = 0;
102                         }
103                         m_dataCount--;
104                         __UNLIKELY_IF(m_dataCount < 0) {
105                                 m_dataCount = 0;
106                         }
107                         success = true;
108                         return tmpval;
109                 }
110                 virtual T read(void)
111                 {
112                         bool dummy;
113                         return read(dummy);
114                 }
115
116                 virtual T read_not_remove(int offset, bool& success)
117                 {
118                         __UNLIKELY_IF((m_buf == nullptr) ||
119                                                   (m_bufSize == 0) || (offset < 0)) {
120                                 success = false;
121                                 return (T)0;
122                         }
123                         T tmpval;
124                         unsigned int real_offset = offset + m_rptr;
125                         if(real_offset >= m_bufSize) {
126                                 real_offset = real_offset % m_bufSize;
127                         }
128                         tmpval = m_buf[real_offset];
129                         success = true;
130                         return tmpval;
131                 }
132                 virtual T read_not_remove(int offset)
133                 {
134                         bool dummy;
135                         return read_not_remove(offset, dummy);
136                 }
137
138                 virtual int read_to_buffer(T* dst, int _count, bool& success)
139                 {
140                         __UNLIKELY_IF((dst == nullptr) || (m_buf == nullptr) || (m_bufSize == 0)) {
141                                 success = false;
142                                 return 0;
143                         }
144                         if(_count > m_dataCount) {
145                                 _count = m_dataCount;
146                         }
147                         if(_count > (int)m_bufSize) {
148                                 _count = (int)m_bufSize;
149                         }
150                         __UNLIKELY_IF(_count <= 0) {
151                                 success = false;
152                                 return 0;
153                         }
154                         // OK, Transfer
155                         unsigned int xptr = m_rptr;
156                         if((xptr + (unsigned int)_count) >= m_bufSize) {
157                                 int count1 = (int)(m_bufSize - (xptr % m_bufSize));
158                                 int count2 = _count - count1;
159                                 int wp = 0;
160                                 for(int i = 0; i < count1; i++) {
161                                         dst[wp++] = m_buf[xptr++];
162                                 }
163                                 xptr = 0;
164                                 for(int i = 0; i < count2; i++) {
165                                         dst[wp++] = m_buf[xptr++];
166                                 }
167                         } else {
168                                 // Inside buffer
169                                 for(int i = 0; i < _count; i++) {
170                                         dst[i] = m_buf[xptr++];
171                                 }
172                         }
173                         m_rptr = xptr % m_bufSize;
174                         m_dataCount -= _count;
175                         __UNLIKELY_IF(m_dataCount < 0) {
176                                 m_dataCount = 0;
177                         }
178                         __UNLIKELY_IF(m_dataCount > (int)m_bufSize) {
179                                 m_dataCount = (int)m_bufSize;
180                         }
181                         __UNLIKELY_IF(m_rptr >= m_bufSize) {
182                                 m_rptr = m_rptr % m_bufSize;
183                         }
184                         success = true;
185                         return _count;
186                 }
187                 virtual bool write(T data)
188                 {
189                         __UNLIKELY_IF((m_buf == nullptr) || (m_dataCount >= (int)m_bufSize)
190                                                   || (m_bufSize == 0)) {
191                                 return false;
192                         }
193                         __UNLIKELY_IF(m_dataCount < 0) {
194                                 m_dataCount = 0; // OK?
195                         }
196                         m_buf[m_wptr++] = data;
197                         m_dataCount++;
198                         __UNLIKELY_IF(m_wptr >= m_bufSize) {
199                                 m_wptr = 0;
200                         }
201                         __UNLIKELY_IF(m_dataCount >= (int)m_bufSize) {
202                                 m_dataCount = (int)m_bufSize;
203                         }
204                         return true;
205                 }
206                 virtual bool write_not_push(int offset, T data)
207                 {
208                         __UNLIKELY_IF((m_buf == nullptr) ||
209                                                   (m_bufSize == 0) || (offset < 0)) {
210                                 return false;
211                         }
212                         unsigned int wp = m_wptr + offset;
213                         __UNLIKELY_IF(wp >= (int)m_bufSize) {
214                                 wp = wp % m_bufSize;
215                         }
216                         m_buf[wp] = data;
217                         return true;
218                 }
219                 virtual int write_from_buffer(T* src, int _count, bool& success)
220                 {
221                         __UNLIKELY_IF((src == nullptr) || (_count <= 0) ||
222                                                   (m_buf == nullptr) || (m_bufSize == 0) ||
223                                                   (m_dataCount >= (int)m_bufSize)) {
224                                 success = false;
225                                 return 0;
226                         }
227                         __UNLIKELY_IF(m_dataCount < 0) {
228                                 m_dataCount = 0; // OK?
229                         }
230                         __UNLIKELY_IF(_count > (int)m_bufSize) {
231                                 _count = (int)m_bufSize;
232                         }
233                         __UNLIKELY_IF((_count + m_dataCount) >= (int)m_bufSize) {
234                                 _count = (int)m_bufSize - m_dataCount;
235                                 if(_count <= 0) {
236                                         success = false;
237                                         return 0;
238                                 }
239                         }
240                         __UNLIKELY_IF(m_wptr >= m_bufSize) {
241                                 m_wptr = m_wptr % m_bufSize;
242                         }
243                         // OK, Transfer
244                         int xptr = m_wptr;
245                         if((xptr + (unsigned int)_count) > m_bufSize) {
246                                 int count1 = (int)(m_bufSize - (xptr % m_bufSize));
247                                 int count2 = _count - count1;
248                                 int rp = 0;
249                                 for(int i = 0; i < count1; i++) {
250                                         m_buf[xptr++] = src[rp++];
251                                 }
252                                 xptr = 0;
253                                 for(int i = 0; i < count2; i++) {
254                                         m_buf[xptr++] = src[rp++];
255                                 }
256                         } else {
257                                 // Inside buffer
258                                 for(int i = 0; i < _count; i++) {
259                                         m_buf[xptr++] = src[i];
260                                 }
261                         }
262                         m_wptr = xptr % m_bufSize;
263                         m_dataCount += _count;
264                         __UNLIKELY_IF(m_dataCount > (int)m_bufSize) {
265                                 m_dataCount = (int)m_bufSize;
266                         }
267                         success = true;
268                         return _count;
269                 }
270
271                 virtual bool available()
272                 {
273                         return ((m_buf != nullptr) && (m_bufSize > 0));
274                 }
275                 virtual bool empty()
276                 {
277                         bool f = available();
278                         return (!(f) || (m_dataCount <= 0));
279                 }
280                 virtual bool read_ready()
281                 {
282                         bool f = available();
283                         return ((f) && (m_dataCount > 0));
284                 }
285                 virtual bool write_ready()
286                 {
287                         bool f = available();
288                         return ((f) && (m_dataCount < (int)m_bufSize));
289                 }
290                 virtual bool full()
291                 {
292                         bool f = available();
293                         return (!(f) || (m_dataCount >= (int)m_bufSize));
294                 }
295
296                 virtual int count()
297                 {
298                         return (m_dataCount > 0) ? m_dataCount : 0;
299                 }
300
301                 virtual int fifo_size()
302                 {
303                         return (m_bufSize > 0) ? m_bufSize : 0;
304                 }
305
306                 virtual int left()
307                 {
308                         __UNLIKELY_IF((m_bufSize == 0) || (m_buf == nullptr)) {
309                                 return 0;
310                         }
311                         __UNLIKELY_IF(m_dataCount < 0) {
312                                 return (int)m_bufSize;
313                         }
314                         __UNLIKELY_IF(((unsigned int)m_dataCount) > m_bufSize) {
315                                 return 0;
316                         }
317                         return (int)(m_bufSize - (unsigned int)m_dataCount);
318                 }
319                 virtual void set_high_warn_value(int val = INT_MAX - 1)
320                 {
321                         m_high_warning = val;
322                 }
323                 virtual void set_low_warn_value(int val = INT_MIN + 1)
324                 {
325                         m_low_warning = val;
326                 }
327                 virtual bool high_warn()
328                 {
329                         return (m_high_warning < m_dataCount) ? true : false;
330                 }
331                 virtual bool low_warn()
332                 {
333                         return (m_low_warning > m_dataCount) ? true : false;
334                 }
335                 virtual bool resize(int _size, int _low_warn = INT_MIN + 1, int _high_warn = INT_MAX - 1)
336                 {
337                         __UNLIKELY_IF((_size <= 0) || (_size >= INT_MAX)) {
338                                 return false;
339                         }
340                         try {
341                                 T *tmpptr = new T[_size];
342                                 if(m_buf != nullptr) {
343                                         delete[] m_buf;
344                                 }
345                                 m_buf = tmpptr;
346                         } catch (std::bad_alloc& e) {
347                                 return false;
348                         }
349                         m_bufSize = (unsigned int)_size;
350                         m_low_warning = _low_warn;
351                         m_high_warning = _high_warn;
352                         return true;
353                 }
354         };
355
356         template <class T >
357         class LOCKED_FIFO : public UNLOCKED_FIFO<T> {
358         protected:
359                 std::recursive_mutex m_locker;
360         public:
361                 LOCKED_FIFO(int _size) :
362                 UNLOCKED_FIFO<T>(_size)
363                 {
364                 }
365                 ~LOCKED_FIFO()
366                 {
367                 }
368
369                 virtual void initialize()
370                 {
371                         std::lock_guard<std::recursive_mutex> locker(m_locker);
372                 }
373                 virtual void release()
374                 {
375                         std::lock_guard<std::recursive_mutex> locker(m_locker);
376                         UNLOCKED_FIFO<T>::release();
377                 }
378                 virtual void clear()
379                 {
380                         std::lock_guard<std::recursive_mutex> locker(m_locker);
381                         UNLOCKED_FIFO<T>::clear();
382                 }
383                 virtual T read(bool& success)
384                 {
385                         std::lock_guard<std::recursive_mutex> locker(m_locker);
386                         return UNLOCKED_FIFO<T>::read(success);
387                 }
388                 virtual T read(void)
389                 {
390                         bool success;
391                         std::lock_guard<std::recursive_mutex> locker(m_locker);
392                         return UNLOCKED_FIFO<T>::read(success);
393                 }
394
395                 virtual T read_not_remove(int offset, bool& success)
396                 {
397                         std::lock_guard<std::recursive_mutex> locker(m_locker);
398                         return UNLOCKED_FIFO<T>::read_not_remove(offset, success);
399                 }
400                 virtual T read_not_remove(int offset)
401                 {
402                         bool success;
403                         std::lock_guard<std::recursive_mutex> locker(m_locker);
404                         return UNLOCKED_FIFO<T>::read_not_remove(offset, success);
405                 }
406                 virtual int read_to_buffer(T* dst, int _count, bool& success)
407                 {
408                         std::lock_guard<std::recursive_mutex> locker(m_locker);
409                         return UNLOCKED_FIFO<T>::read_to_buffer(dst, _count, success);
410                 }
411                 virtual bool write(T data)
412                 {
413                         std::lock_guard<std::recursive_mutex> locker(m_locker);
414                         return UNLOCKED_FIFO<T>::write(data);
415                 }
416                 virtual bool write_not_push(int offset, T data)
417                 {
418                         std::lock_guard<std::recursive_mutex> locker(m_locker);
419                         return UNLOCKED_FIFO<T>::write_not_push(offset, data);
420                 }
421                 virtual int write_from_buffer(T* src, int _count, bool& success)
422                 {
423                         std::lock_guard<std::recursive_mutex> locker(m_locker);
424                         return UNLOCKED_FIFO<T>::write_from_buffer(src, _count, success);
425                 }
426                 virtual bool available()
427                 {
428                         std::lock_guard<std::recursive_mutex> locker(m_locker);
429                         return UNLOCKED_FIFO<T>::available();
430                 }
431                 virtual bool empty()
432                 {
433                         std::lock_guard<std::recursive_mutex> locker(m_locker);
434                         return UNLOCKED_FIFO<T>::empty();
435                 }
436                 virtual bool read_ready()
437                 {
438                         std::lock_guard<std::recursive_mutex> locker(m_locker);
439                         return UNLOCKED_FIFO<T>::read_ready();
440                 }
441                 virtual bool write_ready()
442                 {
443                         std::lock_guard<std::recursive_mutex> locker(m_locker);
444                         return UNLOCKED_FIFO<T>::write_ready();
445                 }
446
447                 virtual bool full()
448                 {
449                         std::lock_guard<std::recursive_mutex> locker(m_locker);
450                         return UNLOCKED_FIFO<T>::full();
451                 }
452                 virtual int count()
453                 {
454                         std::lock_guard<std::recursive_mutex> locker(m_locker);
455                         return UNLOCKED_FIFO<T>::count();
456                 }
457                 virtual int fifo_size()
458                 {
459                         std::lock_guard<std::recursive_mutex> locker(m_locker);
460                         return UNLOCKED_FIFO<T>::fifo_size();
461                 }
462                 virtual int left()
463                 {
464                         std::lock_guard<std::recursive_mutex> locker(m_locker);
465                         return UNLOCKED_FIFO<T>::left();
466                 }
467                 virtual void set_high_warn_value(int val = INT_MAX - 1)
468                 {
469                         std::lock_guard<std::recursive_mutex> locker(m_locker);
470                         return UNLOCKED_FIFO<T>::set_high_warn_value(val);
471                 }
472                 virtual void set_low_warn_value(int val = INT_MIN + 1)
473                 {
474                         std::lock_guard<std::recursive_mutex> locker(m_locker);
475                         return UNLOCKED_FIFO<T>::set_low_warn_value(val);
476                 }
477                 virtual bool high_warn()
478                 {
479                         std::lock_guard<std::recursive_mutex> locker(m_locker);
480                         return UNLOCKED_FIFO<T>::high_warn();
481                 }
482                 virtual bool low_warn()
483                 {
484                         std::lock_guard<std::recursive_mutex> locker(m_locker);
485                         return UNLOCKED_FIFO<T>::low_warn();
486                 }
487                 virtual bool resize(int _size, int _low_warn = INT_MIN + 1, int _high_warn = INT_MAX - 1)
488                 {
489                         std::lock_guard<std::recursive_mutex> locker(m_locker);
490                         return UNLOCKED_FIFO<T>::resize(_size, _low_warn, _high_warn);
491                 }
492         };
493
494         template <class T >
495         class UNLOCKED_RINGBUFFER : public UNLOCKED_FIFO<T> {
496         public:
497                 UNLOCKED_RINGBUFFER(int _size) :
498                 UNLOCKED_FIFO<T>(_size)
499                 {
500                 }
501                 ~UNLOCKED_RINGBUFFER()
502                 {
503                 }
504                 virtual void initialize()
505                 {
506                         UNLOCKED_FIFO<T>::initialize();
507                 }
508                 virtual void release()
509                 {
510                         UNLOCKED_FIFO<T>::release();
511                 }
512                 // RINGBUFFER :  Even write to buffer when full.
513                 virtual bool write(T data)
514                 {
515                         __UNLIKELY_IF((UNLOCKED_FIFO<T>::m_buf == nullptr) || (UNLOCKED_FIFO<T>::m_bufSize == 0)) {
516                                 return false;
517                         }
518
519                         __UNLIKELY_IF(UNLOCKED_FIFO<T>::m_dataCount < 0) {
520                                 UNLOCKED_FIFO<T>::m_dataCount = 0; // OK?
521                         }
522                         UNLOCKED_FIFO<T>::m_buf[UNLOCKED_FIFO<T>::m_wptr++] = data;
523                         UNLOCKED_FIFO<T>::m_dataCount++;
524                         __UNLIKELY_IF(UNLOCKED_FIFO<T>::m_wptr >= UNLOCKED_FIFO<T>::m_bufSize) {
525                                 UNLOCKED_FIFO<T>::m_wptr = UNLOCKED_FIFO<T>::m_wptr % UNLOCKED_FIFO<T>::m_bufSize;
526                         }
527                         __UNLIKELY_IF(UNLOCKED_FIFO<T>::m_dataCount > (int)UNLOCKED_FIFO<T>::m_bufSize) {
528                                 UNLOCKED_FIFO<T>::m_dataCount = (int)UNLOCKED_FIFO<T>::m_bufSize;
529                         }
530                         return true;
531                 }
532                 virtual bool write_not_push(int offset, T data)
533                 {
534                         __UNLIKELY_IF((UNLOCKED_FIFO<T>::m_buf == nullptr) ||
535                                                   (UNLOCKED_FIFO<T>::m_bufSize == 0) || (offset < 0)) {
536                                 return false;
537                         }
538                         unsigned int wp = UNLOCKED_FIFO<T>::m_wptr + offset;
539                         __UNLIKELY_IF(wp >= (int)UNLOCKED_FIFO<T>::m_bufSize) {
540                                 wp = wp % UNLOCKED_FIFO<T>::m_bufSize;
541                         }
542                         UNLOCKED_FIFO<T>::m_buf[wp] = data;
543                         return true;
544                 }
545                 virtual int write_from_buffer(T* src, int _count, bool& success)
546                 {
547                         __UNLIKELY_IF((src == nullptr) || (_count <= 0) ||
548                            (UNLOCKED_FIFO<T>::m_buf == nullptr) || (UNLOCKED_FIFO<T>::m_bufSize == 0)) {
549                                 success = false;
550                                 return 0;
551                         }
552                         __UNLIKELY_IF(UNLOCKED_FIFO<T>::m_dataCount < 0) {
553                                 UNLOCKED_FIFO<T>::m_dataCount = 0; // OK?
554                         }
555                         __UNLIKELY_IF(_count > (int)UNLOCKED_FIFO<T>::m_bufSize) {
556                                 _count = (int)UNLOCKED_FIFO<T>::m_bufSize;
557                                 __UNLIKELY_IF(_count <= 0) {
558                                         success = false;
559                                         return 0;
560                                 }
561                         }
562                         __UNLIKELY_IF(UNLOCKED_FIFO<T>::m_wptr >= UNLOCKED_FIFO<T>::m_bufSize) {
563                                 UNLOCKED_FIFO<T>::m_wptr = UNLOCKED_FIFO<T>::m_wptr % UNLOCKED_FIFO<T>::m_bufSize;
564                         }
565                         // OK, Transfer
566                         unsigned int xptr = UNLOCKED_FIFO<T>::m_wptr;
567                         if((xptr + (unsigned int)_count) >= UNLOCKED_FIFO<T>::m_bufSize) {
568                                 int count1 = (int)(UNLOCKED_FIFO<T>::m_bufSize - xptr);
569                                 int count2 = _count - count1;
570                                 int rp = 0;
571                                 for(int i = 0; i < count1; i++) {
572                                         UNLOCKED_FIFO<T>::m_buf[xptr++] = src[rp++];
573                                 }
574                                 xptr = 0;
575                                 for(int i = 0; i < count2; i++) {
576                                         UNLOCKED_FIFO<T>::m_buf[xptr++] = src[rp++];
577                                 }
578                         } else {
579                                 // Inside buffer
580                                 for(int i = 0; i < _count; i++) {
581                                         UNLOCKED_FIFO<T>::m_buf[xptr++] = src[i];
582                                 }
583                         }
584                         UNLOCKED_FIFO<T>::m_dataCount += _count;
585                         UNLOCKED_FIFO<T>::m_wptr = (xptr % UNLOCKED_FIFO<T>::m_bufSize);
586                         __UNLIKELY_IF(UNLOCKED_FIFO<T>::m_dataCount >= (int)UNLOCKED_FIFO<T>::m_bufSize) {
587                                 UNLOCKED_FIFO<T>::m_dataCount = UNLOCKED_FIFO<T>::m_bufSize;
588                         }
589                         success = true;
590                         return _count;
591                 }
592                 virtual bool write_ready()
593                 {
594                         bool f = UNLOCKED_FIFO<T>::available();
595                         return f; // OK?
596                 }
597                 virtual bool full()
598                 {
599                         return false; // OK?
600                 }
601                 virtual int left()
602                 {
603                         __UNLIKELY_IF((UNLOCKED_FIFO<T>::m_bufSize == 0) || (UNLOCKED_FIFO<T>::m_buf == nullptr)) {
604                                 return 0;
605                         }
606                         return (int)UNLOCKED_FIFO<T>::m_bufSize;
607                 }
608         };
609
610         template <class T >
611         class LOCKED_RINGBUFFER : public UNLOCKED_RINGBUFFER<T> {
612         protected:
613                 std::recursive_mutex m_locker;
614         public:
615                 LOCKED_RINGBUFFER(int _size) :
616                 UNLOCKED_RINGBUFFER<T>(_size)
617                 {
618                 }
619                 ~LOCKED_RINGBUFFER()
620                 {
621                 }
622                 virtual void initialize()
623                 {
624                         std::lock_guard<std::recursive_mutex> locker(m_locker);
625                         UNLOCKED_RINGBUFFER<T>::initialize();
626                 }
627                 virtual void release()
628                 {
629                         std::lock_guard<std::recursive_mutex> locker(m_locker);
630                         UNLOCKED_RINGBUFFER<T>::release();
631                 }
632                 virtual void clear()
633                 {
634                         std::lock_guard<std::recursive_mutex> locker(m_locker);
635                         UNLOCKED_RINGBUFFER<T>::clear();
636                 }
637
638                 virtual T read(bool& success)
639                 {
640                         std::lock_guard<std::recursive_mutex> locker(m_locker);
641                         return UNLOCKED_RINGBUFFER<T>::read(success);
642                 }
643                 virtual T read(void)
644                 {
645                         bool success;
646                         std::lock_guard<std::recursive_mutex> locker(m_locker);
647                         return UNLOCKED_RINGBUFFER<T>::read(success);
648                 }
649                 virtual T read_not_remove(int offset, bool& success)
650                 {
651                         std::lock_guard<std::recursive_mutex> locker(m_locker);
652                         return UNLOCKED_RINGBUFFER<T>::read_not_remove(offset, success);
653                 }
654                 virtual T read_not_remove(int offset)
655                 {
656                         bool success;
657                         std::lock_guard<std::recursive_mutex> locker(m_locker);
658                         return UNLOCKED_RINGBUFFER<T>::read_not_remove(offset, success);
659                 }
660
661                 virtual int read_to_buffer(T* dst, int _count, bool& success)
662                 {
663                         std::lock_guard<std::recursive_mutex> locker(m_locker);
664                         return UNLOCKED_RINGBUFFER<T>::read_to_buffer(dst, _count, success);
665                 }
666
667                 virtual bool write(T data)
668                 {
669                         std::lock_guard<std::recursive_mutex> locker(m_locker);
670                         return UNLOCKED_RINGBUFFER<T>::write(data);
671                 }
672                 virtual bool write_not_push(int offset, T data)
673                 {
674                         std::lock_guard<std::recursive_mutex> locker(m_locker);
675                         return UNLOCKED_RINGBUFFER<T>::write_not_push(offset, data);
676                 }
677                 virtual int write_from_buffer(T* src, int _count, bool& success)
678                 {
679                         std::lock_guard<std::recursive_mutex> locker(m_locker);
680                         return UNLOCKED_RINGBUFFER<T>::write_from_buffer(src, _count, success);
681                 }
682                 virtual bool available()
683                 {
684                         std::lock_guard<std::recursive_mutex> locker(m_locker);
685                         return UNLOCKED_RINGBUFFER<T>::available();
686                 }
687                 virtual bool empty()
688                 {
689                         std::lock_guard<std::recursive_mutex> locker(m_locker);
690                         return UNLOCKED_RINGBUFFER<T>::empty();
691                 }
692                 virtual bool read_ready()
693                 {
694                         std::lock_guard<std::recursive_mutex> locker(m_locker);
695                         return UNLOCKED_RINGBUFFER<T>::read_ready();
696                 }
697                 virtual bool write_ready()
698                 {
699                         std::lock_guard<std::recursive_mutex> locker(m_locker);
700                         return UNLOCKED_RINGBUFFER<T>::write_ready();
701                 }
702                 virtual bool full()
703                 {
704                         std::lock_guard<std::recursive_mutex> locker(m_locker);
705                         return UNLOCKED_RINGBUFFER<T>::full();
706                 }
707                 virtual int count()
708                 {
709                         std::lock_guard<std::recursive_mutex> locker(m_locker);
710                         return UNLOCKED_RINGBUFFER<T>::count();
711                 }
712                 virtual int fifo_size()
713                 {
714                         std::lock_guard<std::recursive_mutex> locker(m_locker);
715                         return UNLOCKED_RINGBUFFER<T>::fifo_size();
716                 }
717                 virtual int left()
718                 {
719                         std::lock_guard<std::recursive_mutex> locker(m_locker);
720                         return UNLOCKED_RINGBUFFER<T>::left();
721                 }
722
723                 virtual void set_high_warn_value(int val = INT_MAX - 1)
724                 {
725                         std::lock_guard<std::recursive_mutex> locker(m_locker);
726                         return UNLOCKED_RINGBUFFER<T>::set_high_warn_value(val);
727                 }
728                 virtual void set_low_warn_value(int val = INT_MIN + 1)
729                 {
730                         std::lock_guard<std::recursive_mutex> locker(m_locker);
731                         return UNLOCKED_RINGBUFFER<T>::set_low_warn_value(val);
732                 }
733                 virtual bool high_warn()
734                 {
735                         std::lock_guard<std::recursive_mutex> locker(m_locker);
736                         return UNLOCKED_RINGBUFFER<T>::high_warn();
737                 }
738                 virtual bool low_warn()
739                 {
740                         std::lock_guard<std::recursive_mutex> locker(m_locker);
741                         return UNLOCKED_RINGBUFFER<T>::low_warn();
742                 }
743                 virtual bool resize(int _size, int _low_warn = INT_MIN + 1, int _high_warn = INT_MAX - 1)
744                 {
745                         std::lock_guard<std::recursive_mutex> locker(m_locker);
746                         return UNLOCKED_RINGBUFFER<T>::resize(_size, _low_warn, _high_warn);
747                 }
748         };
749 }