From 1008ac20ffcf4a88420c5c5a9a0b2396cca04f20 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 5 Dec 2019 15:34:51 -0700 Subject: a few parameter changes, and flesh out code to switch rbufs in DiskReader --- libs/ardour/disk_io.cc | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'libs/ardour/disk_io.cc') diff --git a/libs/ardour/disk_io.cc b/libs/ardour/disk_io.cc index cd41f78505..9ac0d58750 100644 --- a/libs/ardour/disk_io.cc +++ b/libs/ardour/disk_io.cc @@ -324,8 +324,8 @@ DiskIOProcessor::use_playlist (DataType dt, boost::shared_ptr playlist } DiskIOProcessor::ChannelInfo::ChannelInfo (samplecnt_t bufsize) - : current_rbuf (0) - , read_switch_rbuf (0) + : _process_rbuf (0) + , _switch_rbuf (0) , wbuf (0) , capture_transition_buf (0) , curr_capture_cnt (0) @@ -347,11 +347,41 @@ DiskIOProcessor::ChannelInfo::~ChannelInfo () } PlaybackBuffer* -DiskIOProcessor::ChannelInfo::rbuf() +DiskIOProcessor::ChannelInfo::process_rbuf() { - return _rbuf[0]; + return _rbuf[g_atomic_int_get (&_process_rbuf)]; } +PlaybackBuffer* +DiskIOProcessor::ChannelInfo::other_rbuf() +{ + return _rbuf[!g_atomic_int_get (&_process_rbuf)]; +} + +void +DiskIOProcessor::ChannelInfo::maybe_switch_rbuf () +{ + if (!g_atomic_int_get (&_switch_rbuf)) { + return; + } + + while (true) { + gint current_process_rbuf = g_atomic_int_get (&_process_rbuf); + + if (g_atomic_int_compare_and_exchange (&_process_rbuf, current_process_rbuf, !_process_rbuf)) { + g_atomic_int_set (&_switch_rbuf, 0); + break; + } + } +} + +void +DiskIOProcessor::ChannelInfo::queue_switch_rbuf () +{ + g_atomic_int_set (&_switch_rbuf, 1); +} + + void DiskIOProcessor::drop_track () { -- cgit v1.2.3