comparison base/RingBuffer.h @ 1553:66c1988fc906

Use bqvec barrier
author Chris Cannam
date Thu, 11 Oct 2018 13:08:21 +0100
parents 48e9f538e6e9
children 6e218407f0cf
comparison
equal deleted inserted replaced
1552:05c3fbaec8ea 1553:66c1988fc906
16 This is a modified version of a source file from the 16 This is a modified version of a source file from the
17 Rosegarden MIDI and audio sequencer and notation editor. 17 Rosegarden MIDI and audio sequencer and notation editor.
18 This file copyright 2000-2006 Chris Cannam. 18 This file copyright 2000-2006 Chris Cannam.
19 */ 19 */
20 20
21 #ifndef _RINGBUFFER_H_ 21 #ifndef SV_RINGBUFFER_H
22 #define _RINGBUFFER_H_ 22 #define SV_RINGBUFFER_H
23 23
24 #include <sys/types.h> 24 #include <sys/types.h>
25 25
26 #include "system/System.h" 26 #include "system/System.h"
27
28 #include <bqvec/Barrier.h>
27 29
28 #include <cstring> // memcpy, memset &c 30 #include <cstring> // memcpy, memset &c
29 31
30 //#define DEBUG_RINGBUFFER 1 32 //#define DEBUG_RINGBUFFER 1
31 33
337 } else { 339 } else {
338 memcpy(destination, m_buffer + m_readers[R], here * sizeof(T)); 340 memcpy(destination, m_buffer + m_readers[R], here * sizeof(T));
339 memcpy(destination + here, m_buffer, (n - here) * sizeof(T)); 341 memcpy(destination + here, m_buffer, (n - here) * sizeof(T));
340 } 342 }
341 343
342 MBARRIER(); 344 BQ_MBARRIER();
343 m_readers[R] = (m_readers[R] + n) % m_size; 345 m_readers[R] = (m_readers[R] + n) % m_size;
344 346
345 #ifdef DEBUG_RINGBUFFER 347 #ifdef DEBUG_RINGBUFFER
346 std::cerr << "RingBuffer<T," << N << ">[" << this << "]::read: read " << n << ", reader now " << m_readers[R] << std::endl; 348 std::cerr << "RingBuffer<T," << N << ">[" << this << "]::read: read " << n << ", reader now " << m_readers[R] << std::endl;
347 #endif 349 #endif
380 for (int i = 0; i < (n - here); ++i) { 382 for (int i = 0; i < (n - here); ++i) {
381 destination[i + here] += m_buffer[i]; 383 destination[i + here] += m_buffer[i];
382 } 384 }
383 } 385 }
384 386
385 MBARRIER(); 387 BQ_MBARRIER();
386 m_readers[R] = (m_readers[R] + n) % m_size; 388 m_readers[R] = (m_readers[R] + n) % m_size;
387 return n; 389 return n;
388 } 390 }
389 391
390 template <typename T, int N> 392 template <typename T, int N>
403 T t; 405 T t;
404 memset(&t, 0, sizeof(T)); 406 memset(&t, 0, sizeof(T));
405 return t; 407 return t;
406 } 408 }
407 T value = m_buffer[m_readers[R]]; 409 T value = m_buffer[m_readers[R]];
408 MBARRIER(); 410 BQ_MBARRIER();
409 if (++m_readers[R] == m_size) m_readers[R] = 0; 411 if (++m_readers[R] == m_size) m_readers[R] = 0;
410 return value; 412 return value;
411 } 413 }
412 414
413 template <typename T, int N> 415 template <typename T, int N>
510 } else { 512 } else {
511 memcpy(m_buffer + m_writer, source, here * sizeof(T)); 513 memcpy(m_buffer + m_writer, source, here * sizeof(T));
512 memcpy(m_buffer, source + here, (n - here) * sizeof(T)); 514 memcpy(m_buffer, source + here, (n - here) * sizeof(T));
513 } 515 }
514 516
515 MBARRIER(); 517 BQ_MBARRIER();
516 m_writer = (m_writer + n) % m_size; 518 m_writer = (m_writer + n) % m_size;
517 519
518 #ifdef DEBUG_RINGBUFFER 520 #ifdef DEBUG_RINGBUFFER
519 std::cerr << "RingBuffer<T," << N << ">[" << this << "]::write: wrote " << n << ", writer now " << m_writer << std::endl; 521 std::cerr << "RingBuffer<T," << N << ">[" << this << "]::write: wrote " << n << ", writer now " << m_writer << std::endl;
520 #endif 522 #endif
546 } else { 548 } else {
547 memset(m_buffer + m_writer, 0, here * sizeof(T)); 549 memset(m_buffer + m_writer, 0, here * sizeof(T));
548 memset(m_buffer, 0, (n - here) * sizeof(T)); 550 memset(m_buffer, 0, (n - here) * sizeof(T));
549 } 551 }
550 552
551 MBARRIER(); 553 BQ_MBARRIER();
552 m_writer = (m_writer + n) % m_size; 554 m_writer = (m_writer + n) % m_size;
553 return n; 555 return n;
554 } 556 }
555 557
556 #endif // _RINGBUFFER_H_ 558 #endif // _RINGBUFFER_H_