switch from glib atomic to std::atomic (libs edition)

This commit is contained in:
Paul Davis 2023-02-17 00:31:21 -07:00
parent d7922738f0
commit 4ba4cd69ff
77 changed files with 630 additions and 603 deletions

View file

@ -22,6 +22,7 @@
#ifndef __ardour_audio_unit_h__ #ifndef __ardour_audio_unit_h__
#define __ardour_audio_unit_h__ #define __ardour_audio_unit_h__
#include <atomic>
#include <cstdint> #include <cstdint>
#include <list> #include <list>
#include <map> #include <map>
@ -30,7 +31,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "pbd/g_atomic_compat.h"
#include "ardour/plugin.h" #include "ardour/plugin.h"
#include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnit.h>
@ -170,7 +170,7 @@ class LIBARDOUR_API AUPlugin : public ARDOUR::Plugin
int32_t output_channels; int32_t output_channels;
std::vector<std::pair<int,int> > io_configs; std::vector<std::pair<int,int> > io_configs;
samplecnt_t _last_nframes; samplecnt_t _last_nframes;
mutable GATOMIC_QUAL guint _current_latency; mutable std::atomic<unsigned int> _current_latency;
bool _requires_fixed_size_buffers; bool _requires_fixed_size_buffers;
AudioBufferList* buffers; AudioBufferList* buffers;
bool _has_midi_input; bool _has_midi_input;

View file

@ -27,6 +27,7 @@
#include "libardour-config.h" #include "libardour-config.h"
#endif #endif
#include <atomic>
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <set> #include <set>
@ -38,7 +39,6 @@
#include "pbd/signals.h" #include "pbd/signals.h"
#include "pbd/pthread_utils.h" #include "pbd/pthread_utils.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h" #include "ardour/ardour.h"
#include "ardour/data_type.h" #include "ardour/data_type.h"
@ -118,7 +118,7 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr
bool is_realtime() const; bool is_realtime() const;
// for the user which hold state_lock to check if reset operation is pending // for the user which hold state_lock to check if reset operation is pending
bool is_reset_requested() const { return g_atomic_int_get (const_cast<GATOMIC_QUAL gint*> (&_hw_reset_request_count)); } bool is_reset_requested() const { return g_atomic_int_get (const_cast<std::atomic<int>*> (&_hw_reset_request_count)); }
int set_device_name (const std::string&); int set_device_name (const std::string&);
int set_sample_rate (float); int set_sample_rate (float);
@ -297,19 +297,19 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr
std::string _last_backend_error_string; std::string _last_backend_error_string;
PBD::Thread* _hw_reset_event_thread; PBD::Thread* _hw_reset_event_thread;
GATOMIC_QUAL gint _hw_reset_request_count; std::atomic<int> _hw_reset_request_count;
Glib::Threads::Cond _hw_reset_condition; Glib::Threads::Cond _hw_reset_condition;
Glib::Threads::Mutex _reset_request_lock; Glib::Threads::Mutex _reset_request_lock;
GATOMIC_QUAL gint _stop_hw_reset_processing; std::atomic<int> _stop_hw_reset_processing;
PBD::Thread* _hw_devicelist_update_thread; PBD::Thread* _hw_devicelist_update_thread;
GATOMIC_QUAL gint _hw_devicelist_update_count; std::atomic<int> _hw_devicelist_update_count;
Glib::Threads::Cond _hw_devicelist_update_condition; Glib::Threads::Cond _hw_devicelist_update_condition;
Glib::Threads::Mutex _devicelist_update_lock; Glib::Threads::Mutex _devicelist_update_lock;
GATOMIC_QUAL gint _stop_hw_devicelist_processing; std::atomic<int> _stop_hw_devicelist_processing;
uint32_t _start_cnt; uint32_t _start_cnt;
uint32_t _init_countdown; uint32_t _init_countdown;
GATOMIC_QUAL gint _pending_playback_latency_callback; std::atomic<int> _pending_playback_latency_callback;
GATOMIC_QUAL gint _pending_capture_latency_callback; std::atomic<int> _pending_capture_latency_callback;
void start_hw_event_processing(); void start_hw_event_processing();
void stop_hw_event_processing(); void stop_hw_event_processing();

View file

@ -112,7 +112,7 @@ private:
std::shared_ptr<AudioRegion> the_region; std::shared_ptr<AudioRegion> the_region;
std::shared_ptr<MidiRegion> midi_region; std::shared_ptr<MidiRegion> midi_region;
samplepos_t current_sample; samplepos_t current_sample;
mutable GATOMIC_QUAL gint _auditioning; mutable std::atomic<int> _auditioning;
Glib::Threads::Mutex lock; Glib::Threads::Mutex lock;
timecnt_t length; timecnt_t length;
sampleoffset_t _seek_sample; sampleoffset_t _seek_sample;

View file

@ -23,7 +23,8 @@
#ifndef __ardour_automation_event_h__ #ifndef __ardour_automation_event_h__
#define __ardour_automation_event_h__ #define __ardour_automation_event_h__
#include <stdint.h> #include <atomic>
#include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <list> #include <list>
#include <cmath> #include <cmath>
@ -37,7 +38,6 @@
#include "pbd/xml++.h" #include "pbd/xml++.h"
#include "pbd/statefuldestructible.h" #include "pbd/statefuldestructible.h"
#include "pbd/properties.h" #include "pbd/properties.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h" #include "ardour/ardour.h"
@ -109,7 +109,7 @@ public:
void start_touch (timepos_t const & when); void start_touch (timepos_t const & when);
void stop_touch (timepos_t const & when); void stop_touch (timepos_t const & when);
bool touching () const { return g_atomic_int_get (const_cast<GATOMIC_QUAL gint*>(&_touching)) != 0; } bool touching () const { return g_atomic_int_get (const_cast<std::atomic<int>*>(&_touching)) != 0; }
bool writing () const { return _state == Write; } bool writing () const { return _state == Write; }
bool touch_enabled () const { return _state & (Touch | Latch); } bool touch_enabled () const { return _state & (Touch | Latch); }
@ -136,7 +136,7 @@ private:
void maybe_signal_changed (); void maybe_signal_changed ();
AutoState _state; AutoState _state;
GATOMIC_QUAL gint _touching; std::atomic<int> _touching;
PBD::ScopedConnection _writepass_connection; PBD::ScopedConnection _writepass_connection;

View file

@ -23,12 +23,13 @@
#ifndef __ardour_butler_h__ #ifndef __ardour_butler_h__
#define __ardour_butler_h__ #define __ardour_butler_h__
#include <atomic>
#include <pthread.h> #include <pthread.h>
#include <glibmm/threads.h> #include <glibmm/threads.h>
#include "pbd/crossthread.h" #include "pbd/crossthread.h"
#include "pbd/g_atomic_compat.h"
#include "pbd/pool.h" #include "pbd/pool.h"
#include "pbd/ringbuffer.h" #include "pbd/ringbuffer.h"
#include "pbd/mpmc_queue.h" #include "pbd/mpmc_queue.h"
@ -81,7 +82,7 @@ public:
return _midi_buffer_size; return _midi_buffer_size;
} }
mutable GATOMIC_QUAL gint should_do_transport_work; mutable std::atomic<int> should_do_transport_work;
private: private:
struct Request { struct Request {

View file

@ -19,8 +19,9 @@
#ifndef _ardour_circular_buffer_h_ #ifndef _ardour_circular_buffer_h_
#define _ardour_circular_buffer_h_ #define _ardour_circular_buffer_h_
#include <atomic>
#include "pbd/ringbuffer.h" #include "pbd/ringbuffer.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
#include "ardour/types.h" #include "ardour/types.h"
@ -72,8 +73,8 @@ private:
guint _size; guint _size;
guint _size_mask; guint _size_mask;
GATOMIC_QUAL gint _idx; std::atomic<int> _idx;
GATOMIC_QUAL gint _ack; std::atomic<int> _ack;
}; };
} }

View file

@ -20,9 +20,9 @@
#ifndef _ardour_disk_reader_h_ #ifndef _ardour_disk_reader_h_
#define _ardour_disk_reader_h_ #define _ardour_disk_reader_h_
#include <boost/optional.hpp> #include <atomic>
#include "pbd/g_atomic_compat.h" #include <boost/optional.hpp>
#include "evoral/Curve.h" #include "evoral/Curve.h"
@ -114,7 +114,7 @@ public:
static void dec_no_disk_output (); static void dec_no_disk_output ();
static bool no_disk_output () static bool no_disk_output ()
{ {
return g_atomic_int_get (&_no_disk_output); return _no_disk_output.load ();
} }
static void reset_loop_declick (Location*, samplecnt_t sample_rate); static void reset_loop_declick (Location*, samplecnt_t sample_rate);
static void alloc_loop_declick (samplecnt_t sample_rate); static void alloc_loop_declick (samplecnt_t sample_rate);
@ -202,7 +202,7 @@ private:
IOChange input_change_pending; IOChange input_change_pending;
samplepos_t file_sample[DataType::num_types]; samplepos_t file_sample[DataType::num_types];
mutable GATOMIC_QUAL gint _pending_overwrite; mutable std::atomic<OverwriteReason> _pending_overwrite;
DeclickAmp _declick_amp; DeclickAmp _declick_amp;
sampleoffset_t _declick_offs; sampleoffset_t _declick_offs;
@ -213,7 +213,7 @@ private:
static samplecnt_t _chunk_samples; static samplecnt_t _chunk_samples;
static GATOMIC_QUAL gint _no_disk_output; static std::atomic<int> _no_disk_output;
static Declicker loop_declick_in; static Declicker loop_declick_in;
static Declicker loop_declick_out; static Declicker loop_declick_out;

View file

@ -20,12 +20,11 @@
#ifndef __ardour_disk_writer_h__ #ifndef __ardour_disk_writer_h__
#define __ardour_disk_writer_h__ #define __ardour_disk_writer_h__
#include <atomic>
#include <list> #include <list>
#include <vector> #include <vector>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include "pbd/g_atomic_compat.h"
#include "ardour/disk_io.h" #include "ardour/disk_io.h"
#include "ardour/midi_buffer.h" #include "ardour/midi_buffer.h"
@ -86,8 +85,8 @@ public:
std::list<std::shared_ptr<Source> >& last_capture_sources () { return _last_capture_sources; } std::list<std::shared_ptr<Source> >& last_capture_sources () { return _last_capture_sources; }
bool record_enabled () const { return g_atomic_int_get (const_cast<GATOMIC_QUAL gint*>(&_record_enabled)); } bool record_enabled () const { return g_atomic_int_get (const_cast<std::atomic<int>*>(&_record_enabled)); }
bool record_safe () const { return g_atomic_int_get (const_cast<GATOMIC_QUAL gint*>(&_record_safe)); } bool record_safe () const { return g_atomic_int_get (const_cast<std::atomic<int>*>(&_record_safe)); }
void set_record_enabled (bool yn); void set_record_enabled (bool yn);
void set_record_safe (bool yn); void set_record_safe (bool yn);
@ -187,10 +186,10 @@ private:
bool _transport_looped; bool _transport_looped;
samplepos_t _transport_loop_sample; samplepos_t _transport_loop_sample;
GATOMIC_QUAL gint _record_enabled; std::atomic<int> _record_enabled;
GATOMIC_QUAL gint _record_safe; std::atomic<int> _record_safe;
GATOMIC_QUAL gint _samples_pending_write; std::atomic<int> _samples_pending_write;
GATOMIC_QUAL gint _num_captured_loops; std::atomic<int> _num_captured_loops;
std::shared_ptr<SMFSource> _midi_write_source; std::shared_ptr<SMFSource> _midi_write_source;

View file

@ -19,7 +19,8 @@
#ifndef _ardour_ffmpegfile_importable_source_h_ #ifndef _ardour_ffmpegfile_importable_source_h_
#define _ardour_ffmpegfile_importable_source_h_ #define _ardour_ffmpegfile_importable_source_h_
#include "pbd/g_atomic_compat.h" #include <atomic>
#include "pbd/ringbuffer.h" #include "pbd/ringbuffer.h"
#include "ardour/importable_source.h" #include "ardour/importable_source.h"
@ -68,7 +69,7 @@ private:
PBD::RingBuffer<Sample> _buffer; PBD::RingBuffer<Sample> _buffer;
/* Set to 1 to indicate that ffmpeg should be terminating. */ /* Set to 1 to indicate that ffmpeg should be terminating. */
GATOMIC_QUAL gint _ffmpeg_should_terminate; std::atomic<int> _ffmpeg_should_terminate;
/* To make sure we don't try to parse partial floats, we might have a couple of bytes /* To make sure we don't try to parse partial floats, we might have a couple of bytes
* of leftover unparsable data after any `did_read_data` call. Those couple of bytes are * of leftover unparsable data after any `did_read_data` call. Those couple of bytes are

View file

@ -23,6 +23,7 @@
#ifndef __ardour_graph_h__ #ifndef __ardour_graph_h__
#define __ardour_graph_h__ #define __ardour_graph_h__
#include <atomic>
#include <list> #include <list>
#include <memory> #include <memory>
#include <set> #include <set>
@ -30,7 +31,6 @@
#include <vector> #include <vector>
#include "pbd/g_atomic_compat.h"
#include "pbd/mpmc_queue.h" #include "pbd/mpmc_queue.h"
#include "pbd/semutils.h" #include "pbd/semutils.h"
@ -107,28 +107,28 @@ private:
void helper_thread (); void helper_thread ();
PBD::MPMCQueue<ProcessNode*> _trigger_queue; ///< nodes that can be processed PBD::MPMCQueue<ProcessNode*> _trigger_queue; ///< nodes that can be processed
GATOMIC_QUAL guint _trigger_queue_size; ///< number of entries in trigger-queue std::atomic<unsigned int> _trigger_queue_size; ///< number of entries in trigger-queue
/** Start worker threads */ /** Start worker threads */
PBD::Semaphore _execution_sem; PBD::Semaphore _execution_sem;
/** The number of processing threads that are asleep */ /** The number of processing threads that are asleep */
GATOMIC_QUAL guint _idle_thread_cnt; std::atomic<unsigned int> _idle_thread_cnt;
/** Signalled to start a run of the graph for a process callback */ /** Signalled to start a run of the graph for a process callback */
PBD::Semaphore _callback_start_sem; PBD::Semaphore _callback_start_sem;
PBD::Semaphore _callback_done_sem; PBD::Semaphore _callback_done_sem;
/** The number of unprocessed nodes that do not feed any other node; updated during processing */ /** The number of unprocessed nodes that do not feed any other node; updated during processing */
GATOMIC_QUAL guint _terminal_refcnt; std::atomic<unsigned int> _terminal_refcnt;
bool _graph_empty; bool _graph_empty;
/* number of background worker threads >= 0 */ /* number of background worker threads >= 0 */
GATOMIC_QUAL guint _n_workers; std::atomic<unsigned int> _n_workers;
/* flag to terminate background threads */ /* flag to terminate background threads */
GATOMIC_QUAL gint _terminate; std::atomic<int> _terminate;
/* graph chain */ /* graph chain */
GraphChain const* _graph_chain; GraphChain const* _graph_chain;

View file

@ -21,12 +21,12 @@
#ifndef __ardour_graphnode_h__ #ifndef __ardour_graphnode_h__
#define __ardour_graphnode_h__ #define __ardour_graphnode_h__
#include <atomic>
#include <list> #include <list>
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include "pbd/g_atomic_compat.h"
#include "pbd/rcu.h" #include "pbd/rcu.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
@ -94,7 +94,7 @@ protected:
private: private:
void finish (GraphChain const*); void finish (GraphChain const*);
GATOMIC_QUAL gint _refcount; std::atomic<int> _refcount;
}; };
} // namespace ARDOUR } // namespace ARDOUR

View file

@ -19,10 +19,9 @@
#ifndef _libardour_io_plug_h_ #ifndef _libardour_io_plug_h_
#define _libardour_io_plug_h_ #define _libardour_io_plug_h_
#include <boost/shared_ptr.hpp> #include <atomic>
#include "pbd/timing.h" #include "pbd/timing.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h" #include "ardour/ardour.h"
#include "ardour/automation_control.h" #include "ardour/automation_control.h"
@ -169,8 +168,8 @@ private:
Gtkmm2ext::WindowProxy* _window_proxy; Gtkmm2ext::WindowProxy* _window_proxy;
PBD::TimingStats _timing_stats; PBD::TimingStats _timing_stats;
GATOMIC_QUAL gint _stat_reset; std::atomic<int> _stat_reset;
GATOMIC_QUAL gint _reset_meters; std::atomic<int> _reset_meters;
}; };
} }

View file

@ -22,10 +22,10 @@
#ifndef __ardour_meter_h__ #ifndef __ardour_meter_h__
#define __ardour_meter_h__ #define __ardour_meter_h__
#include <atomic>
#include <vector> #include <vector>
#include "pbd/fastlog.h" #include "pbd/fastlog.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
#include "ardour/processor.h" #include "ardour/processor.h"
@ -101,8 +101,8 @@ private:
ChanCount current_meters; ChanCount current_meters;
ChanCount _max_n_meters; ChanCount _max_n_meters;
GATOMIC_QUAL gint _reset_dpm; std::atomic<int> _reset_dpm;
GATOMIC_QUAL gint _reset_max; std::atomic<int> _reset_max;
uint32_t _bufcnt; uint32_t _bufcnt;
std::vector<float> _peak_buffer; // internal, integrate std::vector<float> _peak_buffer; // internal, integrate

View file

@ -19,12 +19,12 @@
#ifndef __ardour_channel_filter_h__ #ifndef __ardour_channel_filter_h__
#define __ardour_channel_filter_h__ #define __ardour_channel_filter_h__
#include <stdint.h> #include <atomic>
#include <cstdint>
#include <glib.h> #include <glib.h>
#include "pbd/signals.h" #include "pbd/signals.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/types.h" #include "ardour/types.h"
@ -73,24 +73,24 @@ public:
/** Atomically get both the channel mode and mask. */ /** Atomically get both the channel mode and mask. */
void get_mode_and_mask(ChannelMode* mode, uint16_t* mask) const { void get_mode_and_mask(ChannelMode* mode, uint16_t* mask) const {
const uint32_t mm = g_atomic_int_get (const_cast<GATOMIC_QUAL guint*> (&_mode_mask)); const uint32_t mm = g_atomic_int_get (const_cast<std::atomic<unsigned int>*> (&_mode_mask));
*mode = static_cast<ChannelMode>((mm & 0xFFFF0000) >> 16); *mode = static_cast<ChannelMode>((mm & 0xFFFF0000) >> 16);
*mask = (mm & 0x0000FFFF); *mask = (mm & 0x0000FFFF);
} }
ChannelMode get_channel_mode() const { ChannelMode get_channel_mode() const {
return static_cast<ChannelMode>((g_atomic_int_get (const_cast<GATOMIC_QUAL guint*> (&_mode_mask)) & 0xFFFF0000) >> 16); return static_cast<ChannelMode>((g_atomic_int_get (const_cast<std::atomic<unsigned int>*> (&_mode_mask)) & 0xFFFF0000) >> 16);
} }
uint16_t get_channel_mask() const { uint16_t get_channel_mask() const {
return g_atomic_int_get (const_cast<GATOMIC_QUAL guint*> (&_mode_mask)) & 0x0000FFFF; return g_atomic_int_get (const_cast<std::atomic<unsigned int>*> (&_mode_mask)) & 0x0000FFFF;
} }
PBD::Signal0<void> ChannelMaskChanged; PBD::Signal0<void> ChannelMaskChanged;
PBD::Signal0<void> ChannelModeChanged; PBD::Signal0<void> ChannelModeChanged;
private: private:
GATOMIC_QUAL uint32_t _mode_mask; ///< 16 bits mode, 16 bits mask std::atomic<uint32_t> _mode_mask; ///< 16 bits mode, 16 bits mask
}; };
} /* namespace ARDOUR */ } /* namespace ARDOUR */

View file

@ -66,7 +66,7 @@ public:
void start_touch (timepos_t const & when); void start_touch (timepos_t const & when);
void stop_touch (timepos_t const & when); void stop_touch (timepos_t const & when);
bool touching() const { return g_atomic_int_get (const_cast<GATOMIC_QUAL gint*> (&_touching)); } bool touching() const { return g_atomic_int_get (const_cast<std::atomic<int>*> (&_touching)); }
bool writing() const { return _auto_state == Write; } bool writing() const { return _auto_state == Write; }
bool touch_enabled() const { return _auto_state & (Touch | Latch); } bool touch_enabled() const { return _auto_state & (Touch | Latch); }
@ -84,7 +84,7 @@ protected:
bool _has_state; bool _has_state;
uint32_t _responding_to_control_auto_state_change; uint32_t _responding_to_control_auto_state_change;
GATOMIC_QUAL gint _touching; std::atomic<int> _touching;
void control_auto_state_changed (AutoState); void control_auto_state_changed (AutoState);

View file

@ -27,24 +27,24 @@
#ifndef __ardour_playlist_h__ #ifndef __ardour_playlist_h__
#define __ardour_playlist_h__ #define __ardour_playlist_h__
#include <memory> #include <atomic>
#include <boost/optional.hpp>
#include <boost/utility.hpp>
#include <list> #include <list>
#include <map> #include <map>
#include <memory>
#include <set> #include <set>
#include <string> #include <string>
#include <sys/stat.h> #include <sys/stat.h>
#include <boost/optional.hpp>
#include <boost/utility.hpp>
#include <glib.h> #include <glib.h>
#include "pbd/sequence_property.h" #include "pbd/sequence_property.h"
#include "pbd/stateful.h" #include "pbd/stateful.h"
#include "pbd/statefuldestructible.h" #include "pbd/statefuldestructible.h"
#include "pbd/undo.h" #include "pbd/undo.h"
#include "pbd/g_atomic_compat.h"
#include "temporal/range.h" #include "temporal/range.h"
@ -349,8 +349,8 @@ protected:
PBD::ScopedConnectionList region_drop_references_connections; PBD::ScopedConnectionList region_drop_references_connections;
DataType _type; DataType _type;
uint32_t _sort_id; uint32_t _sort_id;
mutable GATOMIC_QUAL gint block_notifications; mutable std::atomic<int> block_notifications;
mutable GATOMIC_QUAL gint ignore_state_changes; mutable std::atomic<int> ignore_state_changes;
std::set<std::shared_ptr<Region> > pending_adds; std::set<std::shared_ptr<Region> > pending_adds;
std::set<std::shared_ptr<Region> > pending_removes; std::set<std::shared_ptr<Region> > pending_removes;
RegionList pending_bounds; RegionList pending_bounds;
@ -391,8 +391,8 @@ protected:
bool holding_state () const bool holding_state () const
{ {
return g_atomic_int_get (&block_notifications) != 0 || return block_notifications.load () != 0 ||
g_atomic_int_get (&ignore_state_changes) != 0; ignore_state_changes.load () != 0;
} }
void delay_notifications (); void delay_notifications ();

View file

@ -24,13 +24,13 @@
#ifndef __ardour_plugin_insert_h__ #ifndef __ardour_plugin_insert_h__
#define __ardour_plugin_insert_h__ #define __ardour_plugin_insert_h__
#include <atomic>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "pbd/stack_allocator.h" #include "pbd/stack_allocator.h"
#include "pbd/timing.h" #include "pbd/timing.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h" #include "ardour/ardour.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
@ -446,8 +446,8 @@ private:
CtrlOutMap _control_outputs; CtrlOutMap _control_outputs;
PBD::TimingStats _timing_stats; PBD::TimingStats _timing_stats;
GATOMIC_QUAL gint _stat_reset; std::atomic<int> _stat_reset;
GATOMIC_QUAL gint _flush; std::atomic<int> _flush;
}; };
} // namespace ARDOUR } // namespace ARDOUR

View file

@ -20,6 +20,7 @@
#ifndef _libardour_port_engine_shared_h_ #ifndef _libardour_port_engine_shared_h_
#define _libardour_port_engine_shared_h_ #define _libardour_port_engine_shared_h_
#include <atomic>
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
@ -29,7 +30,6 @@
#include "pbd/natsort.h" #include "pbd/natsort.h"
#include "pbd/rcu.h" #include "pbd/rcu.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
#include "ardour/port_engine.h" #include "ardour/port_engine.h"
@ -195,7 +195,7 @@ protected:
std::vector<PortConnectData *> _port_connection_queue; std::vector<PortConnectData *> _port_connection_queue;
pthread_mutex_t _port_callback_mutex; pthread_mutex_t _port_callback_mutex;
GATOMIC_QUAL gint _port_change_flag; /* atomic */ std::atomic<int> _port_change_flag; /* atomic */
void port_connect_callback (const std::string& a, const std::string& b, bool conn) { void port_connect_callback (const std::string& a, const std::string& b, bool conn) {
pthread_mutex_lock (&_port_callback_mutex); pthread_mutex_lock (&_port_callback_mutex);
@ -204,7 +204,7 @@ protected:
} }
void port_connect_add_remove_callback () { void port_connect_add_remove_callback () {
g_atomic_int_set (&_port_change_flag, 1); _port_change_flag.store (1);
} }
virtual void update_system_port_latencies (); virtual void update_system_port_latencies ();

View file

@ -20,6 +20,7 @@
#ifndef __libardour_port_manager_h__ #ifndef __libardour_port_manager_h__
#define __libardour_port_manager_h__ #define __libardour_port_manager_h__
#include <atomic>
#include <cstdint> #include <cstdint>
#include <exception> #include <exception>
#include <map> #include <map>
@ -30,7 +31,6 @@
#include "pbd/natsort.h" #include "pbd/natsort.h"
#include "pbd/rcu.h" #include "pbd/rcu.h"
#include "pbd/ringbuffer.h" #include "pbd/ringbuffer.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/chan_count.h" #include "ardour/chan_count.h"
#include "ardour/midiport_manager.h" #include "ardour/midiport_manager.h"
@ -387,7 +387,7 @@ private:
SerializedRCUManager<AudioInputPorts> _audio_input_ports; SerializedRCUManager<AudioInputPorts> _audio_input_ports;
SerializedRCUManager<MIDIInputPorts> _midi_input_ports; SerializedRCUManager<MIDIInputPorts> _midi_input_ports;
GATOMIC_QUAL gint _reset_meters; std::atomic<int> _reset_meters;
}; };
} // namespace ARDOUR } // namespace ARDOUR

View file

@ -24,12 +24,12 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <stdint.h> #include <atomic>
#include <cstdint>
#include "pbd/signals.h" #include "pbd/signals.h"
#include "pbd/stateful.h" #include "pbd/stateful.h"
#include "pbd/properties.h" #include "pbd/properties.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
@ -287,7 +287,7 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
static PBD::PropertyChange _pending_static_changes; static PBD::PropertyChange _pending_static_changes;
static Glib::Threads::Mutex static_signal_lock; static Glib::Threads::Mutex static_signal_lock;
static GATOMIC_QUAL gint _change_signal_suspended; static std::atomic<int> _change_signal_suspended;
static int selection_counter; static int selection_counter;
}; };

View file

@ -24,6 +24,7 @@
#ifndef __ardour_route_h__ #ifndef __ardour_route_h__
#define __ardour_route_h__ #define __ardour_route_h__
#include <atomic>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <list> #include <list>
@ -39,7 +40,6 @@
#include "pbd/stateful.h" #include "pbd/stateful.h"
#include "pbd/controllable.h" #include "pbd/controllable.h"
#include "pbd/destructible.h" #include "pbd/destructible.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h" #include "ardour/ardour.h"
#include "ardour/gain_control.h" #include "ardour/gain_control.h"
@ -681,9 +681,9 @@ protected:
}; };
ProcessorList _pending_processor_order; ProcessorList _pending_processor_order;
GATOMIC_QUAL gint _pending_process_reorder; // atomic std::atomic<int> _pending_process_reorder; // atomic
GATOMIC_QUAL gint _pending_listen_change; // atomic std::atomic<int> _pending_listen_change; // atomic
GATOMIC_QUAL gint _pending_signals; // atomic std::atomic<int> _pending_signals; // atomic
MeterPoint _meter_point; MeterPoint _meter_point;
MeterPoint _pending_meter_point; MeterPoint _pending_meter_point;

View file

@ -89,7 +89,7 @@ class LIBARDOUR_API CoreSelection : public PBD::Stateful {
private: private:
mutable Glib::Threads::RWLock _lock; mutable Glib::Threads::RWLock _lock;
GATOMIC_QUAL gint _selection_order; std::atomic<int> _selection_order;
Session& session; Session& session;

View file

@ -36,6 +36,7 @@
#include "libardour-config.h" #include "libardour-config.h"
#endif #endif
#include <atomic>
#include <exception> #include <exception>
#include <list> #include <list>
#include <map> #include <map>
@ -54,6 +55,7 @@
#include <ltc.h> #include <ltc.h>
#include "pbd/atomic.h"
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/event_loop.h" #include "pbd/event_loop.h"
#include "pbd/file_archive.h" #include "pbd/file_archive.h"
@ -62,7 +64,6 @@
#include "pbd/statefuldestructible.h" #include "pbd/statefuldestructible.h"
#include "pbd/signals.h" #include "pbd/signals.h"
#include "pbd/undo.h" #include "pbd/undo.h"
#include "pbd/g_atomic_compat.h"
#include "lua/luastate.h" #include "lua/luastate.h"
@ -395,7 +396,7 @@ public:
} }
RecordState record_status() const { RecordState record_status() const {
return (RecordState) g_atomic_int_get (const_cast<GATOMIC_QUAL gint*> (&_record_status)); return _record_status.load();
} }
bool actively_recording () const { bool actively_recording () const {
@ -665,10 +666,10 @@ public:
class StateProtector { class StateProtector {
public: public:
StateProtector (Session* s) : _session (s) { StateProtector (Session* s) : _session (s) {
g_atomic_int_inc (&s->_suspend_save); PBD::atomic_inc (s->_suspend_save);
} }
~StateProtector () { ~StateProtector () {
if (g_atomic_int_dec_and_test (&_session->_suspend_save)) { if (PBD::atomic_dec_and_test (_session->_suspend_save)) {
while (_session->_save_queued) { while (_session->_save_queued) {
_session->_save_queued = false; _session->_save_queued = false;
_session->save_state (""); _session->save_state ("");
@ -1414,8 +1415,8 @@ private:
int create (const std::string& mix_template, BusProfile const *, bool unnamed); int create (const std::string& mix_template, BusProfile const *, bool unnamed);
void destroy (); void destroy ();
static guint _name_id_counter; static std::atomic<unsigned int> _name_id_counter;
static void init_name_id_counter (guint n); static void init_name_id_counter (unsigned int n);
static unsigned int name_id_counter (); static unsigned int name_id_counter ();
std::shared_ptr<SessionPlaylists> _playlists; std::shared_ptr<SessionPlaylists> _playlists;
@ -1434,8 +1435,8 @@ private:
samplecnt_t _base_sample_rate; // sample-rate of the session at creation time, "native" SR samplecnt_t _base_sample_rate; // sample-rate of the session at creation time, "native" SR
samplecnt_t _current_sample_rate; // this includes video pullup offset samplecnt_t _current_sample_rate; // this includes video pullup offset
samplepos_t _transport_sample; samplepos_t _transport_sample;
GATOMIC_QUAL gint _seek_counter; std::atomic<int> _seek_counter;
GATOMIC_QUAL gint _butler_seek_counter; std::atomic<int> _butler_seek_counter;
Location* _session_range_location; ///< session range, or 0 if there is nothing in the session yet Location* _session_range_location; ///< session range, or 0 if there is nothing in the session yet
bool _session_range_is_free; bool _session_range_is_free;
bool _silent; bool _silent;
@ -1470,8 +1471,8 @@ private:
std::string _missing_file_replacement; std::string _missing_file_replacement;
mutable GATOMIC_QUAL gint _processing_prohibited; mutable std::atomic<int> _processing_prohibited;
mutable GATOMIC_QUAL gint _record_status; mutable std::atomic<RecordState> _record_status;
void add_monitor_section (); void add_monitor_section ();
void remove_monitor_section (); void remove_monitor_section ();
@ -1500,8 +1501,8 @@ private:
samplecnt_t calc_preroll_subcycle (samplecnt_t) const; samplecnt_t calc_preroll_subcycle (samplecnt_t) const;
void block_processing(); void block_processing();
void unblock_processing() { g_atomic_int_set (&_processing_prohibited, 0); } void unblock_processing() { _processing_prohibited.store (0); }
bool processing_blocked() const { return g_atomic_int_get (&_processing_prohibited); } bool processing_blocked() const { return _processing_prohibited.load (); }
static const samplecnt_t bounce_chunk_size; static const samplecnt_t bounce_chunk_size;
@ -1603,7 +1604,7 @@ private:
StateOfTheState _state_of_the_state; StateOfTheState _state_of_the_state;
friend class StateProtector; friend class StateProtector;
GATOMIC_QUAL gint _suspend_save; std::atomic<int> _suspend_save;
volatile bool _save_queued; volatile bool _save_queued;
volatile bool _save_queued_pending; volatile bool _save_queued_pending;
@ -1649,9 +1650,9 @@ private:
static const PostTransportWork ProcessCannotProceedMask = PostTransportWork (PostTransportAudition); static const PostTransportWork ProcessCannotProceedMask = PostTransportWork (PostTransportAudition);
GATOMIC_QUAL gint _post_transport_work; /* accessed only atomic ops */ std::atomic<PostTransportWork> _post_transport_work; /* accessed only atomic ops */
PostTransportWork post_transport_work() const { return (PostTransportWork) g_atomic_int_get (const_cast<GATOMIC_QUAL gint*> (&_post_transport_work)); } PostTransportWork post_transport_work() const { return _post_transport_work.load(); }
void set_post_transport_work (PostTransportWork ptw) { g_atomic_int_set (&_post_transport_work, (gint) ptw); } void set_post_transport_work (PostTransportWork ptw) { _post_transport_work.store (ptw); }
void add_post_transport_work (PostTransportWork ptw); void add_post_transport_work (PostTransportWork ptw);
void schedule_playback_buffering_adjustment (); void schedule_playback_buffering_adjustment ();
@ -1734,7 +1735,7 @@ private:
void auto_connect_thread_terminate (); void auto_connect_thread_terminate ();
pthread_t _auto_connect_thread; pthread_t _auto_connect_thread;
gint _ac_thread_active; std::atomic<int> _ac_thread_active;
pthread_mutex_t _auto_connect_mutex; pthread_mutex_t _auto_connect_mutex;
pthread_cond_t _auto_connect_cond; pthread_cond_t _auto_connect_cond;
@ -1769,7 +1770,7 @@ private:
typedef std::queue<AutoConnectRequest> AutoConnectQueue; typedef std::queue<AutoConnectRequest> AutoConnectQueue;
Glib::Threads::Mutex _auto_connect_queue_lock; Glib::Threads::Mutex _auto_connect_queue_lock;
AutoConnectQueue _auto_connect_queue; AutoConnectQueue _auto_connect_queue;
GATOMIC_QUAL guint _latency_recompute_pending; std::atomic<unsigned int> _latency_recompute_pending;
void get_physical_ports (std::vector<std::string>& inputs, std::vector<std::string>& outputs, DataType type, void get_physical_ports (std::vector<std::string>& inputs, std::vector<std::string>& outputs, DataType type,
MidiPortFlags include = MidiPortFlags (0), MidiPortFlags include = MidiPortFlags (0),
@ -1890,8 +1891,8 @@ private:
OnlyLoop, OnlyLoop,
}; };
GATOMIC_QUAL gint _punch_or_loop; // enum PunchLoopLock std::atomic<PunchLoopLock> _punch_or_loop;
GATOMIC_QUAL gint _current_usecs_per_track; std::atomic<int> _current_usecs_per_track;
bool punch_active () const; bool punch_active () const;
void unset_punch (); void unset_punch ();
@ -2095,8 +2096,8 @@ private:
std::string get_best_session_directory_for_new_audio (); std::string get_best_session_directory_for_new_audio ();
mutable GATOMIC_QUAL gint _playback_load; mutable std::atomic<int> _playback_load;
mutable GATOMIC_QUAL gint _capture_load; mutable std::atomic<int> _capture_load;
/* I/O bundles */ /* I/O bundles */
@ -2223,8 +2224,8 @@ private:
mutable bool have_looped; ///< Used in \ref audible_sample mutable bool have_looped; ///< Used in \ref audible_sample
void update_route_record_state (); void update_route_record_state ();
GATOMIC_QUAL gint _have_rec_enabled_track; std::atomic<int> _have_rec_enabled_track;
GATOMIC_QUAL gint _have_rec_disabled_track; std::atomic<int> _have_rec_disabled_track;
static int ask_about_playlist_deletion (std::shared_ptr<Playlist>); static int ask_about_playlist_deletion (std::shared_ptr<Playlist>);
@ -2271,7 +2272,7 @@ private:
uint32_t _step_editors; uint32_t _step_editors;
/** true if timecode transmission by the transport is suspended, otherwise false */ /** true if timecode transmission by the transport is suspended, otherwise false */
mutable GATOMIC_QUAL gint _suspend_timecode_transmission; mutable std::atomic<int> _suspend_timecode_transmission;
void start_time_changed (samplepos_t); void start_time_changed (samplepos_t);
void end_time_changed (samplepos_t); void end_time_changed (samplepos_t);
@ -2301,8 +2302,8 @@ private:
void ensure_route_presentation_info_gap (PresentationInfo::order_t, uint32_t gap_size); void ensure_route_presentation_info_gap (PresentationInfo::order_t, uint32_t gap_size);
friend class ProcessorChangeBlocker; friend class ProcessorChangeBlocker;
GATOMIC_QUAL gint _ignore_route_processor_changes; std::atomic<int> _ignore_route_processor_changes;
GATOMIC_QUAL gint _ignored_a_processor_change; std::atomic<int> _ignored_a_processor_change;
MidiClockTicker* midi_clock; MidiClockTicker* midi_clock;
@ -2351,7 +2352,7 @@ private:
std::string unnamed_file_name () const; std::string unnamed_file_name () const;
GATOMIC_QUAL gint _update_pretty_names; std::atomic<int> _update_pretty_names;
void setup_thread_local_variables (); void setup_thread_local_variables ();
void cue_marker_change (Location*); void cue_marker_change (Location*);

View file

@ -23,6 +23,7 @@
#ifndef __ardour_source_h__ #ifndef __ardour_source_h__
#define __ardour_source_h__ #define __ardour_source_h__
#include <atomic>
#include <memory> #include <memory>
#include <string> #include <string>
#include <set> #include <set>
@ -32,7 +33,6 @@
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include "pbd/statefuldestructible.h" #include "pbd/statefuldestructible.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h" #include "ardour/ardour.h"
#include "ardour/session_object.h" #include "ardour/session_object.h"
@ -140,7 +140,7 @@ public:
virtual void inc_use_count (); virtual void inc_use_count ();
virtual void dec_use_count (); virtual void dec_use_count ();
int use_count() const { return g_atomic_int_get (const_cast<GATOMIC_QUAL gint*> (&_use_count)); } int use_count() const { return g_atomic_int_get (const_cast<std::atomic<int>*> (&_use_count)); }
bool used() const { return use_count() > 0; } bool used() const { return use_count() > 0; }
uint32_t level() const { return _level; } uint32_t level() const { return _level; }
@ -162,7 +162,7 @@ public:
timepos_t _natural_position; timepos_t _natural_position;
bool _have_natural_position; bool _have_natural_position;
bool _analysed; bool _analysed;
GATOMIC_QUAL gint _use_count; /* atomic */ std::atomic<int> _use_count; /* atomic */
uint32_t _level; /* how deeply nested is this source w.r.t a disk file */ uint32_t _level; /* how deeply nested is this source w.r.t a disk file */
std::string _ancestor_name; std::string _ancestor_name;
std::string _captured_for; std::string _captured_for;

View file

@ -19,6 +19,7 @@
#ifndef _ardour_vst3_host_h_ #ifndef _ardour_vst3_host_h_
#define _ardour_vst3_host_h_ #define _ardour_vst3_host_h_
#include <atomic>
#include <cstdint> #include <cstdint>
#include <map> #include <map>
#include <memory> #include <memory>
@ -27,8 +28,6 @@
#include <glib.h> #include <glib.h>
#include "pbd/g_atomic_compat.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
#include "vst3/vst3.h" #include "vst3/vst3.h"
@ -155,7 +154,7 @@ public:
uint32 PLUGIN_API release () SMTG_OVERRIDE; uint32 PLUGIN_API release () SMTG_OVERRIDE;
private: private:
GATOMIC_QUAL gint _cnt; // atomic std::atomic<int> _cnt; // atomic
}; };
class LIBARDOUR_API HostAttributeList : public Vst::IAttributeList, public RefObject class LIBARDOUR_API HostAttributeList : public Vst::IAttributeList, public RefObject

View file

@ -760,7 +760,7 @@ AUPlugin::default_value (uint32_t port)
samplecnt_t samplecnt_t
AUPlugin::plugin_latency () const AUPlugin::plugin_latency () const
{ {
guint lat = g_atomic_int_get (&_current_latency);; guint lat = _current_latency.load ();;
if (lat == UINT_MAX) { if (lat == UINT_MAX) {
lat = unit->Latency() * _session.sample_rate(); lat = unit->Latency() * _session.sample_rate();
g_atomic_int_set (&_current_latency, lat); g_atomic_int_set (&_current_latency, lat);

View file

@ -75,7 +75,7 @@ using namespace PBD;
AudioEngine* AudioEngine::_instance = 0; AudioEngine* AudioEngine::_instance = 0;
static GATOMIC_QUAL gint audioengine_thread_cnt = 1; static std::atomic<int> audioengine_thread_cnt (1);
#ifdef SILENCE_AFTER #ifdef SILENCE_AFTER
#define SILENCE_AFTER_SECONDS 600 #define SILENCE_AFTER_SECONDS 600
@ -112,12 +112,12 @@ AudioEngine::AudioEngine ()
start_hw_event_processing(); start_hw_event_processing();
discover_backends (); discover_backends ();
g_atomic_int_set (&_hw_reset_request_count, 0); _hw_reset_request_count.store (0);
g_atomic_int_set (&_pending_playback_latency_callback, 0); _pending_playback_latency_callback.store (0);
g_atomic_int_set (&_pending_capture_latency_callback, 0); _pending_capture_latency_callback.store (0);
g_atomic_int_set (&_hw_devicelist_update_count, 0); _hw_devicelist_update_count.store (0);
g_atomic_int_set (&_stop_hw_reset_processing, 0); _stop_hw_reset_processing.store (0);
g_atomic_int_set (&_stop_hw_devicelist_processing, 0); _stop_hw_devicelist_processing.store (0);
} }
AudioEngine::~AudioEngine () AudioEngine::~AudioEngine ()
@ -305,10 +305,12 @@ AudioEngine::process_callback (pframes_t nframes)
if (_session && !_session->processing_blocked ()) { if (_session && !_session->processing_blocked ()) {
bool lp = false; bool lp = false;
bool lc = false; bool lc = false;
if (g_atomic_int_compare_and_exchange (&_pending_playback_latency_callback, 1, 0)) { int canderef (1);
if (_pending_playback_latency_callback.compare_exchange_strong (canderef, 0)) {
lp = true; lp = true;
} }
if (g_atomic_int_compare_and_exchange (&_pending_capture_latency_callback, 1, 0)) { canderef = 1;
if (_pending_capture_latency_callback.compare_exchange_strong (canderef, 0)) {
lc = true; lc = true;
} }
if (lp || lc) { if (lp || lc) {
@ -653,14 +655,14 @@ void
AudioEngine::request_backend_reset() AudioEngine::request_backend_reset()
{ {
Glib::Threads::Mutex::Lock guard (_reset_request_lock); Glib::Threads::Mutex::Lock guard (_reset_request_lock);
g_atomic_int_inc (&_hw_reset_request_count); _hw_reset_request_count.fetch_add (1);
_hw_reset_condition.signal (); _hw_reset_condition.signal ();
} }
int int
AudioEngine::backend_reset_requested() AudioEngine::backend_reset_requested()
{ {
return g_atomic_int_get (&_hw_reset_request_count); return _hw_reset_request_count.load ();
} }
void void
@ -671,14 +673,14 @@ AudioEngine::do_reset_backend()
Glib::Threads::Mutex::Lock guard (_reset_request_lock); Glib::Threads::Mutex::Lock guard (_reset_request_lock);
while (!g_atomic_int_get (&_stop_hw_reset_processing)) { while (!_stop_hw_reset_processing.load ()) {
if (g_atomic_int_get (&_hw_reset_request_count) != 0 && _backend) { if (_hw_reset_request_count.load () != 0 && _backend) {
_reset_request_lock.unlock(); _reset_request_lock.unlock();
Glib::Threads::RecMutex::Lock pl (_state_lock); Glib::Threads::RecMutex::Lock pl (_state_lock);
g_atomic_int_dec_and_test (&_hw_reset_request_count); PBD::atomic_dec_and_test (_hw_reset_request_count);
std::cout << "AudioEngine::RESET::Reset request processing. Requests left: " << _hw_reset_request_count << std::endl; std::cout << "AudioEngine::RESET::Reset request processing. Requests left: " << _hw_reset_request_count << std::endl;
DeviceResetStarted(); // notify about device reset to be started DeviceResetStarted(); // notify about device reset to be started
@ -720,7 +722,7 @@ void
AudioEngine::request_device_list_update() AudioEngine::request_device_list_update()
{ {
Glib::Threads::Mutex::Lock guard (_devicelist_update_lock); Glib::Threads::Mutex::Lock guard (_devicelist_update_lock);
g_atomic_int_inc (&_hw_devicelist_update_count); _hw_devicelist_update_count.fetch_add (1);
_hw_devicelist_update_condition.signal (); _hw_devicelist_update_condition.signal ();
} }
@ -734,13 +736,13 @@ AudioEngine::do_devicelist_update()
while (!_stop_hw_devicelist_processing) { while (!_stop_hw_devicelist_processing) {
if (g_atomic_int_get (&_hw_devicelist_update_count)) { if (_hw_devicelist_update_count.load ()) {
_devicelist_update_lock.unlock(); _devicelist_update_lock.unlock();
Glib::Threads::RecMutex::Lock pl (_state_lock); Glib::Threads::RecMutex::Lock pl (_state_lock);
g_atomic_int_dec_and_test (&_hw_devicelist_update_count); PBD::atomic_dec_and_test (_hw_devicelist_update_count);
DeviceListChanged (); /* EMIT SIGNAL */ DeviceListChanged (); /* EMIT SIGNAL */
_devicelist_update_lock.lock(); _devicelist_update_lock.lock();
@ -756,14 +758,14 @@ void
AudioEngine::start_hw_event_processing() AudioEngine::start_hw_event_processing()
{ {
if (_hw_reset_event_thread == 0) { if (_hw_reset_event_thread == 0) {
g_atomic_int_set (&_hw_reset_request_count, 0); _hw_reset_request_count.store (0);
g_atomic_int_set (&_stop_hw_reset_processing, 0); _stop_hw_reset_processing.store (0);
_hw_reset_event_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_reset_backend, this)); _hw_reset_event_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_reset_backend, this));
} }
if (_hw_devicelist_update_thread == 0) { if (_hw_devicelist_update_thread == 0) {
g_atomic_int_set (&_hw_devicelist_update_count, 0); _hw_devicelist_update_count.store (0);
g_atomic_int_set (&_stop_hw_devicelist_processing, 0); _stop_hw_devicelist_processing.store (0);
_hw_devicelist_update_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_devicelist_update, this)); _hw_devicelist_update_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_devicelist_update, this));
} }
} }
@ -773,16 +775,16 @@ void
AudioEngine::stop_hw_event_processing() AudioEngine::stop_hw_event_processing()
{ {
if (_hw_reset_event_thread) { if (_hw_reset_event_thread) {
g_atomic_int_set (&_stop_hw_reset_processing, 1); _stop_hw_reset_processing.store (1);
g_atomic_int_set (&_hw_reset_request_count, 0); _hw_reset_request_count.store (0);
_hw_reset_condition.signal (); _hw_reset_condition.signal ();
_hw_reset_event_thread->join (); _hw_reset_event_thread->join ();
_hw_reset_event_thread = 0; _hw_reset_event_thread = 0;
} }
if (_hw_devicelist_update_thread) { if (_hw_devicelist_update_thread) {
g_atomic_int_set (&_stop_hw_devicelist_processing, 1); _stop_hw_devicelist_processing.store (1);
g_atomic_int_set (&_hw_devicelist_update_count, 0); _hw_devicelist_update_count.store (0);
_hw_devicelist_update_condition.signal (); _hw_devicelist_update_condition.signal ();
_hw_devicelist_update_thread->join (); _hw_devicelist_update_thread->join ();
_hw_devicelist_update_thread = 0; _hw_devicelist_update_thread = 0;
@ -798,8 +800,8 @@ AudioEngine::set_session (Session *s)
if (_session) { if (_session) {
_init_countdown = std::max (4, (int)(_backend->sample_rate () / _backend->buffer_size ()) / 8); _init_countdown = std::max (4, (int)(_backend->sample_rate () / _backend->buffer_size ()) / 8);
g_atomic_int_set (&_pending_playback_latency_callback, 0); _pending_playback_latency_callback.store (0);
g_atomic_int_set (&_pending_capture_latency_callback, 0); _pending_capture_latency_callback.store (0);
} }
} }
@ -1451,7 +1453,7 @@ AudioEngine::thread_init_callback (void* arg)
pthread_set_name (X_("audioengine")); pthread_set_name (X_("audioengine"));
const int thread_num = g_atomic_int_add (&audioengine_thread_cnt, 1); const int thread_num = audioengine_thread_cnt.fetch_add (1);
const string thread_name = string_compose (X_("AudioEngine %1"), thread_num); const string thread_name = string_compose (X_("AudioEngine %1"), thread_num);
SessionEvent::create_per_thread_pool (thread_name, 512); SessionEvent::create_per_thread_pool (thread_name, 512);
@ -1525,9 +1527,9 @@ void
AudioEngine::queue_latency_update (bool for_playback) AudioEngine::queue_latency_update (bool for_playback)
{ {
if (for_playback) { if (for_playback) {
g_atomic_int_set (&_pending_playback_latency_callback, 1); _pending_playback_latency_callback.store (1);
} else { } else {
g_atomic_int_set (&_pending_capture_latency_callback, 1); _pending_capture_latency_callback.store (1);
} }
} }

View file

@ -62,7 +62,7 @@ Auditioner::Auditioner (Session& s)
, _queue_panic (false) , _queue_panic (false)
, _import_position (0) , _import_position (0)
{ {
g_atomic_int_set (&_auditioning, 0); _auditioning.store (0);
} }
int int
@ -365,7 +365,7 @@ Auditioner::update_controls (BufferSet const& bufs)
void void
Auditioner::audition_region (std::shared_ptr<Region> region, bool loop) Auditioner::audition_region (std::shared_ptr<Region> region, bool loop)
{ {
if (g_atomic_int_get (&_auditioning)) { if (_auditioning.load ()) {
/* don't go via session for this, because we are going /* don't go via session for this, because we are going
to remain active. to remain active.
*/ */
@ -483,7 +483,7 @@ Auditioner::audition_region (std::shared_ptr<Region> region, bool loop)
current_sample = offset.samples(); current_sample = offset.samples();
g_atomic_int_set (&_auditioning, 1); _auditioning.store (1);
} }
void void
@ -503,7 +503,7 @@ Auditioner::play_audition (samplecnt_t nframes)
samplecnt_t this_nframes; samplecnt_t this_nframes;
int ret; int ret;
if (g_atomic_int_get (&_auditioning) == 0) { if (_auditioning.load () == 0) {
silence (nframes); silence (nframes);
if (_reload_synth) { if (_reload_synth) {
unload_synth (false); unload_synth (false);
@ -581,12 +581,12 @@ Auditioner::play_audition (samplecnt_t nframes)
void void
Auditioner::cancel_audition () { Auditioner::cancel_audition () {
g_atomic_int_set (&_auditioning, 0); _auditioning.store (0);
} }
bool bool
Auditioner::auditioning() const { Auditioner::auditioning() const {
return g_atomic_int_get (&_auditioning); return _auditioning.load ();
} }
void void

View file

@ -66,7 +66,7 @@ AutomationList::AutomationList (const Evoral::Parameter& id, const Evoral::Param
, _before (0) , _before (0)
{ {
_state = Off; _state = Off;
g_atomic_int_set (&_touching, 0); _touching.store (0);
_interpolation = default_interpolation (); _interpolation = default_interpolation ();
create_curve_if_necessary(); create_curve_if_necessary();
@ -80,7 +80,7 @@ AutomationList::AutomationList (const Evoral::Parameter& id, Temporal::TimeDomai
, _before (0) , _before (0)
{ {
_state = Off; _state = Off;
g_atomic_int_set (&_touching, 0); _touching.store (0);
_interpolation = default_interpolation (); _interpolation = default_interpolation ();
create_curve_if_necessary(); create_curve_if_necessary();
@ -123,7 +123,7 @@ AutomationList::AutomationList (const XMLNode& node, Evoral::Parameter id)
: ControlList(id, ARDOUR::ParameterDescriptor(id), Temporal::AudioTime) /* domain may change in ::set_state */ : ControlList(id, ARDOUR::ParameterDescriptor(id), Temporal::AudioTime) /* domain may change in ::set_state */
, _before (0) , _before (0)
{ {
g_atomic_int_set (&_touching, 0); _touching.store (0);
_interpolation = default_interpolation (); _interpolation = default_interpolation ();
_state = Off; _state = Off;
@ -185,7 +185,7 @@ AutomationList::operator= (const AutomationList& other)
*/ */
ControlList::operator= (other); ControlList::operator= (other);
_state = other._state; _state = other._state;
_touching = other._touching; _touching.store (other._touching);
ControlList::thaw (); ControlList::thaw ();
} }
@ -264,20 +264,20 @@ AutomationList::write_pass_finished (timepos_t const & when, double thinning_fac
void void
AutomationList::start_touch (timepos_t const & when) AutomationList::start_touch (timepos_t const & when)
{ {
g_atomic_int_set (&_touching, 1); _touching.store (1);
} }
void void
AutomationList::stop_touch (timepos_t const & /* not used */) AutomationList::stop_touch (timepos_t const & /* not used */)
{ {
if (g_atomic_int_get (&_touching) == 0) { if (_touching.load () == 0) {
/* this touch has already been stopped (probably by Automatable::transport_stopped), /* this touch has already been stopped (probably by Automatable::transport_stopped),
so we've nothing to do. so we've nothing to do.
*/ */
return; return;
} }
g_atomic_int_set (&_touching, 0); _touching.store (0);
} }
/* _before may be owned by the undo stack, /* _before may be owned by the undo stack,

View file

@ -60,7 +60,7 @@ Butler::Butler (Session& s)
, pool_trash (16) , pool_trash (16)
, _xthread (true) , _xthread (true)
{ {
g_atomic_int_set (&should_do_transport_work, 0); should_do_transport_work.store (0);
SessionEvent::pool->set_trash (&pool_trash); SessionEvent::pool->set_trash (&pool_trash);
/* catch future changes to parameters */ /* catch future changes to parameters */
@ -381,7 +381,7 @@ void
Butler::schedule_transport_work () Butler::schedule_transport_work ()
{ {
DEBUG_TRACE (DEBUG::Butler, "requesting more transport work\n"); DEBUG_TRACE (DEBUG::Butler, "requesting more transport work\n");
g_atomic_int_inc (&should_do_transport_work); should_do_transport_work.fetch_add (1);
summon (); summon ();
} }
@ -432,7 +432,7 @@ Butler::wait_until_finished ()
bool bool
Butler::transport_work_requested () const Butler::transport_work_requested () const
{ {
return g_atomic_int_get (&should_do_transport_work); return should_do_transport_work.load ();
} }
void void

View file

@ -29,7 +29,7 @@ CircularSampleBuffer::CircularSampleBuffer (samplecnt_t size)
void void
CircularSampleBuffer::write (Sample const* buf, samplecnt_t n_samples) CircularSampleBuffer::write (Sample const* buf, samplecnt_t n_samples)
{ {
guint ws = _rb.write_space (); ssize_t ws = (ssize_t) _rb.write_space ();
if (ws < n_samples) { if (ws < n_samples) {
/* overwrite old data (consider a spinlock wrt ::read) */ /* overwrite old data (consider a spinlock wrt ::read) */
_rb.increment_read_idx (n_samples - ws); _rb.increment_read_idx (n_samples - ws);
@ -40,7 +40,7 @@ CircularSampleBuffer::write (Sample const* buf, samplecnt_t n_samples)
void void
CircularSampleBuffer::silence (samplecnt_t n_samples) CircularSampleBuffer::silence (samplecnt_t n_samples)
{ {
guint ws = _rb.write_space (); ssize_t ws = (ssize_t) _rb.write_space ();
if (ws < n_samples) { if (ws < n_samples) {
/* overwrite old data (consider a spinlock wrt ::read) */ /* overwrite old data (consider a spinlock wrt ::read) */
_rb.increment_read_idx (n_samples - ws); _rb.increment_read_idx (n_samples - ws);
@ -129,8 +129,8 @@ CircularEventBuffer::~CircularEventBuffer ()
void void
CircularEventBuffer::reset () { CircularEventBuffer::reset () {
g_atomic_int_set (&_idx, 0); _idx.store (0);
g_atomic_int_set (&_ack, 0); _ack.store (0);
memset ((void*)_buf, 0, _size * sizeof (Event)); memset ((void*)_buf, 0, _size * sizeof (Event));
} }
@ -139,23 +139,24 @@ CircularEventBuffer::write (uint8_t const* buf, size_t size)
{ {
Event e (buf, size); Event e (buf, size);
guint write_idx = g_atomic_int_get (&_idx); guint write_idx = _idx.load ();
memcpy (&_buf[write_idx], &e, sizeof (Event)); memcpy (&_buf[write_idx], &e, sizeof (Event));
write_idx = (write_idx + 1) & _size_mask; write_idx = (write_idx + 1) & _size_mask;
g_atomic_int_set (&_idx, write_idx); g_atomic_int_set (&_idx, write_idx);
g_atomic_int_set (&_ack, 1); _ack.store (1);
} }
bool bool
CircularEventBuffer::read (EventList& l) CircularEventBuffer::read (EventList& l)
{ {
guint to_read = _size_mask; guint to_read = _size_mask;
if (!g_atomic_int_compare_and_exchange (&_ack, 1, 0)) { int canderef (1);
if (!_ack.compare_exchange_strong (canderef, 0)) {
return false; return false;
} }
l.clear (); l.clear ();
guint priv_idx = g_atomic_int_get (&_idx); guint priv_idx = _idx.load ();
while (priv_idx > 0) { while (priv_idx > 0) {
--priv_idx; --priv_idx;
--to_read; --to_read;

View file

@ -52,7 +52,7 @@ PBD::Signal0<void> DiskReader::Underrun;
Sample* DiskReader::_sum_buffer = 0; Sample* DiskReader::_sum_buffer = 0;
Sample* DiskReader::_mixdown_buffer = 0; Sample* DiskReader::_mixdown_buffer = 0;
gain_t* DiskReader::_gain_buffer = 0; gain_t* DiskReader::_gain_buffer = 0;
GATOMIC_QUAL gint DiskReader::_no_disk_output (0); std::atomic<int> DiskReader::_no_disk_output (0);
DiskReader::Declicker DiskReader::loop_declick_in; DiskReader::Declicker DiskReader::loop_declick_in;
DiskReader::Declicker DiskReader::loop_declick_out; DiskReader::Declicker DiskReader::loop_declick_out;
samplecnt_t DiskReader::loop_fade_length (0); samplecnt_t DiskReader::loop_fade_length (0);
@ -68,7 +68,7 @@ DiskReader::DiskReader (Session& s, Track& t, string const& str, Temporal::Time
{ {
file_sample[DataType::AUDIO] = 0; file_sample[DataType::AUDIO] = 0;
file_sample[DataType::MIDI] = 0; file_sample[DataType::MIDI] = 0;
g_atomic_int_set (&_pending_overwrite, 0); _pending_overwrite.store (OverwriteReason (0));
} }
DiskReader::~DiskReader () DiskReader::~DiskReader ()
@ -263,7 +263,7 @@ DiskReader::use_playlist (DataType dt, std::shared_ptr<Playlist> playlist)
* the diskstream for the very first time - the input changed handling will * the diskstream for the very first time - the input changed handling will
* take care of the buffer refill. */ * take care of the buffer refill. */
if (!(g_atomic_int_get (&_pending_overwrite) & PlaylistChanged) || prior_playlist) { if (!(_pending_overwrite.load () & PlaylistChanged) || prior_playlist) {
_session.request_overwrite_buffer (_track.shared_ptr (), PlaylistChanged); _session.request_overwrite_buffer (_track.shared_ptr (), PlaylistChanged);
} }
@ -279,7 +279,7 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
sampleoffset_t disk_samples_to_consume; sampleoffset_t disk_samples_to_consume;
MonitorState ms = _track.monitoring_state (); MonitorState ms = _track.monitoring_state ();
const bool midi_only = (c->empty() || !_playlists[DataType::AUDIO]); const bool midi_only = (c->empty() || !_playlists[DataType::AUDIO]);
bool no_disk_output = g_atomic_int_get (&_no_disk_output) != 0; bool no_disk_output = _no_disk_output.load () != 0;
if (!check_active()) { if (!check_active()) {
return; return;
@ -547,7 +547,7 @@ DiskReader::configuration_changed ()
bool bool
DiskReader::pending_overwrite () const DiskReader::pending_overwrite () const
{ {
return g_atomic_int_get (&_pending_overwrite) != 0; return _pending_overwrite.load () != 0;
} }
void void
@ -613,9 +613,9 @@ DiskReader::set_pending_overwrite (OverwriteReason why)
} }
while (true) { while (true) {
OverwriteReason current = OverwriteReason (g_atomic_int_get (&_pending_overwrite)); OverwriteReason current = OverwriteReason (_pending_overwrite.load ());
OverwriteReason next = OverwriteReason (current | why); OverwriteReason next = OverwriteReason (current | why);
if (g_atomic_int_compare_and_exchange (&_pending_overwrite, current, next)) { if (_pending_overwrite.compare_exchange_strong (current, next)) {
break; break;
} }
} }
@ -787,23 +787,23 @@ DiskReader::overwrite_existing_buffers ()
{ {
/* called from butler thread */ /* called from butler thread */
DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1 overwriting existing buffers at %2 (because %3%4%5\n", owner ()->name (), overwrite_sample, std::hex, g_atomic_int_get (&_pending_overwrite), std::dec)); DEBUG_TRACE (DEBUG::DiskIO, string_compose ("%1 overwriting existing buffers at %2 (because %3%4%5\n", owner ()->name (), overwrite_sample, std::hex, _pending_overwrite.load (), std::dec));
bool ret = true; bool ret = true;
if (g_atomic_int_get (&_pending_overwrite) & (PlaylistModified | LoopDisabled | LoopChanged | PlaylistChanged)) { if (_pending_overwrite.load () & (PlaylistModified | LoopDisabled | LoopChanged | PlaylistChanged)) {
if (_playlists[DataType::AUDIO] && !overwrite_existing_audio ()) { if (_playlists[DataType::AUDIO] && !overwrite_existing_audio ()) {
ret = false; ret = false;
} }
} }
if (g_atomic_int_get (&_pending_overwrite) & (PlaylistModified | PlaylistChanged)) { if (_pending_overwrite.load () & (PlaylistModified | PlaylistChanged)) {
if (_playlists[DataType::MIDI] && !overwrite_existing_midi ()) { if (_playlists[DataType::MIDI] && !overwrite_existing_midi ()) {
ret = false; ret = false;
} }
} }
g_atomic_int_set (&_pending_overwrite, 0); _pending_overwrite.store (OverwriteReason (0));
return ret; return ret;
} }
@ -843,7 +843,7 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
} }
} }
g_atomic_int_set (&_pending_overwrite, 0); _pending_overwrite.store (OverwriteReason (0));
DEBUG_TRACE (DEBUG::DiskIO, string_compose ("DiskReader::seek %1 %2 -> %3 refill=%4\n", owner ()->name ().c_str (), playback_sample, sample, complete_refill)); DEBUG_TRACE (DEBUG::DiskIO, string_compose ("DiskReader::seek %1 %2 -> %3 refill=%4\n", owner ()->name ().c_str (), playback_sample, sample, complete_refill));
@ -1456,7 +1456,7 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
target = &dst; target = &dst;
} }
if (g_atomic_int_get (&_no_disk_output)) { if (_no_disk_output.load ()) {
return; return;
} }
@ -1547,7 +1547,7 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
void void
DiskReader::inc_no_disk_output () DiskReader::inc_no_disk_output ()
{ {
g_atomic_int_inc (&_no_disk_output); _no_disk_output.fetch_add (1);
} }
void void
@ -1560,9 +1560,9 @@ DiskReader::dec_no_disk_output ()
*/ */
do { do {
gint v = g_atomic_int_get (&_no_disk_output); gint v = _no_disk_output.load ();
if (v > 0) { if (v > 0) {
if (g_atomic_int_compare_and_exchange (&_no_disk_output, v, v - 1)) { if (_no_disk_output.compare_exchange_strong (v, v - 1)) {
break; break;
} }
} else { } else {

View file

@ -37,6 +37,7 @@
#include "ardour/session.h" #include "ardour/session.h"
#include "ardour/smf_source.h" #include "ardour/smf_source.h"
#include "pbd/atomic.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
using namespace ARDOUR; using namespace ARDOUR;
@ -64,10 +65,10 @@ DiskWriter::DiskWriter (Session& s, Track& t, string const & str, DiskIOProcesso
DiskIOProcessor::init (); DiskIOProcessor::init ();
_xruns.reserve (128); _xruns.reserve (128);
g_atomic_int_set (&_record_enabled, 0); _record_enabled.store (0);
g_atomic_int_set (&_record_safe, 0); _record_safe.store (0);
g_atomic_int_set (&_samples_pending_write, 0); _samples_pending_write.store (0);
g_atomic_int_set (&_num_captured_loops, 0); _num_captured_loops.store (0);
} }
DiskWriter::~DiskWriter () DiskWriter::~DiskWriter ()
@ -285,25 +286,25 @@ DiskWriter::calculate_record_range (Temporal::OverlapType ot, samplepos_t transp
void void
DiskWriter::engage_record_enable () DiskWriter::engage_record_enable ()
{ {
g_atomic_int_set (&_record_enabled, 1); _record_enabled.store (1);
} }
void void
DiskWriter::disengage_record_enable () DiskWriter::disengage_record_enable ()
{ {
g_atomic_int_set (&_record_enabled, 0); _record_enabled.store (0);
} }
void void
DiskWriter::engage_record_safe () DiskWriter::engage_record_safe ()
{ {
g_atomic_int_set (&_record_safe, 1); _record_safe.store (1);
} }
void void
DiskWriter::disengage_record_safe () DiskWriter::disengage_record_safe ()
{ {
g_atomic_int_set (&_record_safe, 0); _record_safe.store (0);
} }
/** Get the start position (in session samples) of the nth capture in the current pass */ /** Get the start position (in session samples) of the nth capture in the current pass */
@ -541,8 +542,8 @@ DiskWriter::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
_midi_write_source->mark_write_starting_now (start, _capture_captured); _midi_write_source->mark_write_starting_now (start, _capture_captured);
} }
g_atomic_int_set (&_samples_pending_write, 0); _samples_pending_write.store (0);
g_atomic_int_set (&_num_captured_loops, 0); _num_captured_loops.store (0);
_was_recording = true; _was_recording = true;
@ -646,7 +647,7 @@ DiskWriter::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
reconstruct their actual time; future clever MIDI looping should reconstruct their actual time; future clever MIDI looping should
probably be implemented in the source instead of here. probably be implemented in the source instead of here.
*/ */
const samplecnt_t loop_offset = g_atomic_int_get (&_num_captured_loops) * loop_length.samples(); const samplecnt_t loop_offset = _num_captured_loops.load () * loop_length.samples();
const samplepos_t event_time = start_sample + loop_offset - _accumulated_capture_offset + ev.time(); const samplepos_t event_time = start_sample + loop_offset - _accumulated_capture_offset + ev.time();
if (event_time < 0 || event_time < _first_recordable_sample) { if (event_time < 0 || event_time < _first_recordable_sample) {
/* Event out of range, skip */ /* Event out of range, skip */
@ -672,7 +673,7 @@ DiskWriter::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
} }
} }
g_atomic_int_add (&_samples_pending_write, nframes); _samples_pending_write.fetch_add ((int) nframes);
if (buf.size() != 0) { if (buf.size() != 0) {
Glib::Threads::Mutex::Lock lm (_gui_feed_buffer_mutex, Glib::Threads::TRY_LOCK); Glib::Threads::Mutex::Lock lm (_gui_feed_buffer_mutex, Glib::Threads::TRY_LOCK);
@ -764,7 +765,7 @@ DiskWriter::finish_capture (std::shared_ptr<ChannelList> c)
timepos_t loop_end; timepos_t loop_end;
timecnt_t loop_length; timecnt_t loop_length;
get_location_times (_loop_location, &loop_start, &loop_end, &loop_length); get_location_times (_loop_location, &loop_start, &loop_end, &loop_length);
ci->loop_offset = g_atomic_int_get (&_num_captured_loops) * loop_length.samples(); ci->loop_offset = _num_captured_loops.load () * loop_length.samples();
} else { } else {
ci->loop_offset = 0; ci->loop_offset = 0;
} }
@ -1003,7 +1004,7 @@ DiskWriter::do_flush (RunContext ctxt, bool force_flush)
if (_midi_write_source && _midi_buf) { if (_midi_write_source && _midi_buf) {
const samplecnt_t total = g_atomic_int_get(&_samples_pending_write); const samplecnt_t total = _samples_pending_write.load ();
if (total == 0 || if (total == 0 ||
_midi_buf->read_space() == 0 || _midi_buf->read_space() == 0 ||
@ -1039,7 +1040,7 @@ DiskWriter::do_flush (RunContext ctxt, bool force_flush)
error << string_compose(_("MidiDiskstream %1: cannot write to disk"), id()) << endmsg; error << string_compose(_("MidiDiskstream %1: cannot write to disk"), id()) << endmsg;
return -1; return -1;
} }
g_atomic_int_add(&_samples_pending_write, -to_write); _samples_pending_write.fetch_sub (to_write);
} }
} }
@ -1347,7 +1348,7 @@ DiskWriter::loop (samplepos_t transport_sample)
the Source and/or entirely after the capture is finished. the Source and/or entirely after the capture is finished.
*/ */
if (_was_recording) { if (_was_recording) {
g_atomic_int_add (&_num_captured_loops, 1); _num_captured_loops.fetch_add (1);
} }
} }

View file

@ -200,13 +200,13 @@ void
FFMPEGFileImportableSource::reset () FFMPEGFileImportableSource::reset ()
{ {
// TODO: actually signal did_read_data to unblock // TODO: actually signal did_read_data to unblock
g_atomic_int_set (&_ffmpeg_should_terminate, 1); _ffmpeg_should_terminate.store (1);
delete _ffmpeg_exec; delete _ffmpeg_exec;
_ffmpeg_exec = 0; _ffmpeg_exec = 0;
_ffmpeg_conn.disconnect (); _ffmpeg_conn.disconnect ();
_buffer.reset (); _buffer.reset ();
_read_pos = 0; _read_pos = 0;
g_atomic_int_set (&_ffmpeg_should_terminate, 0); _ffmpeg_should_terminate.store (0);
} }
void void
@ -221,7 +221,7 @@ FFMPEGFileImportableSource::did_read_data (std::string data, size_t size)
const char* cur = data.data (); const char* cur = data.data ();
while (n_samples > 0) { while (n_samples > 0) {
if (g_atomic_int_get (&_ffmpeg_should_terminate)) { if (_ffmpeg_should_terminate.load ()) {
break; break;
} }

View file

@ -70,11 +70,11 @@ Graph::Graph (Session& session)
, _graph_empty (true) , _graph_empty (true)
, _graph_chain (0) , _graph_chain (0)
{ {
g_atomic_int_set (&_terminal_refcnt, 0); _terminal_refcnt.store (0);
g_atomic_int_set (&_terminate, 0); _terminate.store (0);
g_atomic_int_set (&_n_workers, 0); _n_workers.store (0);
g_atomic_int_set (&_idle_thread_cnt, 0); _idle_thread_cnt.store (0);
g_atomic_int_set (&_trigger_queue_size, 0); _trigger_queue_size.store (0);
/* pre-allocate memory */ /* pre-allocate memory */
_trigger_queue.reserve (1024); _trigger_queue.reserve (1024);
@ -124,7 +124,7 @@ Graph::reset_thread_list ()
} }
/* Allow threads to run */ /* Allow threads to run */
g_atomic_int_set (&_terminate, 0); _terminate.store (0);
if (AudioEngine::instance ()->create_process_thread (boost::bind (&Graph::main_thread, this)) != 0) { if (AudioEngine::instance ()->create_process_thread (boost::bind (&Graph::main_thread, this)) != 0) {
throw failed_constructor (); throw failed_constructor ();
@ -153,7 +153,7 @@ Graph::session_going_away ()
drop_threads (); drop_threads ();
/* now drop all references on the nodes. */ /* now drop all references on the nodes. */
g_atomic_int_set (&_trigger_queue_size, 0); _trigger_queue_size.store (0);
_trigger_queue.clear (); _trigger_queue.clear ();
_graph_chain = 0; _graph_chain = 0;
} }
@ -162,7 +162,7 @@ void
Graph::drop_threads () Graph::drop_threads ()
{ {
/* Flag threads to terminate */ /* Flag threads to terminate */
g_atomic_int_set (&_terminate, 1); _terminate.store (1);
/* Wake-up sleeping threads */ /* Wake-up sleeping threads */
guint tc = g_atomic_uint_get (&_idle_thread_cnt); guint tc = g_atomic_uint_get (&_idle_thread_cnt);
@ -177,8 +177,8 @@ Graph::drop_threads ()
/* join process threads */ /* join process threads */
AudioEngine::instance ()->join_process_threads (); AudioEngine::instance ()->join_process_threads ();
g_atomic_int_set (&_n_workers, 0); _n_workers.store (0);
g_atomic_int_set (&_idle_thread_cnt, 0); _idle_thread_cnt.store (0);
/* signal main process thread if it's waiting for an already terminated thread */ /* signal main process thread if it's waiting for an already terminated thread */
_callback_done_sem.signal (); _callback_done_sem.signal ();
@ -224,7 +224,7 @@ Graph::prep ()
/* Trigger the initial nodes for processing, which are the ones at the `input' end */ /* Trigger the initial nodes for processing, which are the ones at the `input' end */
for (auto const& i : _graph_chain->_init_trigger_list) { for (auto const& i : _graph_chain->_init_trigger_list) {
g_atomic_int_inc (&_trigger_queue_size); _trigger_queue_size.fetch_add (1);
_trigger_queue.push_back (i.get ()); _trigger_queue.push_back (i.get ());
} }
} }
@ -232,7 +232,7 @@ Graph::prep ()
void void
Graph::trigger (ProcessNode* n) Graph::trigger (ProcessNode* n)
{ {
g_atomic_int_inc (&_trigger_queue_size); _trigger_queue_size.fetch_add (1);
_trigger_queue.push_back (n); _trigger_queue.push_back (n);
} }
@ -242,7 +242,7 @@ Graph::trigger (ProcessNode* n)
void void
Graph::reached_terminal_node () Graph::reached_terminal_node ()
{ {
if (g_atomic_int_dec_and_test (&_terminal_refcnt)) { if (PBD::atomic_dec_and_test (_terminal_refcnt)) {
again: again:
/* We have run all the nodes that are at the `output' end of /* We have run all the nodes that are at the `output' end of
@ -268,7 +268,7 @@ Graph::reached_terminal_node ()
/* Block until the a process callback */ /* Block until the a process callback */
_callback_start_sem.wait (); _callback_start_sem.wait ();
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
return; return;
} }
@ -280,7 +280,7 @@ Graph::reached_terminal_node ()
*/ */
prep (); prep ();
if (_graph_empty && !g_atomic_int_get (&_terminate)) { if (_graph_empty && !_terminate.load ()) {
goto again; goto again;
} }
/* .. continue in worker-thread */ /* .. continue in worker-thread */
@ -293,7 +293,7 @@ Graph::run_one ()
{ {
ProcessNode* to_run = NULL; ProcessNode* to_run = NULL;
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
return; return;
} }
@ -315,19 +315,19 @@ Graph::run_one ()
while (!to_run) { while (!to_run) {
/* Wait for work, fall asleep */ /* Wait for work, fall asleep */
g_atomic_int_inc (&_idle_thread_cnt); _idle_thread_cnt.fetch_add (1);
assert (g_atomic_uint_get (&_idle_thread_cnt) <= g_atomic_uint_get (&_n_workers)); assert (g_atomic_uint_get (&_idle_thread_cnt) <= g_atomic_uint_get (&_n_workers));
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 goes to sleep\n", pthread_name ())); DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 goes to sleep\n", pthread_name ()));
_execution_sem.wait (); _execution_sem.wait ();
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
return; return;
} }
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 is awake\n", pthread_name ())); DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 is awake\n", pthread_name ()));
g_atomic_int_dec_and_test (&_idle_thread_cnt); PBD::atomic_dec_and_test (_idle_thread_cnt);
/* Try to find some work to do */ /* Try to find some work to do */
_trigger_queue.pop_front (to_run); _trigger_queue.pop_front (to_run);
@ -342,7 +342,7 @@ Graph::run_one ()
Temporal::TempoMap::fetch (); Temporal::TempoMap::fetch ();
/* Process the graph-node */ /* Process the graph-node */
g_atomic_int_dec_and_test (&_trigger_queue_size); PBD::atomic_dec_and_test (_trigger_queue_size);
to_run->run (_graph_chain); to_run->run (_graph_chain);
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 has finished run_one()\n", pthread_name ())); DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 has finished run_one()\n", pthread_name ()));
@ -351,7 +351,7 @@ Graph::run_one ()
void void
Graph::helper_thread () Graph::helper_thread ()
{ {
g_atomic_int_inc (&_n_workers); _n_workers.fetch_add (1);
guint id = g_atomic_uint_get (&_n_workers); guint id = g_atomic_uint_get (&_n_workers);
/* This is needed for ARDOUR::Session requests called from rt-processors /* This is needed for ARDOUR::Session requests called from rt-processors
@ -370,7 +370,7 @@ Graph::helper_thread ()
pt->get_buffers (); pt->get_buffers ();
while (!g_atomic_int_get (&_terminate)) { while (!_terminate.load ()) {
run_one (); run_one ();
} }
@ -406,7 +406,7 @@ again:
DEBUG_TRACE (DEBUG::ProcessThreads, "main thread is awake\n"); DEBUG_TRACE (DEBUG::ProcessThreads, "main thread is awake\n");
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
pt->drop_buffers (); pt->drop_buffers ();
delete (pt); delete (pt);
return; return;
@ -416,14 +416,14 @@ again:
* (later this is done by Graph_reached_terminal_node) */ * (later this is done by Graph_reached_terminal_node) */
prep (); prep ();
if (_graph_empty && !g_atomic_int_get (&_terminate)) { if (_graph_empty && !_terminate.load ()) {
_callback_done_sem.signal (); _callback_done_sem.signal ();
DEBUG_TRACE (DEBUG::ProcessThreads, "main thread sees graph done, goes back to sleep\n"); DEBUG_TRACE (DEBUG::ProcessThreads, "main thread sees graph done, goes back to sleep\n");
goto again; goto again;
} }
/* After setup, the main-thread just becomes a normal worker */ /* After setup, the main-thread just becomes a normal worker */
while (!g_atomic_int_get (&_terminate)) { while (!_terminate.load ()) {
run_one (); run_one ();
} }
@ -436,7 +436,7 @@ Graph::process_routes (std::shared_ptr<GraphChain> chain, pframes_t nframes, sam
{ {
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("graph execution from %1 to %2 = %3\n", start_sample, end_sample, nframes)); DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("graph execution from %1 to %2 = %3\n", start_sample, end_sample, nframes));
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
return 0; return 0;
} }
@ -464,7 +464,7 @@ Graph::routes_no_roll (std::shared_ptr<GraphChain> chain, pframes_t nframes, sam
{ {
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("no-roll graph execution from %1 to %2 = %3\n", start_sample, end_sample, nframes)); DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("no-roll graph execution from %1 to %2 = %3\n", start_sample, end_sample, nframes));
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
return 0; return 0;
} }
@ -491,7 +491,7 @@ Graph::silence_routes (std::shared_ptr<GraphChain> chain, pframes_t nframes)
{ {
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("silence graph execution from %1 for = %2\n", nframes)); DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("silence graph execution from %1 for = %2\n", nframes));
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
return 0; return 0;
} }
@ -514,7 +514,7 @@ Graph::process_io_plugs (std::shared_ptr<GraphChain> chain, pframes_t nframes, s
{ {
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("IOPlug graph execution at %1 for %2\n", start_sample, nframes)); DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("IOPlug graph execution at %1 for %2\n", start_sample, nframes));
if (g_atomic_int_get (&_terminate)) { if (_terminate.load ()) {
return 0; return 0;
} }

View file

@ -18,6 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "pbd/atomic.h"
#include "ardour/graphnode.h" #include "ardour/graphnode.h"
#include "ardour/graph.h" #include "ardour/graph.h"
#include "ardour/route.h" #include "ardour/route.h"
@ -49,7 +51,7 @@ GraphActivision::init_refcount (GraphChain const* const g) const
GraphNode::GraphNode (std::shared_ptr<Graph> graph) GraphNode::GraphNode (std::shared_ptr<Graph> graph)
: _graph (graph) : _graph (graph)
{ {
g_atomic_int_set (&_refcount, 0); _refcount.store (0);
} }
void void
@ -71,7 +73,7 @@ void
GraphNode::trigger () GraphNode::trigger ()
{ {
/* check if we can run */ /* check if we can run */
if (g_atomic_int_dec_and_test (&_refcount)) { if (PBD::atomic_dec_and_test (_refcount)) {
#if 0 // TODO optimize: remove prep() #if 0 // TODO optimize: remove prep()
/* reset reference count for next cycle */ /* reset reference count for next cycle */
g_atomic_int_set (&_refcount, _init_refcount[chain]); g_atomic_int_set (&_refcount, _init_refcount[chain]);

View file

@ -48,8 +48,8 @@ IOPlug::IOPlug (Session& s, std::shared_ptr<Plugin> p, bool pre)
, _plugin_signal_latency (0) , _plugin_signal_latency (0)
, _window_proxy (0) , _window_proxy (0)
{ {
g_atomic_int_set (&_stat_reset, 0); _stat_reset.store (0);
g_atomic_int_set (&_reset_meters, 0); _reset_meters.store (0);
if (_plugin) { if (_plugin) {
setup (); setup ();
@ -430,7 +430,8 @@ IOPlug::connect_and_run (samplepos_t start, pframes_t n_samples)
Temporal::TempoMap::update_thread_tempo_map (); Temporal::TempoMap::update_thread_tempo_map ();
assert (n_samples > 0); assert (n_samples > 0);
if (g_atomic_int_compare_and_exchange (&_stat_reset, 1, 0)) { int canderef (1);
if (_stat_reset.compare_exchange_strong (canderef, 0)) {
_timing_stats.reset (); _timing_stats.reset ();
} }
@ -466,7 +467,8 @@ IOPlug::connect_and_run (samplepos_t start, pframes_t n_samples)
PortSet& ports (_output->ports()); PortSet& ports (_output->ports());
if (_pre) { if (_pre) {
const bool reset = g_atomic_int_compare_and_exchange (&_reset_meters, 1, 0); canderef = 1;
const bool reset = _reset_meters.compare_exchange_strong (canderef, 0);
samplecnt_t const rate = _session.nominal_sample_rate (); samplecnt_t const rate = _session.nominal_sample_rate ();
auto a = _audio_input_ports.begin (); auto a = _audio_input_ports.begin ();
@ -503,7 +505,7 @@ IOPlug::connect_and_run (samplepos_t start, pframes_t n_samples)
void void
IOPlug::reset_input_meters () IOPlug::reset_input_meters ()
{ {
g_atomic_int_set (&_reset_meters, 1); _reset_meters.store (1);
} }
bool bool
@ -515,7 +517,7 @@ IOPlug::get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, double& a
void void
IOPlug::clear_stats () IOPlug::clear_stats ()
{ {
g_atomic_int_set (&_stat_reset, 1); _stat_reset.store (1);
} }
std::shared_ptr<ReadOnlyControl> std::shared_ptr<ReadOnlyControl>

View file

@ -53,8 +53,8 @@ PeakMeter::PeakMeter (Session& s, const std::string& name)
_meter_type = MeterPeak; _meter_type = MeterPeak;
_bufcnt = 0; _bufcnt = 0;
g_atomic_int_set (&_reset_dpm, 1); _reset_dpm.store (1);
g_atomic_int_set (&_reset_max, 1); _reset_max.store (1);
} }
PeakMeter::~PeakMeter () PeakMeter::~PeakMeter ()
@ -96,9 +96,10 @@ PeakMeter::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end
return; return;
} }
const bool reset_max = g_atomic_int_compare_and_exchange (&_reset_max, 1, 0); int canderef (1);
const bool reset_max = _reset_max.compare_exchange_strong (canderef, 0);
/* max-peak is set from DPM's peak-buffer, so DPM also needs to be reset in sync */ /* max-peak is set from DPM's peak-buffer, so DPM also needs to be reset in sync */
const bool reset_dpm = g_atomic_int_compare_and_exchange (&_reset_dpm, 1, 0) || reset_max; const bool reset_dpm = _reset_dpm.compare_exchange_strong (canderef, 0) || reset_max;
const uint32_t n_audio = min (current_meters.n_audio (), bufs.count ().n_audio ()); const uint32_t n_audio = min (current_meters.n_audio (), bufs.count ().n_audio ());
const uint32_t n_midi = min (current_meters.n_midi (), bufs.count ().n_midi ()); const uint32_t n_midi = min (current_meters.n_midi (), bufs.count ().n_midi ());
@ -202,7 +203,7 @@ void
PeakMeter::reset () PeakMeter::reset ()
{ {
if (_active || _pending_active) { if (_active || _pending_active) {
g_atomic_int_set (&_reset_dpm, 1); _reset_dpm.store (1);
} else { } else {
for (size_t i = 0; i < _peak_power.size (); ++i) { for (size_t i = 0; i < _peak_power.size (); ++i) {
_peak_power[i] = -std::numeric_limits<float>::infinity (); _peak_power[i] = -std::numeric_limits<float>::infinity ();
@ -227,7 +228,7 @@ void
PeakMeter::reset_max () PeakMeter::reset_max ()
{ {
if (_active || _pending_active) { if (_active || _pending_active) {
g_atomic_int_set (&_reset_max, 1); _reset_max.store (1);
return; return;
} }
for (size_t i = 0; i < _max_peak_signal.size (); ++i) { for (size_t i = 0; i < _max_peak_signal.size (); ++i) {
@ -361,7 +362,7 @@ PeakMeter::set_max_channels (const ChanCount& chn)
float float
PeakMeter::meter_level (uint32_t n, MeterType type) PeakMeter::meter_level (uint32_t n, MeterType type)
{ {
if (g_atomic_int_get (&_reset_max)) { if (_reset_max.load ()) {
if (n < current_meters.n_midi () && type != MeterMaxPeak) { if (n < current_meters.n_midi () && type != MeterMaxPeak) {
return 0; return 0;
} else { } else {

View file

@ -53,7 +53,7 @@ Pannable::Pannable (Session& s, Temporal::TimeDomain td)
{ {
//boost_debug_shared_ptr_mark_interesting (this, "pannable"); //boost_debug_shared_ptr_mark_interesting (this, "pannable");
g_atomic_int_set (&_touching, 0); _touching.store (0);
add_control (pan_azimuth_control); add_control (pan_azimuth_control);
add_control (pan_elevation_control); add_control (pan_elevation_control);
@ -161,7 +161,7 @@ Pannable::start_touch (timepos_t const & when)
ac->alist()->start_touch (when); ac->alist()->start_touch (when);
} }
} }
g_atomic_int_set (&_touching, 1); _touching.store (1);
} }
void void
@ -175,7 +175,7 @@ Pannable::stop_touch (timepos_t const & when)
ac->alist()->stop_touch (when); ac->alist()->stop_touch (when);
} }
} }
g_atomic_int_set (&_touching, 0); _touching.store (0);
} }
XMLNode& XMLNode&

View file

@ -321,8 +321,8 @@ Playlist::init (bool hide)
add_property (regions); add_property (regions);
_xml_node_name = X_("Playlist"); _xml_node_name = X_("Playlist");
g_atomic_int_set (&block_notifications, 0); block_notifications.store (0);
g_atomic_int_set (&ignore_state_changes, 0); ignore_state_changes.store (0);
pending_contents_change = false; pending_contents_change = false;
pending_layering = false; pending_layering = false;
first_set_state = true; first_set_state = true;
@ -430,28 +430,28 @@ void
Playlist::freeze_locked () Playlist::freeze_locked ()
{ {
delay_notifications (); delay_notifications ();
g_atomic_int_inc (&ignore_state_changes); ignore_state_changes.fetch_add (1);
} }
/** @param from_undo true if this thaw is triggered by the end of an undo on this playlist */ /** @param from_undo true if this thaw is triggered by the end of an undo on this playlist */
void void
Playlist::thaw (bool from_undo) Playlist::thaw (bool from_undo)
{ {
g_atomic_int_dec_and_test (&ignore_state_changes); PBD::atomic_dec_and_test (ignore_state_changes);
release_notifications (from_undo); release_notifications (from_undo);
} }
void void
Playlist::delay_notifications () Playlist::delay_notifications ()
{ {
g_atomic_int_inc (&block_notifications); block_notifications.fetch_add (1);
} }
/** @param from_undo true if this release is triggered by the end of an undo on this playlist */ /** @param from_undo true if this release is triggered by the end of an undo on this playlist */
void void
Playlist::release_notifications (bool from_undo) Playlist::release_notifications (bool from_undo)
{ {
if (g_atomic_int_dec_and_test (&block_notifications)) { if (PBD::atomic_dec_and_test (block_notifications)) {
flush_notifications (from_undo); flush_notifications (from_undo);
} }
} }

View file

@ -92,8 +92,8 @@ PluginInsert::PluginInsert (Session& s, Temporal::TimeDomain td, std::shared_ptr
, _bypass_port (UINT32_MAX) , _bypass_port (UINT32_MAX)
, _inverted_bypass_enable (false) , _inverted_bypass_enable (false)
{ {
g_atomic_int_set (&_stat_reset, 0); _stat_reset.store (0);
g_atomic_int_set (&_flush, 0); _flush.store (0);
/* the first is the master */ /* the first is the master */
if (plug) { if (plug) {
@ -748,7 +748,7 @@ PluginInsert::deactivate ()
void void
PluginInsert::flush () PluginInsert::flush ()
{ {
g_atomic_int_set (&_flush, 1); _flush.store (1);
} }
void void
@ -1272,7 +1272,8 @@ PluginInsert::silence (samplecnt_t nframes, samplepos_t start_sample)
ChanCount maxbuf = ChanCount::max (natural_input_streams (), natural_output_streams()); ChanCount maxbuf = ChanCount::max (natural_input_streams (), natural_output_streams());
_session.get_scratch_buffers (maxbuf, true).silence (nframes, 0); _session.get_scratch_buffers (maxbuf, true).silence (nframes, 0);
if (g_atomic_int_compare_and_exchange (&_stat_reset, 1, 0)) { int canderef;
if (_stat_reset.compare_exchange_strong (canderef, 0)) {
_timing_stats.reset (); _timing_stats.reset ();
} }
@ -1300,7 +1301,8 @@ PluginInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sa
_sidechain->run (bufs, start_sample, end_sample, speed, nframes, true); _sidechain->run (bufs, start_sample, end_sample, speed, nframes, true);
} }
if (g_atomic_int_compare_and_exchange (&_stat_reset, 1, 0)) { int canderef (1);
if (_stat_reset.compare_exchange_strong (canderef, 0)) {
_timing_stats.reset (); _timing_stats.reset ();
} }
@ -1311,7 +1313,8 @@ PluginInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sa
} }
} }
if (check_active () && g_atomic_int_compare_and_exchange (&_flush, 1, 0)) { canderef = 1;
if (check_active () && _flush.compare_exchange_strong (canderef, 0)) {
for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
(*i)->flush (); (*i)->flush ();
} }
@ -3371,7 +3374,7 @@ PluginInsert::get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, dou
void void
PluginInsert::clear_stats () PluginInsert::clear_stats ()
{ {
g_atomic_int_set (&_stat_reset, 1); _stat_reset.store (1);
} }
std::ostream& operator<<(std::ostream& o, const ARDOUR::PluginInsert::Match& m) std::ostream& operator<<(std::ostream& o, const ARDOUR::PluginInsert::Match& m)

View file

@ -272,7 +272,7 @@ PortEngineSharedImpl::PortEngineSharedImpl (PortManager& mgr, std::string const
, _ports (new PortIndex) , _ports (new PortIndex)
, _portregistry (new PortRegistry) , _portregistry (new PortRegistry)
{ {
g_atomic_int_set (&_port_change_flag, 0); _port_change_flag.store (0);
pthread_mutex_init (&_port_callback_mutex, 0); pthread_mutex_init (&_port_callback_mutex, 0);
} }
@ -528,7 +528,7 @@ PortEngineSharedImpl::clear_ports ()
_portmap.flush (); _portmap.flush ();
_portregistry.flush (); _portregistry.flush ();
g_atomic_int_set (&_port_change_flag, 0); _port_change_flag.store (0);
pthread_mutex_lock (&_port_callback_mutex); pthread_mutex_lock (&_port_callback_mutex);
_port_connection_queue.clear(); _port_connection_queue.clear();
pthread_mutex_unlock (&_port_callback_mutex); pthread_mutex_unlock (&_port_callback_mutex);

View file

@ -257,7 +257,7 @@ PortManager::PortManager ()
, _audio_input_ports (new AudioInputPorts) , _audio_input_ports (new AudioInputPorts)
, _midi_input_ports (new MIDIInputPorts) , _midi_input_ports (new MIDIInputPorts)
{ {
g_atomic_int_set (&_reset_meters, 1); _reset_meters.store (1);
load_port_info (); load_port_info ();
} }
@ -1910,7 +1910,7 @@ PortManager::check_for_ambiguous_latency (bool log) const
void void
PortManager::reset_input_meters () PortManager::reset_input_meters ()
{ {
g_atomic_int_set (&_reset_meters, 1); _reset_meters.store (1);
} }
PortManager::AudioInputPorts PortManager::AudioInputPorts
@ -1934,7 +1934,8 @@ PortManager::run_input_meters (pframes_t n_samples, samplecnt_t rate)
return; return;
} }
const bool reset = g_atomic_int_compare_and_exchange (&_reset_meters, 1, 0); int canderef (1);
const bool reset = _reset_meters.compare_exchange_strong (canderef, 0);
_monitor_port.monitor (port_engine (), n_samples); _monitor_port.monitor (port_engine (), n_samples);

View file

@ -23,6 +23,7 @@
#include <cassert> #include <cassert>
#include "pbd/atomic.h"
#include "pbd/debug.h" #include "pbd/debug.h"
#include "pbd/enum_convert.h" #include "pbd/enum_convert.h"
#include "pbd/enumwriter.h" #include "pbd/enumwriter.h"
@ -47,7 +48,7 @@ string PresentationInfo::state_node_name = X_("PresentationInfo");
PBD::Signal1<void,PropertyChange const &> PresentationInfo::Change; PBD::Signal1<void,PropertyChange const &> PresentationInfo::Change;
Glib::Threads::Mutex PresentationInfo::static_signal_lock; Glib::Threads::Mutex PresentationInfo::static_signal_lock;
GATOMIC_QUAL gint PresentationInfo::_change_signal_suspended = 0; std::atomic<int> PresentationInfo::_change_signal_suspended (0);
PBD::PropertyChange PresentationInfo::_pending_static_changes; PBD::PropertyChange PresentationInfo::_pending_static_changes;
int PresentationInfo::selection_counter= 0; int PresentationInfo::selection_counter= 0;
@ -63,7 +64,7 @@ namespace ARDOUR {
void void
PresentationInfo::suspend_change_signal () PresentationInfo::suspend_change_signal ()
{ {
g_atomic_int_add (&_change_signal_suspended, 1); _change_signal_suspended.fetch_add (1);
} }
void void
@ -71,7 +72,7 @@ PresentationInfo::unsuspend_change_signal ()
{ {
Glib::Threads::Mutex::Lock lm (static_signal_lock); Glib::Threads::Mutex::Lock lm (static_signal_lock);
if (g_atomic_int_dec_and_test (&_change_signal_suspended)) { if (PBD::atomic_dec_and_test (_change_signal_suspended)) {
/* atomically grab currently pending flags */ /* atomically grab currently pending flags */
@ -102,7 +103,7 @@ PresentationInfo::send_static_change (const PropertyChange& what_changed)
} }
if (g_atomic_int_get (&_change_signal_suspended)) { if (_change_signal_suspended.load ()) {
Glib::Threads::Mutex::Lock lm (static_signal_lock); Glib::Threads::Mutex::Lock lm (static_signal_lock);
_pending_static_changes.add (what_changed); _pending_static_changes.add (what_changed);
return; return;

View file

@ -141,9 +141,9 @@ Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType
{ {
processor_max_streams.reset(); processor_max_streams.reset();
g_atomic_int_set (&_pending_process_reorder, 0); _pending_process_reorder.store (0);
g_atomic_int_set (&_pending_listen_change, 0); _pending_listen_change.store (0);
g_atomic_int_set (&_pending_signals, 0); _pending_signals.store (0);
} }
std::weak_ptr<Route> std::weak_ptr<Route>
@ -1015,7 +1015,7 @@ Route::add_processors (const ProcessorList& others, std::shared_ptr<Processor> b
ProcessorList::iterator loc; ProcessorList::iterator loc;
std::shared_ptr <PluginInsert> fanout; std::shared_ptr <PluginInsert> fanout;
if (g_atomic_int_get (&_pending_process_reorder) || g_atomic_int_get (&_pending_listen_change)) { if (_pending_process_reorder.load () || _pending_listen_change.load ()) {
/* we need to flush any pending re-order changes */ /* we need to flush any pending re-order changes */
Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
apply_processor_changes_rt (); apply_processor_changes_rt ();
@ -2254,13 +2254,13 @@ Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err
/* If a change is already queued, wait for it /* If a change is already queued, wait for it
* (unless engine is stopped. apply immediately and proceed * (unless engine is stopped. apply immediately and proceed
*/ */
while (g_atomic_int_get (&_pending_process_reorder)) { while (_pending_process_reorder.load ()) {
if (!AudioEngine::instance()->running()) { if (!AudioEngine::instance()->running()) {
DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n"); DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
Glib::Threads::RWLock::WriterLock lm (_processor_lock); Glib::Threads::RWLock::WriterLock lm (_processor_lock);
g_atomic_int_set (&_pending_process_reorder, 0); _pending_process_reorder.store (0);
g_atomic_int_set (&_pending_listen_change, 0); _pending_listen_change.store (0);
apply_processor_order(_pending_processor_order); apply_processor_order(_pending_processor_order);
_pending_processor_order.clear (); _pending_processor_order.clear ();
@ -2309,7 +2309,7 @@ Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err
// _pending_processor_order is protected by _processor_lock // _pending_processor_order is protected by _processor_lock
_pending_processor_order = new_order; _pending_processor_order = new_order;
g_atomic_int_set (&_pending_process_reorder, 1); _pending_process_reorder.store (1);
} }
return 0; return 0;
@ -4102,11 +4102,11 @@ Route::apply_processor_changes_rt ()
bool changed = false; bool changed = false;
if (g_atomic_int_get (&_pending_process_reorder)) { if (_pending_process_reorder.load ()) {
Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK); Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
if (pwl.locked()) { if (pwl.locked()) {
g_atomic_int_set (&_pending_process_reorder, 0); _pending_process_reorder.store (0);
g_atomic_int_set (&_pending_listen_change, 0); _pending_listen_change.store (0);
apply_processor_order (_pending_processor_order); apply_processor_order (_pending_processor_order);
_pending_processor_order.clear (); _pending_processor_order.clear ();
setup_invisible_processors (); setup_invisible_processors ();
@ -4115,10 +4115,10 @@ Route::apply_processor_changes_rt ()
} }
} }
if (g_atomic_int_get (&_pending_listen_change)) { if (_pending_listen_change.load ()) {
Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK); Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
if (pwl.locked()) { if (pwl.locked()) {
g_atomic_int_set (&_pending_listen_change, 0); _pending_listen_change.store (0);
setup_invisible_processors (); setup_invisible_processors ();
changed = true; changed = true;
emissions |= EmitRtProcessorChange; emissions |= EmitRtProcessorChange;
@ -4142,7 +4142,7 @@ Route::apply_processor_changes_rt ()
void void
Route::emit_pending_signals () Route::emit_pending_signals ()
{ {
int sig = g_atomic_int_and (&_pending_signals, 0); int sig = _pending_signals.fetch_and (0);
if (sig & EmitMeterChanged) { if (sig & EmitMeterChanged) {
_meter->emit_configuration_changed(); _meter->emit_configuration_changed();
meter_change (); /* EMIT SIGNAL */ meter_change (); /* EMIT SIGNAL */
@ -4309,7 +4309,7 @@ Route::listen_position_changed ()
if (c == _monitor_send->input_streams () && AudioEngine::instance()->running()) { if (c == _monitor_send->input_streams () && AudioEngine::instance()->running()) {
Glib::Threads::RWLock::ReaderLock lm (_processor_lock); // XXX is this needed? Glib::Threads::RWLock::ReaderLock lm (_processor_lock); // XXX is this needed?
g_atomic_int_set (&_pending_listen_change, 1); _pending_listen_change.store (1);
return; return;
} }

View file

@ -46,7 +46,7 @@ CoreSelection::send_selection_change ()
CoreSelection::CoreSelection (Session& s) CoreSelection::CoreSelection (Session& s)
: session (s) : session (s)
{ {
g_atomic_int_set (&_selection_order, 0); _selection_order.store (0);
} }
CoreSelection::~CoreSelection () CoreSelection::~CoreSelection ()
@ -248,7 +248,7 @@ CoreSelection::set (StripableList& sl)
for (StripableList::iterator s = sl.begin(); s != sl.end(); ++s) { for (StripableList::iterator s = sl.begin(); s != sl.end(); ++s) {
SelectedStripable ss (*s, no_control, g_atomic_int_add (&_selection_order, 1)); SelectedStripable ss (*s, no_control, _selection_order.fetch_add (1));
if (_stripables.insert (ss).second) { if (_stripables.insert (ss).second) {
DEBUG_TRACE (DEBUG::Selection, string_compose ("set:added %1 to s/c selection\n", (*s)->name())); DEBUG_TRACE (DEBUG::Selection, string_compose ("set:added %1 to s/c selection\n", (*s)->name()));
@ -295,7 +295,7 @@ CoreSelection::add (std::shared_ptr<Stripable> s, std::shared_ptr<AutomationCont
{ {
Glib::Threads::RWLock::WriterLock lm (_lock); Glib::Threads::RWLock::WriterLock lm (_lock);
SelectedStripable ss (s, c, g_atomic_int_add (&_selection_order, 1)); SelectedStripable ss (s, c, _selection_order.fetch_add (1));
if (_stripables.insert (ss).second) { if (_stripables.insert (ss).second) {
DEBUG_TRACE (DEBUG::Selection, string_compose ("added %1/%2 to s/c selection\n", s->name(), c)); DEBUG_TRACE (DEBUG::Selection, string_compose ("added %1/%2 to s/c selection\n", s->name(), c));
@ -357,7 +357,7 @@ CoreSelection::set (std::shared_ptr<Stripable> s, std::shared_ptr<AutomationCont
{ {
Glib::Threads::RWLock::WriterLock lm (_lock); Glib::Threads::RWLock::WriterLock lm (_lock);
SelectedStripable ss (s, c, g_atomic_int_add (&_selection_order, 1)); SelectedStripable ss (s, c, _selection_order.fetch_add (1));
if (_stripables.size() == 1 && _stripables.find (ss) != _stripables.end()) { if (_stripables.size() == 1 && _stripables.find (ss) != _stripables.end()) {
return; return;

View file

@ -46,6 +46,7 @@
#include <boost/algorithm/string/erase.hpp> #include <boost/algorithm/string/erase.hpp>
#include "pbd/atomic.h"
#include "pbd/basename.h" #include "pbd/basename.h"
#include "pbd/convert.h" #include "pbd/convert.h"
#include "pbd/error.h" #include "pbd/error.h"
@ -154,7 +155,7 @@ using namespace Temporal;
bool Session::_disable_all_loaded_plugins = false; bool Session::_disable_all_loaded_plugins = false;
bool Session::_bypass_all_loaded_plugins = false; bool Session::_bypass_all_loaded_plugins = false;
guint Session::_name_id_counter = 0; std::atomic<unsigned int> Session::_name_id_counter (0);
PBD::Signal1<void,std::string> Session::Dialog; PBD::Signal1<void,std::string> Session::Dialog;
PBD::Signal0<int> Session::AskAboutPendingState; PBD::Signal0<int> Session::AskAboutPendingState;
@ -329,21 +330,21 @@ Session::Session (AudioEngine &eng,
, _active_cue (-1) , _active_cue (-1)
, tb_with_filled_slots (0) , tb_with_filled_slots (0)
{ {
g_atomic_int_set (&_suspend_save, 0); _suspend_save.store (0);
g_atomic_int_set (&_playback_load, 0); _playback_load.store (0);
g_atomic_int_set (&_capture_load, 0); _capture_load.store (0);
g_atomic_int_set (&_post_transport_work, 0); _post_transport_work.store (PostTransportWork (0));
g_atomic_int_set (&_processing_prohibited, Disabled); _processing_prohibited.store (Disabled);
g_atomic_int_set (&_record_status, Disabled); _record_status.store (Disabled);
g_atomic_int_set (&_punch_or_loop, NoConstraint); _punch_or_loop.store (NoConstraint);
g_atomic_int_set (&_current_usecs_per_track, 1000); _current_usecs_per_track.store (1000);
g_atomic_int_set (&_have_rec_enabled_track, 0); _have_rec_enabled_track.store (0);
g_atomic_int_set (&_have_rec_disabled_track, 1); _have_rec_disabled_track.store (1);
g_atomic_int_set (&_latency_recompute_pending, 0); _latency_recompute_pending.store (0);
g_atomic_int_set (&_suspend_timecode_transmission, 0); _suspend_timecode_transmission.store (0);
g_atomic_int_set (&_update_pretty_names, 0); _update_pretty_names.store (0);
g_atomic_int_set (&_seek_counter, 0); _seek_counter.store (0);
g_atomic_int_set (&_butler_seek_counter, 0); _butler_seek_counter.store (0);
created_with = string_compose ("%1 %2", PROGRAM_NAME, revision); created_with = string_compose ("%1 %2", PROGRAM_NAME, revision);
@ -542,19 +543,19 @@ Session::~Session ()
unsigned int unsigned int
Session::next_name_id () Session::next_name_id ()
{ {
return g_atomic_int_add (&_name_id_counter, 1); return _name_id_counter.fetch_add (1);
} }
unsigned int unsigned int
Session::name_id_counter () Session::name_id_counter ()
{ {
return g_atomic_int_get (&_name_id_counter); return _name_id_counter.load ();
} }
void void
Session::init_name_id_counter (guint n) Session::init_name_id_counter (guint n)
{ {
g_atomic_int_set (&_name_id_counter, n); _name_id_counter.store (n);
} }
int int
@ -874,7 +875,7 @@ Session::destroy ()
void void
Session::block_processing() Session::block_processing()
{ {
g_atomic_int_set (&_processing_prohibited, 1); _processing_prohibited.store (1);
/* processing_blocked() is only checked at the beginning /* processing_blocked() is only checked at the beginning
* of the next cycle. So wait until any ongoing * of the next cycle. So wait until any ongoing
@ -1477,7 +1478,7 @@ Session::punch_active () const
bool bool
Session::punch_is_possible () const Session::punch_is_possible () const
{ {
return g_atomic_int_get (&_punch_or_loop) != OnlyLoop; return _punch_or_loop.load () != OnlyLoop;
} }
bool bool
@ -1489,13 +1490,13 @@ Session::loop_is_possible () const
} }
} }
#endif #endif
return g_atomic_int_get(&_punch_or_loop) != OnlyPunch; return _punch_or_loop.load () != OnlyPunch;
} }
void void
Session::reset_punch_loop_constraint () Session::reset_punch_loop_constraint ()
{ {
if (g_atomic_int_get (&_punch_or_loop) == NoConstraint) { if (_punch_or_loop.load () == NoConstraint) {
return; return;
} }
g_atomic_int_set (&_punch_or_loop, NoConstraint); g_atomic_int_set (&_punch_or_loop, NoConstraint);
@ -1507,7 +1508,8 @@ Session::maybe_allow_only_loop (bool play_loop) {
if (!(get_play_loop () || play_loop)) { if (!(get_play_loop () || play_loop)) {
return false; return false;
} }
bool rv = g_atomic_int_compare_and_exchange (&_punch_or_loop, NoConstraint, OnlyLoop); PunchLoopLock nocon (NoConstraint);
bool rv = _punch_or_loop.compare_exchange_strong (nocon, OnlyLoop);
if (rv) { if (rv) {
PunchLoopConstraintChange (); /* EMIT SIGNAL */ PunchLoopConstraintChange (); /* EMIT SIGNAL */
} }
@ -1523,7 +1525,8 @@ Session::maybe_allow_only_punch () {
if (!punch_active ()) { if (!punch_active ()) {
return false; return false;
} }
bool rv = g_atomic_int_compare_and_exchange (&_punch_or_loop, NoConstraint, OnlyPunch); PunchLoopLock nocon (NoConstraint);
bool rv = _punch_or_loop.compare_exchange_strong (nocon, OnlyPunch);
if (rv) { if (rv) {
PunchLoopConstraintChange (); /* EMIT SIGNAL */ PunchLoopConstraintChange (); /* EMIT SIGNAL */
} }
@ -1927,13 +1930,13 @@ Session::enable_record ()
} }
while (1) { while (1) {
RecordState rs = (RecordState) g_atomic_int_get (&_record_status); RecordState rs = (RecordState) _record_status.load ();
if (rs == Recording) { if (rs == Recording) {
break; break;
} }
if (g_atomic_int_compare_and_exchange (&_record_status, rs, Recording)) { if (_record_status.compare_exchange_strong (rs, Recording)) {
_last_record_location = _transport_sample; _last_record_location = _transport_sample;
send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordStrobe)); send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordStrobe));
@ -1966,7 +1969,7 @@ Session::disable_record (bool rt_context, bool force)
{ {
RecordState rs; RecordState rs;
if ((rs = (RecordState) g_atomic_int_get (&_record_status)) != Disabled) { if ((rs = (RecordState) _record_status.load ()) != Disabled) {
if (!Config->get_latched_record_enable () || force) { if (!Config->get_latched_record_enable () || force) {
g_atomic_int_set (&_record_status, Disabled); g_atomic_int_set (&_record_status, Disabled);
@ -1988,7 +1991,9 @@ Session::disable_record (bool rt_context, bool force)
void void
Session::step_back_from_record () Session::step_back_from_record ()
{ {
if (g_atomic_int_compare_and_exchange (&_record_status, Recording, Enabled)) { RecordState rs (Recording);
if (_record_status.compare_exchange_strong (rs, Enabled)) {
if (Config->get_monitoring_model() == HardwareMonitoring && config.get_auto_input()) { if (Config->get_monitoring_model() == HardwareMonitoring && config.get_auto_input()) {
set_track_monitor_input_status (false); set_track_monitor_input_status (false);
@ -6290,13 +6295,13 @@ Session::add_automation_list(AutomationList *al)
bool bool
Session::have_rec_enabled_track () const Session::have_rec_enabled_track () const
{ {
return g_atomic_int_get (&_have_rec_enabled_track) == 1; return _have_rec_enabled_track.load () == 1;
} }
bool bool
Session::have_rec_disabled_track () const Session::have_rec_disabled_track () const
{ {
return g_atomic_int_get (&_have_rec_disabled_track) == 1; return _have_rec_disabled_track.load () == 1;
} }
/** Update the state of our rec-enabled tracks flag */ /** Update the state of our rec-enabled tracks flag */
@ -6315,11 +6320,11 @@ Session::update_route_record_state ()
++i; ++i;
} }
int const old = g_atomic_int_get (&_have_rec_enabled_track); int const old = _have_rec_enabled_track.load ();
g_atomic_int_set (&_have_rec_enabled_track, i != rl->end () ? 1 : 0); g_atomic_int_set (&_have_rec_enabled_track, i != rl->end () ? 1 : 0);
if (g_atomic_int_get (&_have_rec_enabled_track) != old) { if (_have_rec_enabled_track.load () != old) {
RecordStateChanged (); /* EMIT SIGNAL */ RecordStateChanged (); /* EMIT SIGNAL */
} }
@ -6332,7 +6337,7 @@ Session::update_route_record_state ()
g_atomic_int_set (&_have_rec_disabled_track, i != rl->end () ? 1 : 0); g_atomic_int_set (&_have_rec_disabled_track, i != rl->end () ? 1 : 0);
bool record_arm_state_changed = (old != g_atomic_int_get (&_have_rec_enabled_track) ); bool record_arm_state_changed = (old != _have_rec_enabled_track.load () );
if (record_status() == Recording && record_arm_state_changed ) { if (record_status() == Recording && record_arm_state_changed ) {
RecordArmStateChanged (); RecordArmStateChanged ();
@ -7291,7 +7296,7 @@ Session::auto_connect_thread_wakeup ()
void void
Session::queue_latency_recompute () Session::queue_latency_recompute ()
{ {
g_atomic_int_inc (&_latency_recompute_pending); _latency_recompute_pending.fetch_add (1);
auto_connect_thread_wakeup (); auto_connect_thread_wakeup ();
} }
@ -7394,7 +7399,7 @@ Session::auto_connect (const AutoConnectRequest& ar)
void void
Session::auto_connect_thread_start () Session::auto_connect_thread_start ()
{ {
if (g_atomic_int_get (&_ac_thread_active)) { if (_ac_thread_active.load ()) {
return; return;
} }
@ -7404,16 +7409,16 @@ Session::auto_connect_thread_start ()
} }
lx.release (); lx.release ();
g_atomic_int_set (&_ac_thread_active, 1); _ac_thread_active.store (1);
if (pthread_create (&_auto_connect_thread, NULL, auto_connect_thread, this)) { if (pthread_create (&_auto_connect_thread, NULL, auto_connect_thread, this)) {
g_atomic_int_set (&_ac_thread_active, 0); _ac_thread_active.store (0);
} }
} }
void void
Session::auto_connect_thread_terminate () Session::auto_connect_thread_terminate ()
{ {
if (!g_atomic_int_get (&_ac_thread_active)) { if (!_ac_thread_active.load ()) {
return; return;
} }
@ -7429,7 +7434,7 @@ Session::auto_connect_thread_terminate ()
*/ */
pthread_mutex_lock (&_auto_connect_mutex); pthread_mutex_lock (&_auto_connect_mutex);
g_atomic_int_set (&_ac_thread_active, 0); _ac_thread_active.store (0);
pthread_cond_signal (&_auto_connect_cond); pthread_cond_signal (&_auto_connect_cond);
pthread_mutex_unlock (&_auto_connect_mutex); pthread_mutex_unlock (&_auto_connect_mutex);
@ -7455,7 +7460,7 @@ Session::auto_connect_thread_run ()
pthread_mutex_lock (&_auto_connect_mutex); pthread_mutex_lock (&_auto_connect_mutex);
Glib::Threads::Mutex::Lock lx (_auto_connect_queue_lock); Glib::Threads::Mutex::Lock lx (_auto_connect_queue_lock);
while (g_atomic_int_get (&_ac_thread_active)) { while (_ac_thread_active.load ()) {
if (!_auto_connect_queue.empty ()) { if (!_auto_connect_queue.empty ()) {
/* Why would we need the process lock? /* Why would we need the process lock?
@ -7485,20 +7490,20 @@ Session::auto_connect_thread_run ()
* calls DiskWriter::set_capture_offset () which * calls DiskWriter::set_capture_offset () which
* modifies the capture-offset, which can be a problem. * modifies the capture-offset, which can be a problem.
*/ */
while (g_atomic_int_and (&_latency_recompute_pending, 0)) { while (_latency_recompute_pending.fetch_and (0)) {
update_latency_compensation (false, false); update_latency_compensation (false, false);
if (g_atomic_int_get (&_latency_recompute_pending)) { if (_latency_recompute_pending.load ()) {
Glib::usleep (1000); Glib::usleep (1000);
} }
} }
} }
if (_midi_ports && g_atomic_int_get (&_update_pretty_names)) { if (_midi_ports && _update_pretty_names.load ()) {
std::shared_ptr<Port> ap = std::dynamic_pointer_cast<Port> (vkbd_output_port ()); std::shared_ptr<Port> ap = std::dynamic_pointer_cast<Port> (vkbd_output_port ());
if (ap->pretty_name () != _("Virtual Keyboard")) { if (ap->pretty_name () != _("Virtual Keyboard")) {
ap->set_pretty_name (_("Virtual Keyboard")); ap->set_pretty_name (_("Virtual Keyboard"));
} }
g_atomic_int_set (&_update_pretty_names, 0); _update_pretty_names.store (0);
} }
if (_engine.port_deletions_pending ().read_space () > 0) { if (_engine.port_deletions_pending ().read_space () > 0) {
@ -7688,13 +7693,13 @@ Session::ProcessorChangeBlocker::ProcessorChangeBlocker (Session* s, bool rc)
: _session (s) : _session (s)
, _reconfigure_on_delete (rc) , _reconfigure_on_delete (rc)
{ {
g_atomic_int_inc (&s->_ignore_route_processor_changes); PBD::atomic_inc (s->_ignore_route_processor_changes);
} }
Session::ProcessorChangeBlocker::~ProcessorChangeBlocker () Session::ProcessorChangeBlocker::~ProcessorChangeBlocker ()
{ {
if (g_atomic_int_dec_and_test (&_session->_ignore_route_processor_changes)) { if (PBD::atomic_dec_and_test (_session->_ignore_route_processor_changes)) {
gint type = g_atomic_int_and (&_session->_ignored_a_processor_change, 0); RouteProcessorChange::Type type = (RouteProcessorChange::Type) _session->_ignored_a_processor_change.fetch_and (0);
if (_reconfigure_on_delete) { if (_reconfigure_on_delete) {
if (type & RouteProcessorChange::GeneralChange) { if (type & RouteProcessorChange::GeneralChange) {
_session->route_processors_changed (RouteProcessorChange ()); _session->route_processors_changed (RouteProcessorChange ());

View file

@ -131,7 +131,7 @@ Session::setup_bundles ()
auto-connect thread, which does this sort of thing anyway. auto-connect thread, which does this sort of thing anyway.
*/ */
g_atomic_int_set (&_update_pretty_names, 1); _update_pretty_names.store (1);
auto_connect_thread_wakeup (); auto_connect_thread_wakeup ();
} }

View file

@ -122,11 +122,11 @@ Session::overwrite_some_buffers (std::shared_ptr<Route> r, OverwriteReason why)
uint32_t uint32_t
Session::playback_load () Session::playback_load ()
{ {
return (uint32_t) g_atomic_int_get (&_playback_load); return (uint32_t) _playback_load.load ();
} }
uint32_t uint32_t
Session::capture_load () Session::capture_load ()
{ {
return (uint32_t) g_atomic_int_get (&_capture_load); return (uint32_t) _capture_load.load ();
} }

View file

@ -1483,7 +1483,7 @@ Session::plan_master_strategy (pframes_t nframes, double master_speed, samplepos
* session (so far). * session (so far).
*/ */
locate_target += wlp + lrintf (ntracks() * sample_rate() * (1.5 * (g_atomic_int_get (&_current_usecs_per_track) / 1000000.0))); locate_target += wlp + lrintf (ntracks() * sample_rate() * (1.5 * (_current_usecs_per_track.load () / 1000000.0)));
DEBUG_TRACE (DEBUG::Slave, string_compose ("After locate-to-catch-master, still too far off (%1). Locate again to %2\n", delta, locate_target)); DEBUG_TRACE (DEBUG::Slave, string_compose ("After locate-to-catch-master, still too far off (%1). Locate again to %2\n", delta, locate_target));
@ -1541,7 +1541,7 @@ Session::plan_master_strategy (pframes_t nframes, double master_speed, samplepos
samplepos_t locate_target = master_transport_sample; samplepos_t locate_target = master_transport_sample;
locate_target += wlp + lrintf (ntracks() * sample_rate() * (1.5 * (g_atomic_int_get (&_current_usecs_per_track) / 1000000.0))); locate_target += wlp + lrintf (ntracks() * sample_rate() * (1.5 * (_current_usecs_per_track.load () / 1000000.0)));
DEBUG_TRACE (DEBUG::Slave, string_compose ("request locate to master position %1\n", locate_target)); DEBUG_TRACE (DEBUG::Slave, string_compose ("request locate to master position %1\n", locate_target));

View file

@ -181,7 +181,7 @@ Session::pre_engine_init (string fullpath)
*/ */
timerclear (&last_mmc_step); timerclear (&last_mmc_step);
g_atomic_int_set (&_processing_prohibited, 0); _processing_prohibited.store (0);
g_atomic_int_set (&_record_status, Disabled); g_atomic_int_set (&_record_status, Disabled);
g_atomic_int_set (&_playback_load, 100); g_atomic_int_set (&_playback_load, 100);
g_atomic_int_set (&_capture_load, 100); g_atomic_int_set (&_capture_load, 100);
@ -786,7 +786,7 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot
return 1; return 1;
} }
if (g_atomic_int_get(&_suspend_save)) { if (_suspend_save.load ()) {
/* StateProtector cannot be used for templates or save-as */ /* StateProtector cannot be used for templates or save-as */
assert (!template_only && !switch_to_snapshot && !for_archive && (snapshot_name.empty () || snapshot_name == _current_snapshot_name)); assert (!template_only && !switch_to_snapshot && !for_archive && (snapshot_name.empty () || snapshot_name == _current_snapshot_name));
if (pending) { if (pending) {

View file

@ -34,6 +34,7 @@
#include <boost/algorithm/string/erase.hpp> #include <boost/algorithm/string/erase.hpp>
#include "pbd/atomic.h"
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/enumwriter.h" #include "pbd/enumwriter.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
@ -200,7 +201,7 @@ Session::locate (samplepos_t target_sample, bool for_loop_end, bool force, bool
_nominal_jack_transport_sample = boost::none; _nominal_jack_transport_sample = boost::none;
// Bump seek counter so that any in-process locate in the butler // Bump seek counter so that any in-process locate in the butler
// thread(s?) can restart. // thread(s?) can restart.
g_atomic_int_inc (&_seek_counter); _seek_counter.fetch_add (1);
_last_roll_or_reversal_location = target_sample; _last_roll_or_reversal_location = target_sample;
if (!for_loop_end) { if (!for_loop_end) {
_remaining_latency_preroll = worst_latency_preroll_buffer_size_ceil (); _remaining_latency_preroll = worst_latency_preroll_buffer_size_ceil ();
@ -761,9 +762,9 @@ Session::add_post_transport_work (PostTransportWork ptw)
int tries = 0; int tries = 0;
while (tries < 8) { while (tries < 8) {
oldval = (PostTransportWork) g_atomic_int_get (&_post_transport_work); oldval = _post_transport_work.load ();
newval = PostTransportWork (oldval | ptw); newval = PostTransportWork (oldval | ptw);
if (g_atomic_int_compare_and_exchange (&_post_transport_work, oldval, newval)) { if (_post_transport_work.compare_exchange_strong (oldval, newval)) {
/* success */ /* success */
return; return;
} }
@ -1162,15 +1163,15 @@ Session::butler_transport_work (bool have_process_lock)
} }
} }
const int butler = g_atomic_int_get (&_butler_seek_counter); const int butler = _butler_seek_counter.load ();
const int rtlocates = g_atomic_int_get (&_seek_counter); const int rtlocates = _seek_counter.load ();
const bool will_locate = (butler != rtlocates); const bool will_locate = (butler != rtlocates);
if (ptw & PostTransportStop) { if (ptw & PostTransportStop) {
non_realtime_stop (ptw & PostTransportAbort, on_entry, finished, will_locate); non_realtime_stop (ptw & PostTransportAbort, on_entry, finished, will_locate);
if (!finished) { if (!finished) {
g_atomic_int_dec_and_test (&_butler->should_do_transport_work); (void) PBD::atomic_dec_and_test (_butler->should_do_transport_work);
goto restart; goto restart;
} }
} }
@ -1184,7 +1185,7 @@ Session::butler_transport_work (bool have_process_lock)
if (ptw & PostTransportOverWrite) { if (ptw & PostTransportOverWrite) {
non_realtime_overwrite (on_entry, finished, (ptw & PostTransportLoopChanged)); non_realtime_overwrite (on_entry, finished, (ptw & PostTransportLoopChanged));
if (!finished) { if (!finished) {
g_atomic_int_dec_and_test (&_butler->should_do_transport_work); (void) PBD::atomic_dec_and_test (_butler->should_do_transport_work);
goto restart; goto restart;
} }
} }
@ -1193,7 +1194,7 @@ Session::butler_transport_work (bool have_process_lock)
non_realtime_set_audition (); non_realtime_set_audition ();
} }
g_atomic_int_dec_and_test (&_butler->should_do_transport_work); (void) PBD::atomic_dec_and_test (_butler->should_do_transport_work);
DEBUG_TRACE (DEBUG::Transport, string_compose (X_("Butler transport work all done after %1 usecs @ %2 ptw %3 trw = %4\n"), g_get_monotonic_time() - before, _transport_sample, enum_2_string (post_transport_work()), _butler->transport_work_requested())); DEBUG_TRACE (DEBUG::Transport, string_compose (X_("Butler transport work all done after %1 usecs @ %2 ptw %3 trw = %4\n"), g_get_monotonic_time() - before, _transport_sample, enum_2_string (post_transport_work()), _butler->transport_work_requested()));
} }
@ -1261,13 +1262,13 @@ Session::non_realtime_locate ()
std::shared_ptr<RouteList> rl = routes.reader(); std::shared_ptr<RouteList> rl = routes.reader();
restart: restart:
sc = g_atomic_int_get (&_seek_counter); sc = _seek_counter.load ();
tf = _transport_sample; tf = _transport_sample;
start = get_microseconds (); start = get_microseconds ();
for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i, ++nt) { for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i, ++nt) {
(*i)->non_realtime_locate (tf); (*i)->non_realtime_locate (tf);
if (sc != g_atomic_int_get (&_seek_counter)) { if (sc != _seek_counter.load ()) {
goto restart; goto restart;
} }
} }
@ -1277,7 +1278,7 @@ Session::non_realtime_locate ()
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "locate to " << tf << " took " << (end - start) << " usecs for " << nt << " tracks = " << usecs_per_track << " per track\n"; std::cerr << "locate to " << tf << " took " << (end - start) << " usecs for " << nt << " tracks = " << usecs_per_track << " per track\n";
#endif #endif
if (usecs_per_track > g_atomic_int_get (&_current_usecs_per_track)) { if (usecs_per_track > _current_usecs_per_track.load ()) {
g_atomic_int_set (&_current_usecs_per_track, usecs_per_track); g_atomic_int_set (&_current_usecs_per_track, usecs_per_track);
} }
} }
@ -1878,8 +1879,8 @@ Session::reset_xrun_count ()
void void
Session::route_processors_changed (RouteProcessorChange c) Session::route_processors_changed (RouteProcessorChange c)
{ {
if (g_atomic_int_get (&_ignore_route_processor_changes) > 0) { if (_ignore_route_processor_changes.load () > 0) {
g_atomic_int_or (&_ignored_a_processor_change, (int)c.type); (void) _ignored_a_processor_change.fetch_or (c.type);
return; return;
} }
@ -1948,7 +1949,7 @@ Session::request_resume_timecode_transmission ()
bool bool
Session::timecode_transmission_suspended () const Session::timecode_transmission_suspended () const
{ {
return g_atomic_int_get (&_suspend_timecode_transmission) == 1; return _suspend_timecode_transmission.load () == 1;
} }
std::shared_ptr<TransportMaster> std::shared_ptr<TransportMaster>

View file

@ -67,7 +67,7 @@ Source::Source (Session& s, DataType type, const string& name, Flag flags)
, _have_natural_position (false) , _have_natural_position (false)
, _level (0) , _level (0)
{ {
g_atomic_int_set (&_use_count, 0); _use_count.store (0);
_analysed = false; _analysed = false;
_timestamp = 0; _timestamp = 0;
@ -82,7 +82,7 @@ Source::Source (Session& s, const XMLNode& node)
, _have_natural_position (false) , _have_natural_position (false)
, _level (0) , _level (0)
{ {
g_atomic_int_set (&_use_count, 0); _use_count.store (0);
_analysed = false; _analysed = false;
_timestamp = 0; _timestamp = 0;
@ -440,21 +440,21 @@ Source::set_allow_remove_if_empty (bool yn)
void void
Source::inc_use_count () Source::inc_use_count ()
{ {
g_atomic_int_inc (&_use_count); _use_count.fetch_add (1);
} }
void void
Source::dec_use_count () Source::dec_use_count ()
{ {
#ifndef NDEBUG #ifndef NDEBUG
gint oldval = g_atomic_int_add (&_use_count, -1); int oldval = _use_count.fetch_sub (1);
if (oldval <= 0) { if (oldval <= 0) {
cerr << "Bad use dec for " << name() << endl; cerr << "Bad use dec for " << name() << endl;
abort (); abort ();
} }
assert (oldval > 0); assert (oldval > 0);
#else #else
g_atomic_int_add (&_use_count, -1); _use_count.fetch_sub (1);
#endif #endif
try { try {

View file

@ -26,6 +26,8 @@
#include "ardour/vst3_host.h" #include "ardour/vst3_host.h"
#include "pbd/atomic.h"
#ifndef VST3_SCANNER_APP #ifndef VST3_SCANNER_APP
#include "ardour/debug.h" #include "ardour/debug.h"
#include "pbd/compose.h" #include "pbd/compose.h"
@ -121,24 +123,24 @@ Steinberg::utf8_to_tchar (Vst::TChar* rv, std::string const& s, size_t l)
RefObject::RefObject () RefObject::RefObject ()
{ {
g_atomic_int_set (&_cnt, 1); _cnt.store (1);
} }
uint32 uint32
RefObject::addRef () RefObject::addRef ()
{ {
g_atomic_int_inc (&_cnt); _cnt.fetch_add (1);
return g_atomic_int_get (&_cnt); return _cnt.load ();
} }
uint32 uint32
RefObject::release () RefObject::release ()
{ {
if (g_atomic_int_dec_and_test (&_cnt)) { if (PBD::atomic_dec_and_test (_cnt)) {
delete this; delete this;
return 0; return 0;
} }
return g_atomic_int_get (&_cnt); return _cnt.load ();
} }
/* ****************************************************************************/ /* ****************************************************************************/

View file

@ -1,16 +1,18 @@
#ifndef AUDIOGRAPHER_THREADER_H #ifndef AUDIOGRAPHER_THREADER_H
#define AUDIOGRAPHER_THREADER_H #define AUDIOGRAPHER_THREADER_H
#include <atomic>
#include <vector>
#include <algorithm>
#include <glibmm/threadpool.h> #include <glibmm/threadpool.h>
#include <glibmm/timeval.h> #include <glibmm/timeval.h>
#include <sigc++/slot.h> #include <sigc++/slot.h>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <glib.h> #include <glib.h>
#include <vector>
#include <algorithm>
#include "pbd/g_atomic_compat.h" #include "pbd/atomic.h"
#include "audiographer/visibility.h" #include "audiographer/visibility.h"
#include "audiographer/source.h" #include "audiographer/source.h"
@ -51,7 +53,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T>
: thread_pool (thread_pool) : thread_pool (thread_pool)
, wait_timeout (wait_timeout_milliseconds) , wait_timeout (wait_timeout_milliseconds)
{ {
g_atomic_int_set (&readers, 0); readers.store (0);
} }
virtual ~Threader () {} virtual ~Threader () {}
@ -76,7 +78,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T>
exception.reset(); exception.reset();
unsigned int outs = outputs.size(); unsigned int outs = outputs.size();
g_atomic_int_add (&readers, outs); (void) readers.fetch_add (outs);
for (unsigned int i = 0; i < outs; ++i) { for (unsigned int i = 0; i < outs; ++i) {
thread_pool.push (sigc::bind (sigc::mem_fun (this, &Threader::process_output), c, i)); thread_pool.push (sigc::bind (sigc::mem_fun (this, &Threader::process_output), c, i));
} }
@ -90,7 +92,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T>
void wait() void wait()
{ {
while (g_atomic_int_get (&readers) != 0) { while (readers.load () != 0) {
gint64 end_time = g_get_monotonic_time () + (wait_timeout * G_TIME_SPAN_MILLISECOND); gint64 end_time = g_get_monotonic_time () + (wait_timeout * G_TIME_SPAN_MILLISECOND);
wait_cond.wait_until(wait_mutex, end_time); wait_cond.wait_until(wait_mutex, end_time);
} }
@ -113,7 +115,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T>
exception_mutex.unlock(); exception_mutex.unlock();
} }
if (g_atomic_int_dec_and_test (&readers)) { if (PBD::atomic_dec_and_test (readers)) {
wait_cond.signal(); wait_cond.signal();
} }
} }
@ -124,7 +126,7 @@ class /*LIBAUDIOGRAPHER_API*/ Threader : public Source<T>, public Sink<T>
Glib::Threads::Mutex wait_mutex; Glib::Threads::Mutex wait_mutex;
Glib::Threads::Cond wait_cond; Glib::Threads::Cond wait_cond;
GATOMIC_QUAL gint readers; std::atomic<int> readers;
long wait_timeout; long wait_timeout;
Glib::Threads::Mutex exception_mutex; Glib::Threads::Mutex exception_mutex;

View file

@ -68,7 +68,7 @@ class TmpFileRt
% c.channels() % SndfileHandle::channels())); % c.channels() % SndfileHandle::channels()));
} }
if (SndfileWriter<T>::throw_level (ThrowProcess) && _rb.write_space() < c.samples()) { if (SndfileWriter<T>::throw_level (ThrowProcess) && _rb.write_space() < (size_t) c.samples()) {
throw Exception (*this, boost::str (boost::format throw Exception (*this, boost::str (boost::format
("Could not write data to ringbuffer/output file (%1%)") ("Could not write data to ringbuffer/output file (%1%)")
% SndfileHandle::strError())); % SndfileHandle::strError()));

View file

@ -1020,7 +1020,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
} }
_run = true; _run = true;
g_atomic_int_set (&_port_change_flag, 0); _port_change_flag.store (0);
if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, PBD_RT_PRI_MAIN, PBD_RT_STACKSIZE_PROC, if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, PBD_RT_PRI_MAIN, PBD_RT_STACKSIZE_PROC,
&_main_thread, pthread_process, this)) { &_main_thread, pthread_process, this)) {
@ -2084,7 +2084,8 @@ AlsaAudioBackend::main_process_thread ()
bool connections_changed = false; bool connections_changed = false;
bool ports_changed = false; bool ports_changed = false;
if (!pthread_mutex_trylock (&_port_callback_mutex)) { if (!pthread_mutex_trylock (&_port_callback_mutex)) {
if (g_atomic_int_compare_and_exchange (&_port_change_flag, 1, 0)) { int canderef (1);
if (_port_change_flag.compare_exchange_strong (canderef, 0)) {
ports_changed = true; ports_changed = true;
} }
if (!_port_connection_queue.empty ()) { if (!_port_connection_queue.empty ()) {

View file

@ -52,7 +52,7 @@ AlsaAudioSlave::AlsaAudioSlave (
, _play_buff (0) , _play_buff (0)
, _src_buff (0) , _src_buff (0)
{ {
g_atomic_int_set (&_draining, 1); _draining.store (1);
if (0 != _pcmi.state()) { if (0 != _pcmi.state()) {
return; return;
@ -213,7 +213,7 @@ AlsaAudioSlave::process_thread ()
} }
const size_t spp = _pcmi.fsize (); const size_t spp = _pcmi.fsize ();
const bool drain = g_atomic_int_get (&_draining); const bool drain = _draining.load ();
last_n_periods = 0; last_n_periods = 0;
while (nr >= (long)spp) { while (nr >= (long)spp) {
@ -267,7 +267,7 @@ AlsaAudioSlave::process_thread ()
_rb_capture.increment_write_idx (spp * nchn); _rb_capture.increment_write_idx (spp * nchn);
#endif #endif
} else { } else {
g_atomic_int_set (&_draining, 1); _draining.store (1);
} }
_pcmi.capt_done (spp); _pcmi.capt_done (spp);
@ -342,7 +342,7 @@ AlsaAudioSlave::process_thread ()
if (xrun && (_pcmi.capt_xrun() > 0 || _pcmi.play_xrun() > 0)) { if (xrun && (_pcmi.capt_xrun() > 0 || _pcmi.play_xrun() > 0)) {
reset_dll = true; reset_dll = true;
_samples_since_dll_reset = 0; _samples_since_dll_reset = 0;
g_atomic_int_set (&_draining, 1); _draining.store (1);
} }
} }
@ -373,11 +373,11 @@ AlsaAudioSlave::cycle_start (double tme, double mst_speed, bool drain)
} }
if (drain) { if (drain) {
g_atomic_int_set (&_draining, 1); _draining.store (1);
return; return;
} }
if (g_atomic_int_get (&_draining)) { if (_draining.load ()) {
_rb_capture.increment_read_idx (_rb_capture.read_space()); _rb_capture.increment_read_idx (_rb_capture.read_space());
return; return;
} }
@ -425,7 +425,7 @@ AlsaAudioSlave::cycle_start (double tme, double mst_speed, bool drain)
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "ALSA Slave: Capture Ringbuffer Underflow\n"; // XXX DEBUG std::cerr << "ALSA Slave: Capture Ringbuffer Underflow\n"; // XXX DEBUG
#endif #endif
g_atomic_int_set(&_draining, 1); _draining.store (1);
} }
if ((!_active || underflow) && _capt_buff) { if ((!_active || underflow) && _capt_buff) {
@ -443,7 +443,7 @@ AlsaAudioSlave::cycle_end ()
bool drain_done = false; bool drain_done = false;
bool overflow = false; bool overflow = false;
if (g_atomic_int_get (&_draining)) { if (_draining.load ()) {
if (_rb_capture.read_space() == 0 && _rb_playback.read_space() == 0 && _samples_since_dll_reset > _pcmi.fsamp ()) { if (_rb_capture.read_space() == 0 && _rb_playback.read_space() == 0 && _samples_since_dll_reset > _pcmi.fsamp ()) {
reset_resampler (_src_capt); reset_resampler (_src_capt);
reset_resampler (_src_play); reset_resampler (_src_play);
@ -502,11 +502,11 @@ AlsaAudioSlave::cycle_end ()
#ifndef NDEBUG #ifndef NDEBUG
std::cerr << "ALSA Slave: Playback Ringbuffer Overflow\n"; // XXX DEBUG std::cerr << "ALSA Slave: Playback Ringbuffer Overflow\n"; // XXX DEBUG
#endif #endif
g_atomic_int_set (&_draining, 1); _draining.store (1);
return; return;
} }
if (drain_done) { if (drain_done) {
g_atomic_int_set (&_draining, 0); _draining.store (0);
} }
} }
@ -514,7 +514,7 @@ void
AlsaAudioSlave::freewheel (bool onoff) AlsaAudioSlave::freewheel (bool onoff)
{ {
if (onoff) { if (onoff) {
g_atomic_int_set (&_draining, 1); _draining.store (1);
} }
} }

View file

@ -19,10 +19,11 @@
#ifndef __libbackend_alsa_slave_h__ #ifndef __libbackend_alsa_slave_h__
#define __libbackend_alsa_slave_h__ #define __libbackend_alsa_slave_h__
#include <atomic>
#include <pthread.h> #include <pthread.h>
#include "pbd/ringbuffer.h" #include "pbd/ringbuffer.h"
#include "pbd/g_atomic_compat.h"
#include "zita-resampler/vresampler.h" #include "zita-resampler/vresampler.h"
#include "zita-alsa-pcmi.h" #include "zita-alsa-pcmi.h"
@ -84,7 +85,7 @@ private:
volatile double _slave_speed; volatile double _slave_speed;
GATOMIC_QUAL gint _draining; std::atomic<int> _draining;
PBD::RingBuffer<float> _rb_capture; PBD::RingBuffer<float> _rb_capture;
PBD::RingBuffer<float> _rb_playback; PBD::RingBuffer<float> _rb_playback;

View file

@ -639,7 +639,7 @@ CoreAudioBackend::_start (bool for_latency_measurement)
_preinit = true; _preinit = true;
_run = true; _run = true;
g_atomic_int_set (&_port_change_flag, 0); _port_change_flag.store (0);
if (_midi_driver_option == _("CoreMidi")) { if (_midi_driver_option == _("CoreMidi")) {
_midiio->set_enabled(true); _midiio->set_enabled(true);
@ -697,7 +697,7 @@ CoreAudioBackend::_start (bool for_latency_measurement)
engine.reconnect_ports (); engine.reconnect_ports ();
// force an initial registration_callback() & latency re-compute // force an initial registration_callback() & latency re-compute
g_atomic_int_set (&_port_change_flag, 1); _port_change_flag.store (1);
pre_process (); pre_process ();
_dsp_load_calc.reset (); _dsp_load_calc.reset ();
@ -1026,7 +1026,7 @@ CoreAudioBackend::coremidi_rediscover()
#ifndef NDEBUG #ifndef NDEBUG
printf("unregister MIDI Output: %s\n", (*it)->name().c_str()); printf("unregister MIDI Output: %s\n", (*it)->name().c_str());
#endif #endif
g_atomic_int_set (&_port_change_flag, 1); _port_change_flag.store (1);
unregister_port((*it)); unregister_port((*it));
it = _system_midi_out.erase(it); it = _system_midi_out.erase(it);
} }
@ -1046,7 +1046,7 @@ CoreAudioBackend::coremidi_rediscover()
#ifndef NDEBUG #ifndef NDEBUG
printf("unregister MIDI Input: %s\n", (*it)->name().c_str()); printf("unregister MIDI Input: %s\n", (*it)->name().c_str());
#endif #endif
g_atomic_int_set (&_port_change_flag, 1); _port_change_flag.store (1);
unregister_port((*it)); unregister_port((*it));
it = _system_midi_in.erase(it); it = _system_midi_in.erase(it);
} }
@ -1072,7 +1072,7 @@ CoreAudioBackend::coremidi_rediscover()
BackendPortPtr pp = std::dynamic_pointer_cast<BackendPort>(p); BackendPortPtr pp = std::dynamic_pointer_cast<BackendPort>(p);
pp->set_hw_port_name(_midiio->port_name(i, true)); pp->set_hw_port_name(_midiio->port_name(i, true));
_system_midi_in.push_back(pp); _system_midi_in.push_back(pp);
g_atomic_int_set (&_port_change_flag, 1); _port_change_flag.store (1);
} }
for (size_t i = 0; i < _midiio->n_midi_outputs(); ++i) { for (size_t i = 0; i < _midiio->n_midi_outputs(); ++i) {
@ -1095,7 +1095,7 @@ CoreAudioBackend::coremidi_rediscover()
BackendPortPtr pp = std::dynamic_pointer_cast<BackendPort>(p); BackendPortPtr pp = std::dynamic_pointer_cast<BackendPort>(p);
pp->set_hw_port_name(_midiio->port_name(i, false)); pp->set_hw_port_name(_midiio->port_name(i, false));
_system_midi_out.push_back(pp); _system_midi_out.push_back(pp);
g_atomic_int_set (&_port_change_flag, 1); _port_change_flag.store (1);
} }

View file

@ -461,7 +461,7 @@ DummyAudioBackend::_start (bool /*for_latency_measurement*/)
} }
engine.reconnect_ports (); engine.reconnect_ports ();
g_atomic_int_set (&_port_change_flag, 0); _port_change_flag.store (0);
if (pbd_pthread_create (PBD_RT_STACKSIZE_PROC, &_main_thread, pthread_process, this)) { if (pbd_pthread_create (PBD_RT_STACKSIZE_PROC, &_main_thread, pthread_process, this)) {
PBD::error << _("DummyAudioBackend: cannot start.") << endmsg; PBD::error << _("DummyAudioBackend: cannot start.") << endmsg;
@ -1008,7 +1008,8 @@ DummyAudioBackend::main_process_thread ()
bool connections_changed = false; bool connections_changed = false;
bool ports_changed = false; bool ports_changed = false;
if (!pthread_mutex_trylock (&_port_callback_mutex)) { if (!pthread_mutex_trylock (&_port_callback_mutex)) {
if (g_atomic_int_compare_and_exchange (&_port_change_flag, 1, 0)) { int canderef (1);
if (_port_change_flag.compare_exchange_strong (canderef, 0)) {
ports_changed = true; ports_changed = true;
} }
if (!_port_connection_queue.empty ()) { if (!_port_connection_queue.empty ()) {

View file

@ -673,7 +673,7 @@ PortAudioBackend::_start (bool for_latency_measurement)
_run = true; _run = true;
engine.reconnect_ports (); engine.reconnect_ports ();
g_atomic_int_set (&_port_change_flag, 0); _port_change_flag.store (0);
_dsp_calc.reset (); _dsp_calc.reset ();

View file

@ -618,7 +618,7 @@ PulseAudioBackend::_start (bool /*for_latency_measurement*/)
engine.reconnect_ports (); engine.reconnect_ports ();
_run = true; _run = true;
g_atomic_int_set (&_port_change_flag, 0); _port_change_flag.store (0);
if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, PBD_RT_PRI_MAIN, PBD_RT_STACKSIZE_PROC, if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, PBD_RT_PRI_MAIN, PBD_RT_STACKSIZE_PROC,
&_main_thread, pthread_process, this)) { &_main_thread, pthread_process, this)) {
@ -1091,7 +1091,8 @@ PulseAudioBackend::main_process_thread ()
bool connections_changed = false; bool connections_changed = false;
bool ports_changed = false; bool ports_changed = false;
if (!pthread_mutex_trylock (&_port_callback_mutex)) { if (!pthread_mutex_trylock (&_port_callback_mutex)) {
if (g_atomic_int_compare_and_exchange (&_port_change_flag, 1, 0)) { int canderef (1);
if (_port_change_flag.compare_exchange_strong (canderef, 0)) {
ports_changed = true; ports_changed = true;
} }
if (!_port_connection_queue.empty ()) { if (!_port_connection_queue.empty ()) {

View file

@ -19,26 +19,27 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <atomic>
#include <glib.h> #include <glib.h>
#include "pbd/g_atomic_compat.h"
#include "temporal/beats.h" #include "temporal/beats.h"
#include "evoral/Event.h" #include "evoral/Event.h"
namespace Evoral { namespace Evoral {
static GATOMIC_QUAL event_id_t _event_id_counter = 0; static std::atomic<event_id_t> _event_id_counter (0);
event_id_t event_id_t
event_id_counter() event_id_counter()
{ {
return g_atomic_int_get (&_event_id_counter); return _event_id_counter.load ();
} }
void void
init_event_id_counter(event_id_t n) init_event_id_counter(event_id_t n)
{ {
g_atomic_int_set (&_event_id_counter, n); _event_id_counter.store (n);
} }
event_id_t event_id_t
@ -53,7 +54,7 @@ next_event_id ()
* *
* current user-record: is event-counter="276390506" (just abov 2^28) * current user-record: is event-counter="276390506" (just abov 2^28)
*/ */
return g_atomic_int_add (&_event_id_counter, 1); return _event_id_counter.fetch_add (1);
} }
#ifdef EVORAL_EVENT_ALLOC #ifdef EVORAL_EVENT_ALLOC

34
libs/pbd/pbd/atomic.h Normal file
View file

@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 Paul Davis <paul@linuxaudiosystems.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __libpbd_atomic_h__
#define __libpbd_atomic_h__
#include <atomic>
namespace PBD {
template<typename T>
bool atomic_dec_and_test (std::atomic<T>& aval) { return (aval.fetch_sub (1) - 1) == 0; }
template<typename T>
void atomic_inc (std::atomic<T>& aval) { (void) aval.fetch_add (1); }
}
#endif /* __libpbd_atomic_h__ */

View file

@ -20,9 +20,9 @@
#ifndef PBD_ATOMIC_COUNTER_H #ifndef PBD_ATOMIC_COUNTER_H
#define PBD_ATOMIC_COUNTER_H #define PBD_ATOMIC_COUNTER_H
#include <glib.h> #include <atomic>
#include "pbd/g_atomic_compat.h" #include <glib.h>
namespace PBD { namespace PBD {
@ -43,7 +43,7 @@ public:
gint get() const gint get() const
{ {
return g_atomic_int_get (&m_value); return m_value.load ();
} }
void set (gint new_value) void set (gint new_value)
@ -53,7 +53,7 @@ public:
void increment () void increment ()
{ {
g_atomic_int_inc (&m_value); m_value.fetch_add (1);
} }
void operator++ () void operator++ ()
@ -63,7 +63,7 @@ public:
bool decrement_and_test () bool decrement_and_test ()
{ {
return g_atomic_int_dec_and_test (&m_value); return PBD::atomic_dec_and_test (m_value);
} }
bool operator-- () bool operator-- ()
@ -90,7 +90,7 @@ public:
} }
private: private:
mutable GATOMIC_QUAL gint m_value; mutable std::atomic<int> m_value;
}; };
} // namespace PBD } // namespace PBD

View file

@ -20,6 +20,7 @@
#ifndef __pbd_event_loop_h__ #ifndef __pbd_event_loop_h__
#define __pbd_event_loop_h__ #define __pbd_event_loop_h__
#include <atomic>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
@ -58,19 +59,19 @@ public:
struct InvalidationRecord { struct InvalidationRecord {
std::list<BaseRequestObject*> requests; std::list<BaseRequestObject*> requests;
PBD::EventLoop* event_loop; PBD::EventLoop* event_loop;
gint _valid; std::atomic<int> _valid;
gint _ref; std::atomic<int> _ref;
const char* file; const char* file;
int line; int line;
InvalidationRecord() : event_loop (0), _valid (1), _ref (0) {} InvalidationRecord() : event_loop (0), _valid (1), _ref (0) {}
void invalidate () { g_atomic_int_set (&_valid, 0); } void invalidate () { _valid.store (0); }
bool valid () { return g_atomic_int_get (&_valid) == 1; } bool valid () { return _valid.load () == 1; }
void ref () { g_atomic_int_inc (&_ref); } void ref () { _ref.fetch_add (1); }
void unref () { (void) g_atomic_int_dec_and_test (&_ref); } void unref () { (void) _ref.fetch_sub (1); }
bool in_use () { return g_atomic_int_get (&_ref) > 0; } bool in_use () { return _ref.load () > 0; }
int use_count () { return g_atomic_int_get (&_ref); } int use_count () { return _ref.load (); }
}; };
static void* invalidate_request (void* data); static void* invalidate_request (void* data);

View file

@ -1,39 +0,0 @@
/*
* Copyright (C) 2021 Robin Gareus <robin@gareus.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _PBD_G_ATOMIC_COMPAT_H_
#define _PBD_G_ATOMIC_COMPAT_H_
/* requires for gint, guint, gpointer */
#include <glib.h>
/* This is to for g_atomic_* compatibility with glib >= 2.68 and gcc-11
*
* "While atomic has a volatile qualifier, this is a historical artifact and the pointer passed to it should not be volatile."
* (https://developer.gnome.org/glib/2.68/glib-Atomic-Operations.html)
*
* Older versions of glib and older compilers still expect a volatile qualifier and print
* "cast from type 'volatile long int*' to type 'long int*' casts away qualifiers [-Wcast-qual]"
*/
#if defined HAVE_GLIB_2_64 && (defined(__cplusplus) && __cplusplus >= 201103L)
# define GATOMIC_QUAL
#else
# define GATOMIC_QUAL volatile
#endif
#endif

View file

@ -33,8 +33,7 @@
# define MPMC_QUEUE_TYPE std::atomic<size_t> # define MPMC_QUEUE_TYPE std::atomic<size_t>
#else #else
# include <glib.h> # include <glib.h>
# include "pbd/g_atomic_compat.h" # define MPMC_QUEUE_TYPE std::atomic<unsigned int>
# define MPMC_QUEUE_TYPE GATOMIC_QUAL guint
#endif #endif
namespace PBD { namespace PBD {
@ -99,8 +98,8 @@ public:
for (size_t i = 0; i <= _buffer_mask; ++i) { for (size_t i = 0; i <= _buffer_mask; ++i) {
g_atomic_int_set (&_buffer[i]._sequence, i); g_atomic_int_set (&_buffer[i]._sequence, i);
} }
g_atomic_int_set (&_enqueue_pos, 0); _enqueue_pos.store (0);
g_atomic_int_set (&_dequeue_pos, 0); _dequeue_pos.store (0);
#endif #endif
} }
@ -111,7 +110,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC #ifdef MPMC_USE_STD_ATOMIC
size_t pos = _enqueue_pos.load (std::memory_order_relaxed); size_t pos = _enqueue_pos.load (std::memory_order_relaxed);
#else #else
guint pos = g_atomic_int_get (&_enqueue_pos); guint pos = _enqueue_pos.load ();
#endif #endif
for (;;) { for (;;) {
cell = &_buffer[pos & _buffer_mask]; cell = &_buffer[pos & _buffer_mask];
@ -136,7 +135,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC #ifdef MPMC_USE_STD_ATOMIC
pos = _enqueue_pos.load (std::memory_order_relaxed); pos = _enqueue_pos.load (std::memory_order_relaxed);
#else #else
pos = g_atomic_int_get (&_enqueue_pos); pos = _enqueue_pos.load ();
#endif #endif
} }
} }
@ -158,7 +157,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC #ifdef MPMC_USE_STD_ATOMIC
size_t pos = _dequeue_pos.load (std::memory_order_relaxed); size_t pos = _dequeue_pos.load (std::memory_order_relaxed);
#else #else
guint pos = g_atomic_int_get (&_dequeue_pos); guint pos = _dequeue_pos.load ();
#endif #endif
for (;;) { for (;;) {
cell = &_buffer[pos & _buffer_mask]; cell = &_buffer[pos & _buffer_mask];
@ -183,7 +182,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC #ifdef MPMC_USE_STD_ATOMIC
pos = _dequeue_pos.load (std::memory_order_relaxed); pos = _dequeue_pos.load (std::memory_order_relaxed);
#else #else
pos = g_atomic_int_get (&_dequeue_pos); pos = _dequeue_pos.load ();
#endif #endif
} }
} }

View file

@ -20,13 +20,14 @@
#ifndef playback_buffer_h #ifndef playback_buffer_h
#define playback_buffer_h #define playback_buffer_h
#include <atomic>
#include <cstdint>
#include <cstring> #include <cstring>
#include <stdint.h>
#include <glibmm.h> #include <glibmm.h>
#include "pbd/libpbd_visibility.h" #include "pbd/libpbd_visibility.h"
#include "pbd/spinlock.h" #include "pbd/spinlock.h"
#include "pbd/g_atomic_compat.h"
namespace PBD { namespace PBD {
@ -48,7 +49,7 @@ public:
size_mask = size - 1; size_mask = size - 1;
buf = new T[size]; buf = new T[size];
g_atomic_int_set (&read_idx, 0); read_idx.store (0);
reset (); reset ();
} }
@ -66,9 +67,9 @@ public:
/* writer, when seeking, may block */ /* writer, when seeking, may block */
Glib::Threads::Mutex::Lock lm (_reset_lock); Glib::Threads::Mutex::Lock lm (_reset_lock);
SpinLock sl (_reservation_lock); SpinLock sl (_reservation_lock);
g_atomic_int_set (&read_idx, 0); read_idx.store (0);
g_atomic_int_set (&write_idx, 0); write_idx.store (0);
g_atomic_int_set (&reserved, 0); reserved.store (0);
} }
/* called from rt (reader) thread for new buffers */ /* called from rt (reader) thread for new buffers */
@ -84,8 +85,8 @@ public:
guint write_space () const { guint write_space () const {
guint w, r; guint w, r;
w = g_atomic_int_get (&write_idx); w = write_idx.load ();
r = g_atomic_int_get (&read_idx); r = read_idx.load ();
guint rv; guint rv;
@ -113,8 +114,8 @@ public:
guint read_space () const { guint read_space () const {
guint w, r; guint w, r;
w = g_atomic_int_get (&write_idx); w = write_idx.load ();
r = g_atomic_int_get (&read_idx); r = read_idx.load ();
if (w > r) { if (w > r) {
return w - r; return w - r;
@ -127,7 +128,7 @@ public:
guint overwritable_at (guint r) const { guint overwritable_at (guint r) const {
guint w; guint w;
w = g_atomic_int_get (&write_idx); w = write_idx.load ();
if (w > r) { if (w > r) {
return w - r; return w - r;
@ -146,7 +147,7 @@ public:
guint increment_write_ptr (guint cnt) guint increment_write_ptr (guint cnt)
{ {
cnt = std::min (cnt, write_space ()); cnt = std::min (cnt, write_space ());
g_atomic_int_set (&write_idx, (g_atomic_int_get (&write_idx) + cnt) & size_mask); g_atomic_int_set (&write_idx, (write_idx.load () + cnt) & size_mask);
return cnt; return cnt;
} }
@ -154,15 +155,15 @@ public:
guint decrement_read_ptr (guint cnt) guint decrement_read_ptr (guint cnt)
{ {
SpinLock sl (_reservation_lock); SpinLock sl (_reservation_lock);
guint r = g_atomic_int_get (&read_idx); guint r = read_idx.load ();
guint res = g_atomic_int_get (&reserved); guint res = reserved.load ();
cnt = std::min (cnt, res); cnt = std::min (cnt, res);
r = (r + size - cnt) & size_mask; r = (r + size - cnt) & size_mask;
res -= cnt; res -= cnt;
g_atomic_int_set (&read_idx, r); read_idx.store (r);
g_atomic_int_set (&reserved, res); g_atomic_int_set (&reserved, res);
return cnt; return cnt;
@ -174,8 +175,8 @@ public:
cnt = std::min (cnt, read_space ()); cnt = std::min (cnt, read_space ());
SpinLock sl (_reservation_lock); SpinLock sl (_reservation_lock);
g_atomic_int_set (&read_idx, (g_atomic_int_get (&read_idx) + cnt) & size_mask); g_atomic_int_set (&read_idx, (read_idx.load () + cnt) & size_mask);
g_atomic_int_set (&reserved, std::min (reservation, g_atomic_int_get (&reserved) + cnt)); g_atomic_int_set (&reserved, std::min (reservation, reserved.load () + cnt));
return cnt; return cnt;
} }
@ -185,15 +186,15 @@ public:
if (cnt > 0) { if (cnt > 0) {
return read_space() >= cnt; return read_space() >= cnt;
} else if (cnt < 0) { } else if (cnt < 0) {
return g_atomic_int_get (&reserved) >= -cnt; return reserved.load () >= -cnt;
} else { } else {
return true; return true;
} }
} }
guint read_ptr() const { return g_atomic_int_get (&read_idx); } guint read_ptr() const { return read_idx.load (); }
guint write_ptr() const { return g_atomic_int_get (&write_idx); } guint write_ptr() const { return write_idx.load (); }
guint reserved_size() const { return g_atomic_int_get (&reserved); } guint reserved_size() const { return reserved.load (); }
guint reservation_size() const { return reservation; } guint reservation_size() const { return reservation; }
private: private:
@ -202,9 +203,9 @@ private:
guint size; guint size;
guint size_mask; guint size_mask;
mutable GATOMIC_QUAL gint write_idx; mutable std::atomic<int> write_idx;
mutable GATOMIC_QUAL gint read_idx; mutable std::atomic<int> read_idx;
mutable GATOMIC_QUAL gint reserved; mutable std::atomic<int> reserved;
/* spinlock will be used to update write_idx and reserved in sync */ /* spinlock will be used to update write_idx and reserved in sync */
spinlock_t _reservation_lock; spinlock_t _reservation_lock;
@ -215,7 +216,7 @@ private:
template<class T> /*LIBPBD_API*/ guint template<class T> /*LIBPBD_API*/ guint
PlaybackBuffer<T>::write (T const *src, guint cnt) PlaybackBuffer<T>::write (T const *src, guint cnt)
{ {
guint w = g_atomic_int_get (&write_idx); guint w = write_idx.load ();
const guint free_cnt = write_space (); const guint free_cnt = write_space ();
if (free_cnt == 0) { if (free_cnt == 0) {
@ -242,14 +243,14 @@ PlaybackBuffer<T>::write (T const *src, guint cnt)
w = n2; w = n2;
} }
g_atomic_int_set (&write_idx, w); write_idx.store (w);
return to_write; return to_write;
} }
template<class T> /*LIBPBD_API*/ guint template<class T> /*LIBPBD_API*/ guint
PlaybackBuffer<T>::write_zero (guint cnt) PlaybackBuffer<T>::write_zero (guint cnt)
{ {
guint w = g_atomic_int_get (&write_idx); guint w = write_idx.load ();
const guint free_cnt = write_space (); const guint free_cnt = write_space ();
if (free_cnt == 0) { if (free_cnt == 0) {
@ -276,7 +277,7 @@ PlaybackBuffer<T>::write_zero (guint cnt)
w = n2; w = n2;
} }
g_atomic_int_set (&write_idx, w); write_idx.store (w);
return to_write; return to_write;
} }
@ -289,8 +290,8 @@ PlaybackBuffer<T>::read (T *dest, guint cnt, bool commit, guint offset)
return 0; return 0;
} }
guint r = g_atomic_int_get (&read_idx); guint r = read_idx.load ();
const guint w = g_atomic_int_get (&write_idx); const guint w = write_idx.load ();
guint free_cnt = (w > r) ? (w - r) : ((w - r + size) & size_mask); guint free_cnt = (w > r) ? (w - r) : ((w - r + size) & size_mask);
@ -325,8 +326,8 @@ PlaybackBuffer<T>::read (T *dest, guint cnt, bool commit, guint offset)
if (commit) { if (commit) {
SpinLock sl (_reservation_lock); SpinLock sl (_reservation_lock);
g_atomic_int_set (&read_idx, r); read_idx.store (r);
g_atomic_int_set (&reserved, std::min (reservation, g_atomic_int_get (&reserved) + to_read)); g_atomic_int_set (&reserved, std::min (reservation, reserved.load () + to_read));
} }
return to_read; return to_read;
} }

View file

@ -23,10 +23,10 @@
#ifndef ringbuffer_h #ifndef ringbuffer_h
#define ringbuffer_h #define ringbuffer_h
#include <atomic>
#include <cstring> #include <cstring>
#include "pbd/libpbd_visibility.h" #include "pbd/libpbd_visibility.h"
#include "pbd/g_atomic_compat.h"
namespace PBD { namespace PBD {
@ -34,11 +34,11 @@ template<class T>
class /*LIBPBD_API*/ RingBuffer class /*LIBPBD_API*/ RingBuffer
{ {
public: public:
RingBuffer (guint sz) { RingBuffer (size_t sz) {
#if 0 #if 0
size = ffs(sz); /* find first [bit] set is a single inlined assembly instruction. But it looks like the API rounds up so... */ size = ffs(sz); /* find first [bit] set is a single inlined assembly instruction. But it looks like the API rounds up so... */
#endif #endif
guint power_of_two; size_t power_of_two;
for (power_of_two = 1; 1U<<power_of_two < sz; power_of_two++) {} for (power_of_two = 1; 1U<<power_of_two < sz; power_of_two++) {}
size = 1<<power_of_two; size = 1<<power_of_two;
size_mask = size; size_mask = size;
@ -53,44 +53,44 @@ public:
void reset () { void reset () {
/* !!! NOT THREAD SAFE !!! */ /* !!! NOT THREAD SAFE !!! */
g_atomic_int_set (&write_idx, 0); write_idx.store (0);
g_atomic_int_set (&read_idx, 0); read_idx.store (0);
} }
void set (guint r, guint w) { void set (size_t r, size_t w) {
/* !!! NOT THREAD SAFE !!! */ /* !!! NOT THREAD SAFE !!! */
g_atomic_int_set (&write_idx, w); write_idx.store (w);
g_atomic_int_set (&read_idx, r); read_idx.store (r);
} }
guint read (T *dest, guint cnt); size_t read (T *dest, size_t cnt);
guint write (T const * src, guint cnt); size_t write (T const * src, size_t cnt);
struct rw_vector { struct rw_vector {
T *buf[2]; T *buf[2];
guint len[2]; size_t len[2];
}; };
void get_read_vector (rw_vector *); void get_read_vector (rw_vector *);
void get_write_vector (rw_vector *); void get_write_vector (rw_vector *);
void decrement_read_idx (guint cnt) { void decrement_read_idx (size_t cnt) {
g_atomic_int_set (&read_idx, (g_atomic_int_get(&read_idx) - cnt) & size_mask); read_idx.store ((read_idx.load() - cnt) & size_mask);
} }
void increment_read_idx (guint cnt) { void increment_read_idx (size_t cnt) {
g_atomic_int_set (&read_idx, (g_atomic_int_get(&read_idx) + cnt) & size_mask); read_idx.store ((read_idx.load () + cnt) & size_mask);
} }
void increment_write_idx (guint cnt) { void increment_write_idx (size_t cnt) {
g_atomic_int_set (&write_idx, (g_atomic_int_get(&write_idx) + cnt) & size_mask); write_idx.store ((write_idx.load () + cnt) & size_mask);
} }
guint write_space () const { size_t write_space () const {
guint w, r; size_t w, r;
w = g_atomic_int_get (&write_idx); w = write_idx.load ();
r = g_atomic_int_get (&read_idx); r = read_idx.load ();
if (w > r) { if (w > r) {
return ((r - w + size) & size_mask) - 1; return ((r - w + size) & size_mask) - 1;
@ -101,11 +101,11 @@ public:
} }
} }
guint read_space () const { size_t read_space () const {
guint w, r; size_t w, r;
w = g_atomic_int_get (&write_idx); w = write_idx.load ();
r = g_atomic_int_get (&read_idx); r = read_idx.load ();
if (w > r) { if (w > r) {
return w - r; return w - r;
@ -115,31 +115,31 @@ public:
} }
T *buffer () { return buf; } T *buffer () { return buf; }
guint get_write_idx () const { return g_atomic_int_get (&write_idx); } size_t get_write_idx () const { return write_idx.load (); }
guint get_read_idx () const { return g_atomic_int_get (&read_idx); } size_t get_read_idx () const { return read_idx.load (); }
guint bufsize () const { return size; } size_t bufsize () const { return size; }
protected: protected:
T *buf; T *buf;
guint size; size_t size;
guint size_mask; size_t size_mask;
mutable GATOMIC_QUAL gint write_idx; mutable std::atomic<int> write_idx;
mutable GATOMIC_QUAL gint read_idx; mutable std::atomic<int> read_idx;
private: private:
RingBuffer (RingBuffer const&); RingBuffer (RingBuffer const&);
}; };
template<class T> /*LIBPBD_API*/ guint template<class T> /*LIBPBD_API*/ size_t
RingBuffer<T>::read (T *dest, guint cnt) RingBuffer<T>::read (T *dest, size_t cnt)
{ {
guint free_cnt; size_t free_cnt;
guint cnt2; size_t cnt2;
guint to_read; size_t to_read;
guint n1, n2; size_t n1, n2;
guint priv_read_idx; size_t priv_read_idx;
priv_read_idx = g_atomic_int_get (&read_idx); priv_read_idx = read_idx.load ();
if ((free_cnt = read_space ()) == 0) { if ((free_cnt = read_space ()) == 0) {
return 0; return 0;
@ -165,21 +165,21 @@ RingBuffer<T>::read (T *dest, guint cnt)
priv_read_idx = n2; priv_read_idx = n2;
} }
g_atomic_int_set (&read_idx, priv_read_idx); read_idx.store (priv_read_idx);
return to_read; return to_read;
} }
template<class T> /*LIBPBD_API*/ guint template<class T> /*LIBPBD_API*/ size_t
RingBuffer<T>::write (T const *src, guint cnt) RingBuffer<T>::write (T const *src, size_t cnt)
{ {
guint free_cnt; size_t free_cnt;
guint cnt2; size_t cnt2;
guint to_write; size_t to_write;
guint n1, n2; size_t n1, n2;
guint priv_write_idx; size_t priv_write_idx;
priv_write_idx = g_atomic_int_get (&write_idx); priv_write_idx = write_idx.load ();
if ((free_cnt = write_space ()) == 0) { if ((free_cnt = write_space ()) == 0) {
return 0; return 0;
@ -205,7 +205,7 @@ RingBuffer<T>::write (T const *src, guint cnt)
priv_write_idx = n2; priv_write_idx = n2;
} }
g_atomic_int_set (&write_idx, priv_write_idx); write_idx.store (priv_write_idx);
return to_write; return to_write;
} }
@ -213,12 +213,12 @@ template<class T> /*LIBPBD_API*/ void
RingBuffer<T>::get_read_vector (typename RingBuffer<T>::rw_vector *vec) RingBuffer<T>::get_read_vector (typename RingBuffer<T>::rw_vector *vec)
{ {
guint free_cnt; size_t free_cnt;
guint cnt2; size_t cnt2;
guint w, r; size_t w, r;
w = g_atomic_int_get (&write_idx); w = write_idx.load ();
r = g_atomic_int_get (&read_idx); r = read_idx.load ();
if (w > r) { if (w > r) {
free_cnt = w - r; free_cnt = w - r;
@ -254,12 +254,12 @@ template<class T> /*LIBPBD_API*/ void
RingBuffer<T>::get_write_vector (typename RingBuffer<T>::rw_vector *vec) RingBuffer<T>::get_write_vector (typename RingBuffer<T>::rw_vector *vec)
{ {
guint free_cnt; size_t free_cnt;
guint cnt2; size_t cnt2;
guint w, r; size_t w, r;
w = g_atomic_int_get (&write_idx); w = write_idx.load ();
r = g_atomic_int_get (&read_idx); r = read_idx.load ();
if (w > r) { if (w > r) {
free_cnt = ((r - w + size) & size_mask) - 1; free_cnt = ((r - w + size) & size_mask) - 1;

View file

@ -23,11 +23,11 @@
//#include <sys/mman.h> //#include <sys/mman.h>
#include <atomic>
#include <cstring> #include <cstring>
#include <glib.h> #include <glib.h>
#include "pbd/libpbd_visibility.h" #include "pbd/libpbd_visibility.h"
#include "pbd/g_atomic_compat.h"
namespace PBD { namespace PBD {
@ -49,14 +49,14 @@ class /*LIBPBD_API*/ RingBufferNPT
void reset () { void reset () {
/* !!! NOT THREAD SAFE !!! */ /* !!! NOT THREAD SAFE !!! */
g_atomic_int_set (&write_ptr, 0); write_ptr.store (0);
g_atomic_int_set (&read_ptr, 0); read_ptr.store (0);
} }
void set (size_t r, size_t w) { void set (size_t r, size_t w) {
/* !!! NOT THREAD SAFE !!! */ /* !!! NOT THREAD SAFE !!! */
g_atomic_int_set (&write_ptr, w); write_ptr.store (w);
g_atomic_int_set (&read_ptr, r); read_ptr.store (r);
} }
size_t read (T *dest, size_t cnt); size_t read (T *dest, size_t cnt);
@ -72,22 +72,22 @@ class /*LIBPBD_API*/ RingBufferNPT
void get_write_vector (rw_vector *); void get_write_vector (rw_vector *);
void decrement_read_ptr (size_t cnt) { void decrement_read_ptr (size_t cnt) {
g_atomic_int_set (&read_ptr, (g_atomic_int_get(&read_ptr) - cnt) % size); g_atomic_int_set (&read_ptr, (read_ptr.load () - cnt) % size);
} }
void increment_read_ptr (size_t cnt) { void increment_read_ptr (size_t cnt) {
g_atomic_int_set (&read_ptr, (g_atomic_int_get(&read_ptr) + cnt) % size); g_atomic_int_set (&read_ptr, (read_ptr.load () + cnt) % size);
} }
void increment_write_ptr (size_t cnt) { void increment_write_ptr (size_t cnt) {
g_atomic_int_set (&write_ptr, (g_atomic_int_get(&write_ptr) + cnt) % size); g_atomic_int_set (&write_ptr, (write_ptr.load () + cnt) % size);
} }
size_t write_space () { size_t write_space () {
size_t w, r; size_t w, r;
w = g_atomic_int_get (&write_ptr); w = write_ptr.load ();
r = g_atomic_int_get (&read_ptr); r = read_ptr.load ();
if (w > r) { if (w > r) {
return ((r - w + size) % size) - 1; return ((r - w + size) % size) - 1;
@ -101,8 +101,8 @@ class /*LIBPBD_API*/ RingBufferNPT
size_t read_space () { size_t read_space () {
size_t w, r; size_t w, r;
w = g_atomic_int_get (&write_ptr); w = write_ptr.load ();
r = g_atomic_int_get (&read_ptr); r = read_ptr.load ();
if (w > r) { if (w > r) {
return w - r; return w - r;
@ -112,15 +112,15 @@ class /*LIBPBD_API*/ RingBufferNPT
} }
T *buffer () { return buf; } T *buffer () { return buf; }
size_t get_write_ptr () const { return g_atomic_int_get (&write_ptr); } size_t get_write_ptr () const { return write_ptr.load (); }
size_t get_read_ptr () const { return g_atomic_int_get (&read_ptr); } size_t get_read_ptr () const { return read_ptr.load (); }
size_t bufsize () const { return size; } size_t bufsize () const { return size; }
protected: protected:
T *buf; T *buf;
size_t size; size_t size;
mutable GATOMIC_QUAL gint write_ptr; mutable std::atomic<int> write_ptr;
mutable GATOMIC_QUAL gint read_ptr; mutable std::atomic<int> read_ptr;
private: private:
RingBufferNPT (RingBufferNPT const&); RingBufferNPT (RingBufferNPT const&);
@ -135,7 +135,7 @@ RingBufferNPT<T>::read (T *dest, size_t cnt)
size_t n1, n2; size_t n1, n2;
size_t priv_read_ptr; size_t priv_read_ptr;
priv_read_ptr = g_atomic_int_get (&read_ptr); priv_read_ptr = read_ptr.load ();
if ((free_cnt = read_space ()) == 0) { if ((free_cnt = read_space ()) == 0) {
return 0; return 0;
@ -174,7 +174,7 @@ RingBufferNPT<T>::write (const T *src, size_t cnt)
size_t n1, n2; size_t n1, n2;
size_t priv_write_ptr; size_t priv_write_ptr;
priv_write_ptr = g_atomic_int_get (&write_ptr); priv_write_ptr = write_ptr.load ();
if ((free_cnt = write_space ()) == 0) { if ((free_cnt = write_space ()) == 0) {
return 0; return 0;
@ -217,8 +217,8 @@ RingBufferNPT<T>::get_read_vector (typename RingBufferNPT<T>::rw_vector *vec)
size_t cnt2; size_t cnt2;
size_t w, r; size_t w, r;
w = g_atomic_int_get (&write_ptr); w = write_ptr.load ();
r = g_atomic_int_get (&read_ptr); r = read_ptr.load ();
if (w > r) { if (w > r) {
free_cnt = w - r; free_cnt = w - r;
@ -257,8 +257,8 @@ RingBufferNPT<T>::get_write_vector (typename RingBufferNPT<T>::rw_vector *vec)
size_t cnt2; size_t cnt2;
size_t w, r; size_t w, r;
w = g_atomic_int_get (&write_ptr); w = write_ptr.load ();
r = g_atomic_int_get (&read_ptr); r = read_ptr.load ();
if (w > r) { if (w > r) {
free_cnt = ((r - w + size) % size) - 1; free_cnt = ((r - w + size) % size) - 1;

View file

@ -23,6 +23,7 @@
#ifndef __pbd_stateful_h__ #ifndef __pbd_stateful_h__
#define __pbd_stateful_h__ #define __pbd_stateful_h__
#include <atomic>
#include <string> #include <string>
#include <list> #include <list>
#include <cassert> #include <cassert>
@ -32,7 +33,6 @@
#include "pbd/xml++.h" #include "pbd/xml++.h"
#include "pbd/property_basics.h" #include "pbd/property_basics.h"
#include "pbd/signals.h" #include "pbd/signals.h"
#include "pbd/g_atomic_compat.h"
class XMLNode; class XMLNode;
@ -105,7 +105,7 @@ class LIBPBD_API Stateful {
virtual void suspend_property_changes (); virtual void suspend_property_changes ();
virtual void resume_property_changes (); virtual void resume_property_changes ();
bool property_changes_suspended() const { return g_atomic_int_get (const_cast<GATOMIC_QUAL gint*> (&_stateful_frozen)) > 0; } bool property_changes_suspended() const { return g_atomic_int_get (const_cast<std::atomic<int>*> (&_stateful_frozen)) > 0; }
protected: protected:
@ -142,7 +142,7 @@ class LIBPBD_API Stateful {
static Glib::Threads::Private<bool> _regenerate_xml_or_string_ids; static Glib::Threads::Private<bool> _regenerate_xml_or_string_ids;
PBD::ID _id; PBD::ID _id;
GATOMIC_QUAL gint _stateful_frozen; std::atomic<int> _stateful_frozen;
static void set_regenerate_xml_and_string_ids_in_this_thread (bool yn); static void set_regenerate_xml_and_string_ids_in_this_thread (bool yn);
}; };

View file

@ -87,7 +87,7 @@ Pool::alloc ()
if (free_list.read (&ptr, 1) < 1) { if (free_list.read (&ptr, 1) < 1) {
PBD::stacktrace (std::cerr, 20); PBD::stacktrace (std::cerr, 20);
if (_dump) { if (_dump) {
printf ("RingBuffer write-idx: %u read-idx: %u\n", free_list.get_write_idx (), free_list.get_read_idx ()); std::cout << "RingBuffer write-idx: " << free_list.get_write_idx () << " read-idx: " << free_list.get_read_idx () << '\n';
void** _block = free_list.buffer (); void** _block = free_list.buffer ();
for (size_t i = 0; i < free_list.bufsize (); ++i) { for (size_t i = 0; i < free_list.bufsize (); ++i) {
_dump (i, _block[i]); _dump (i, _block[i]);

View file

@ -24,6 +24,7 @@
#include <glibmm/fileutils.h> #include <glibmm/fileutils.h>
#include <glibmm/miscutils.h> #include <glibmm/miscutils.h>
#include "pbd/atomic.h"
#include "pbd/debug.h" #include "pbd/debug.h"
#include "pbd/stateful.h" #include "pbd/stateful.h"
#include "pbd/types_convert.h" #include "pbd/types_convert.h"
@ -48,7 +49,7 @@ Stateful::Stateful ()
, _instant_xml (nullptr) , _instant_xml (nullptr)
, _properties (new OwnedPropertyList) , _properties (new OwnedPropertyList)
{ {
g_atomic_int_set (&_stateful_frozen, 0); _stateful_frozen.store (0);
} }
Stateful::~Stateful () Stateful::~Stateful ()
@ -298,7 +299,7 @@ Stateful::send_change (const PropertyChange& what_changed)
void void
Stateful::suspend_property_changes () Stateful::suspend_property_changes ()
{ {
g_atomic_int_add (&_stateful_frozen, 1); _stateful_frozen.fetch_add (1);
} }
void void
@ -309,7 +310,7 @@ Stateful::resume_property_changes ()
{ {
Glib::Threads::Mutex::Lock lm (_lock); Glib::Threads::Mutex::Lock lm (_lock);
if (property_changes_suspended() && g_atomic_int_dec_and_test (&_stateful_frozen) == FALSE) { if (property_changes_suspended() && PBD::atomic_dec_and_test (_stateful_frozen) == FALSE) {
return; return;
} }

View file

@ -379,7 +379,7 @@ WaveViewThreads::stop_threads ()
/*-------------------------------------------------*/ /*-------------------------------------------------*/
WaveViewDrawRequest::WaveViewDrawRequest () WaveViewDrawRequest::WaveViewDrawRequest ()
{ {
g_atomic_int_set (&_stop, 0); _stop.store (0);
} }
WaveViewDrawRequest::~WaveViewDrawRequest () WaveViewDrawRequest::~WaveViewDrawRequest ()

View file

@ -203,8 +203,8 @@ public:
WaveViewDrawRequest (); WaveViewDrawRequest ();
~WaveViewDrawRequest (); ~WaveViewDrawRequest ();
bool stopped() const { return (bool) g_atomic_int_get (&_stop); } bool stopped() const { return (bool) _stop.load (); }
void cancel() { g_atomic_int_set (&_stop, 1); } void cancel() { _stop.store (1); }
bool finished() { return image->finished(); } bool finished() { return image->finished(); }
std::shared_ptr<WaveViewImage> image; std::shared_ptr<WaveViewImage> image;
@ -214,7 +214,7 @@ public:
} }
private: private:
GATOMIC_QUAL gint _stop; /* intended for atomic access */ std::atomic<int> _stop; /* intended for atomic access */
}; };
class WaveViewCache; class WaveViewCache;