From 5c69aef56efb757a2b4473c9ca6e73cfc23c1618 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 23 Feb 2023 16:13:16 -0700 Subject: [PATCH] add memory fences to try to avoid a conceptual memory ordering issue between capture & the butler --- libs/ardour/butler.cc | 3 +++ libs/ardour/disk_writer.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc index 861bf8e9c4..5b8309e8b7 100644 --- a/libs/ardour/butler.cc +++ b/libs/ardour/butler.cc @@ -213,6 +213,9 @@ Butler::thread_work () Temporal::TempoMap::fetch (); restart: + /* Ensure that no reads migrate before this fence */ + std::atomic_thread_fence (std::memory_order_acquire); + DEBUG_TRACE (DEBUG::Butler, "at restart for disk work\n"); disk_work_outstanding = false; diff --git a/libs/ardour/disk_writer.cc b/libs/ardour/disk_writer.cc index 5be3f73cb6..41b529cf64 100644 --- a/libs/ardour/disk_writer.cc +++ b/libs/ardour/disk_writer.cc @@ -737,6 +737,10 @@ DiskWriter::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp _need_butler = true; } + /* Ensure that anything written during run() is visible in other threads */ + + std::atomic_thread_fence (std::memory_order_release); + // DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 writer run, needs butler = %2\n", name(), _need_butler)); }