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

View File

@ -27,6 +27,7 @@
#include "libardour-config.h"
#endif
#include <atomic>
#include <iostream>
#include <list>
#include <set>
@ -38,7 +39,6 @@
#include "pbd/signals.h"
#include "pbd/pthread_utils.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h"
#include "ardour/data_type.h"
@ -118,7 +118,7 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr
bool is_realtime() const;
// 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_sample_rate (float);
@ -297,19 +297,19 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr
std::string _last_backend_error_string;
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::Mutex _reset_request_lock;
GATOMIC_QUAL gint _stop_hw_reset_processing;
std::atomic<int> _stop_hw_reset_processing;
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::Mutex _devicelist_update_lock;
GATOMIC_QUAL gint _stop_hw_devicelist_processing;
std::atomic<int> _stop_hw_devicelist_processing;
uint32_t _start_cnt;
uint32_t _init_countdown;
GATOMIC_QUAL gint _pending_playback_latency_callback;
GATOMIC_QUAL gint _pending_capture_latency_callback;
std::atomic<int> _pending_playback_latency_callback;
std::atomic<int> _pending_capture_latency_callback;
void start_hw_event_processing();
void stop_hw_event_processing();

View File

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

View File

@ -23,7 +23,8 @@
#ifndef __ardour_automation_event_h__
#define __ardour_automation_event_h__
#include <stdint.h>
#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <list>
#include <cmath>
@ -37,7 +38,6 @@
#include "pbd/xml++.h"
#include "pbd/statefuldestructible.h"
#include "pbd/properties.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h"
@ -109,7 +109,7 @@ public:
void start_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 touch_enabled () const { return _state & (Touch | Latch); }
@ -136,7 +136,7 @@ private:
void maybe_signal_changed ();
AutoState _state;
GATOMIC_QUAL gint _touching;
std::atomic<int> _touching;
PBD::ScopedConnection _writepass_connection;

View File

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

View File

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

View File

@ -20,9 +20,9 @@
#ifndef _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"
@ -114,7 +114,7 @@ public:
static void dec_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 alloc_loop_declick (samplecnt_t sample_rate);
@ -202,7 +202,7 @@ private:
IOChange input_change_pending;
samplepos_t file_sample[DataType::num_types];
mutable GATOMIC_QUAL gint _pending_overwrite;
mutable std::atomic<OverwriteReason> _pending_overwrite;
DeclickAmp _declick_amp;
sampleoffset_t _declick_offs;
@ -213,7 +213,7 @@ private:
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_out;

View File

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

View File

@ -19,7 +19,8 @@
#ifndef _ardour_ffmpegfile_importable_source_h_
#define _ardour_ffmpegfile_importable_source_h_
#include "pbd/g_atomic_compat.h"
#include <atomic>
#include "pbd/ringbuffer.h"
#include "ardour/importable_source.h"
@ -68,7 +69,7 @@ private:
PBD::RingBuffer<Sample> _buffer;
/* 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
* 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__
#define __ardour_graph_h__
#include <atomic>
#include <list>
#include <memory>
#include <set>
@ -30,7 +31,6 @@
#include <vector>
#include "pbd/g_atomic_compat.h"
#include "pbd/mpmc_queue.h"
#include "pbd/semutils.h"
@ -107,28 +107,28 @@ private:
void helper_thread ();
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 */
PBD::Semaphore _execution_sem;
/** 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 */
PBD::Semaphore _callback_start_sem;
PBD::Semaphore _callback_done_sem;
/** 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;
/* number of background worker threads >= 0 */
GATOMIC_QUAL guint _n_workers;
std::atomic<unsigned int> _n_workers;
/* flag to terminate background threads */
GATOMIC_QUAL gint _terminate;
std::atomic<int> _terminate;
/* graph chain */
GraphChain const* _graph_chain;

View File

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

View File

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

View File

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

View File

@ -19,12 +19,12 @@
#ifndef __ardour_channel_filter_h__
#define __ardour_channel_filter_h__
#include <stdint.h>
#include <atomic>
#include <cstdint>
#include <glib.h>
#include "pbd/signals.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/types.h"
@ -73,24 +73,24 @@ public:
/** Atomically get both the channel mode and mask. */
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);
*mask = (mm & 0x0000FFFF);
}
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 {
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> ChannelModeChanged;
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 */

View File

@ -66,7 +66,7 @@ public:
void start_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 touch_enabled() const { return _auto_state & (Touch | Latch); }
@ -84,7 +84,7 @@ protected:
bool _has_state;
uint32_t _responding_to_control_auto_state_change;
GATOMIC_QUAL gint _touching;
std::atomic<int> _touching;
void control_auto_state_changed (AutoState);

View File

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

View File

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

View File

@ -20,6 +20,7 @@
#ifndef _libardour_port_engine_shared_h_
#define _libardour_port_engine_shared_h_
#include <atomic>
#include <map>
#include <memory>
#include <set>
@ -29,7 +30,6 @@
#include "pbd/natsort.h"
#include "pbd/rcu.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/libardour_visibility.h"
#include "ardour/port_engine.h"
@ -195,7 +195,7 @@ protected:
std::vector<PortConnectData *> _port_connection_queue;
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) {
pthread_mutex_lock (&_port_callback_mutex);
@ -204,7 +204,7 @@ protected:
}
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 ();

View File

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

View File

@ -24,12 +24,12 @@
#include <iostream>
#include <string>
#include <stdint.h>
#include <atomic>
#include <cstdint>
#include "pbd/signals.h"
#include "pbd/stateful.h"
#include "pbd/properties.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/libardour_visibility.h"
@ -287,7 +287,7 @@ class LIBARDOUR_API PresentationInfo : public PBD::Stateful
static PBD::PropertyChange _pending_static_changes;
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;
};

View File

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

View File

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

View File

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

View File

@ -23,6 +23,7 @@
#ifndef __ardour_source_h__
#define __ardour_source_h__
#include <atomic>
#include <memory>
#include <string>
#include <set>
@ -32,7 +33,6 @@
#include <boost/utility.hpp>
#include "pbd/statefuldestructible.h"
#include "pbd/g_atomic_compat.h"
#include "ardour/ardour.h"
#include "ardour/session_object.h"
@ -140,7 +140,7 @@ public:
virtual void inc_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; }
uint32_t level() const { return _level; }
@ -162,7 +162,7 @@ public:
timepos_t _natural_position;
bool _have_natural_position;
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 */
std::string _ancestor_name;
std::string _captured_for;

View File

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

View File

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

View File

@ -75,7 +75,7 @@ using namespace PBD;
AudioEngine* AudioEngine::_instance = 0;
static GATOMIC_QUAL gint audioengine_thread_cnt = 1;
static std::atomic<int> audioengine_thread_cnt (1);
#ifdef SILENCE_AFTER
#define SILENCE_AFTER_SECONDS 600
@ -112,12 +112,12 @@ AudioEngine::AudioEngine ()
start_hw_event_processing();
discover_backends ();
g_atomic_int_set (&_hw_reset_request_count, 0);
g_atomic_int_set (&_pending_playback_latency_callback, 0);
g_atomic_int_set (&_pending_capture_latency_callback, 0);
g_atomic_int_set (&_hw_devicelist_update_count, 0);
g_atomic_int_set (&_stop_hw_reset_processing, 0);
g_atomic_int_set (&_stop_hw_devicelist_processing, 0);
_hw_reset_request_count.store (0);
_pending_playback_latency_callback.store (0);
_pending_capture_latency_callback.store (0);
_hw_devicelist_update_count.store (0);
_stop_hw_reset_processing.store (0);
_stop_hw_devicelist_processing.store (0);
}
AudioEngine::~AudioEngine ()
@ -305,10 +305,12 @@ AudioEngine::process_callback (pframes_t nframes)
if (_session && !_session->processing_blocked ()) {
bool lp = 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;
}
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;
}
if (lp || lc) {
@ -653,14 +655,14 @@ void
AudioEngine::request_backend_reset()
{
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 ();
}
int
AudioEngine::backend_reset_requested()
{
return g_atomic_int_get (&_hw_reset_request_count);
return _hw_reset_request_count.load ();
}
void
@ -671,14 +673,14 @@ AudioEngine::do_reset_backend()
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();
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;
DeviceResetStarted(); // notify about device reset to be started
@ -720,7 +722,7 @@ void
AudioEngine::request_device_list_update()
{
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 ();
}
@ -734,13 +736,13 @@ AudioEngine::do_devicelist_update()
while (!_stop_hw_devicelist_processing) {
if (g_atomic_int_get (&_hw_devicelist_update_count)) {
if (_hw_devicelist_update_count.load ()) {
_devicelist_update_lock.unlock();
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 */
_devicelist_update_lock.lock();
@ -756,14 +758,14 @@ void
AudioEngine::start_hw_event_processing()
{
if (_hw_reset_event_thread == 0) {
g_atomic_int_set (&_hw_reset_request_count, 0);
g_atomic_int_set (&_stop_hw_reset_processing, 0);
_hw_reset_request_count.store (0);
_stop_hw_reset_processing.store (0);
_hw_reset_event_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_reset_backend, this));
}
if (_hw_devicelist_update_thread == 0) {
g_atomic_int_set (&_hw_devicelist_update_count, 0);
g_atomic_int_set (&_stop_hw_devicelist_processing, 0);
_hw_devicelist_update_count.store (0);
_stop_hw_devicelist_processing.store (0);
_hw_devicelist_update_thread = PBD::Thread::create (boost::bind (&AudioEngine::do_devicelist_update, this));
}
}
@ -773,16 +775,16 @@ void
AudioEngine::stop_hw_event_processing()
{
if (_hw_reset_event_thread) {
g_atomic_int_set (&_stop_hw_reset_processing, 1);
g_atomic_int_set (&_hw_reset_request_count, 0);
_stop_hw_reset_processing.store (1);
_hw_reset_request_count.store (0);
_hw_reset_condition.signal ();
_hw_reset_event_thread->join ();
_hw_reset_event_thread = 0;
}
if (_hw_devicelist_update_thread) {
g_atomic_int_set (&_stop_hw_devicelist_processing, 1);
g_atomic_int_set (&_hw_devicelist_update_count, 0);
_stop_hw_devicelist_processing.store (1);
_hw_devicelist_update_count.store (0);
_hw_devicelist_update_condition.signal ();
_hw_devicelist_update_thread->join ();
_hw_devicelist_update_thread = 0;
@ -798,8 +800,8 @@ AudioEngine::set_session (Session *s)
if (_session) {
_init_countdown = std::max (4, (int)(_backend->sample_rate () / _backend->buffer_size ()) / 8);
g_atomic_int_set (&_pending_playback_latency_callback, 0);
g_atomic_int_set (&_pending_capture_latency_callback, 0);
_pending_playback_latency_callback.store (0);
_pending_capture_latency_callback.store (0);
}
}
@ -1451,7 +1453,7 @@ AudioEngine::thread_init_callback (void* arg)
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);
SessionEvent::create_per_thread_pool (thread_name, 512);
@ -1525,9 +1527,9 @@ void
AudioEngine::queue_latency_update (bool for_playback)
{
if (for_playback) {
g_atomic_int_set (&_pending_playback_latency_callback, 1);
_pending_playback_latency_callback.store (1);
} 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)
, _import_position (0)
{
g_atomic_int_set (&_auditioning, 0);
_auditioning.store (0);
}
int
@ -365,7 +365,7 @@ Auditioner::update_controls (BufferSet const& bufs)
void
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
to remain active.
*/
@ -483,7 +483,7 @@ Auditioner::audition_region (std::shared_ptr<Region> region, bool loop)
current_sample = offset.samples();
g_atomic_int_set (&_auditioning, 1);
_auditioning.store (1);
}
void
@ -503,7 +503,7 @@ Auditioner::play_audition (samplecnt_t nframes)
samplecnt_t this_nframes;
int ret;
if (g_atomic_int_get (&_auditioning) == 0) {
if (_auditioning.load () == 0) {
silence (nframes);
if (_reload_synth) {
unload_synth (false);
@ -581,12 +581,12 @@ Auditioner::play_audition (samplecnt_t nframes)
void
Auditioner::cancel_audition () {
g_atomic_int_set (&_auditioning, 0);
_auditioning.store (0);
}
bool
Auditioner::auditioning() const {
return g_atomic_int_get (&_auditioning);
return _auditioning.load ();
}
void

View File

@ -66,7 +66,7 @@ AutomationList::AutomationList (const Evoral::Parameter& id, const Evoral::Param
, _before (0)
{
_state = Off;
g_atomic_int_set (&_touching, 0);
_touching.store (0);
_interpolation = default_interpolation ();
create_curve_if_necessary();
@ -80,7 +80,7 @@ AutomationList::AutomationList (const Evoral::Parameter& id, Temporal::TimeDomai
, _before (0)
{
_state = Off;
g_atomic_int_set (&_touching, 0);
_touching.store (0);
_interpolation = default_interpolation ();
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 */
, _before (0)
{
g_atomic_int_set (&_touching, 0);
_touching.store (0);
_interpolation = default_interpolation ();
_state = Off;
@ -185,7 +185,7 @@ AutomationList::operator= (const AutomationList& other)
*/
ControlList::operator= (other);
_state = other._state;
_touching = other._touching;
_touching.store (other._touching);
ControlList::thaw ();
}
@ -264,20 +264,20 @@ AutomationList::write_pass_finished (timepos_t const & when, double thinning_fac
void
AutomationList::start_touch (timepos_t const & when)
{
g_atomic_int_set (&_touching, 1);
_touching.store (1);
}
void
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),
so we've nothing to do.
*/
return;
}
g_atomic_int_set (&_touching, 0);
_touching.store (0);
}
/* _before may be owned by the undo stack,

View File

@ -60,7 +60,7 @@ Butler::Butler (Session& s)
, pool_trash (16)
, _xthread (true)
{
g_atomic_int_set (&should_do_transport_work, 0);
should_do_transport_work.store (0);
SessionEvent::pool->set_trash (&pool_trash);
/* catch future changes to parameters */
@ -381,7 +381,7 @@ void
Butler::schedule_transport_work ()
{
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 ();
}
@ -432,7 +432,7 @@ Butler::wait_until_finished ()
bool
Butler::transport_work_requested () const
{
return g_atomic_int_get (&should_do_transport_work);
return should_do_transport_work.load ();
}
void

View File

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

View File

@ -52,7 +52,7 @@ PBD::Signal0<void> DiskReader::Underrun;
Sample* DiskReader::_sum_buffer = 0;
Sample* DiskReader::_mixdown_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_out;
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::MIDI] = 0;
g_atomic_int_set (&_pending_overwrite, 0);
_pending_overwrite.store (OverwriteReason (0));
}
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
* 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);
}
@ -279,7 +279,7 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
sampleoffset_t disk_samples_to_consume;
MonitorState ms = _track.monitoring_state ();
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()) {
return;
@ -547,7 +547,7 @@ DiskReader::configuration_changed ()
bool
DiskReader::pending_overwrite () const
{
return g_atomic_int_get (&_pending_overwrite) != 0;
return _pending_overwrite.load () != 0;
}
void
@ -613,9 +613,9 @@ DiskReader::set_pending_overwrite (OverwriteReason why)
}
while (true) {
OverwriteReason current = OverwriteReason (g_atomic_int_get (&_pending_overwrite));
OverwriteReason current = OverwriteReason (_pending_overwrite.load ());
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;
}
}
@ -787,23 +787,23 @@ DiskReader::overwrite_existing_buffers ()
{
/* 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;
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 ()) {
ret = false;
}
}
if (g_atomic_int_get (&_pending_overwrite) & (PlaylistModified | PlaylistChanged)) {
if (_pending_overwrite.load () & (PlaylistModified | PlaylistChanged)) {
if (_playlists[DataType::MIDI] && !overwrite_existing_midi ()) {
ret = false;
}
}
g_atomic_int_set (&_pending_overwrite, 0);
_pending_overwrite.store (OverwriteReason (0));
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));
@ -1456,7 +1456,7 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
target = &dst;
}
if (g_atomic_int_get (&_no_disk_output)) {
if (_no_disk_output.load ()) {
return;
}
@ -1547,7 +1547,7 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
void
DiskReader::inc_no_disk_output ()
{
g_atomic_int_inc (&_no_disk_output);
_no_disk_output.fetch_add (1);
}
void
@ -1560,9 +1560,9 @@ DiskReader::dec_no_disk_output ()
*/
do {
gint v = g_atomic_int_get (&_no_disk_output);
gint v = _no_disk_output.load ();
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;
}
} else {

View File

@ -37,6 +37,7 @@
#include "ardour/session.h"
#include "ardour/smf_source.h"
#include "pbd/atomic.h"
#include "pbd/i18n.h"
using namespace ARDOUR;
@ -64,10 +65,10 @@ DiskWriter::DiskWriter (Session& s, Track& t, string const & str, DiskIOProcesso
DiskIOProcessor::init ();
_xruns.reserve (128);
g_atomic_int_set (&_record_enabled, 0);
g_atomic_int_set (&_record_safe, 0);
g_atomic_int_set (&_samples_pending_write, 0);
g_atomic_int_set (&_num_captured_loops, 0);
_record_enabled.store (0);
_record_safe.store (0);
_samples_pending_write.store (0);
_num_captured_loops.store (0);
}
DiskWriter::~DiskWriter ()
@ -285,25 +286,25 @@ DiskWriter::calculate_record_range (Temporal::OverlapType ot, samplepos_t transp
void
DiskWriter::engage_record_enable ()
{
g_atomic_int_set (&_record_enabled, 1);
_record_enabled.store (1);
}
void
DiskWriter::disengage_record_enable ()
{
g_atomic_int_set (&_record_enabled, 0);
_record_enabled.store (0);
}
void
DiskWriter::engage_record_safe ()
{
g_atomic_int_set (&_record_safe, 1);
_record_safe.store (1);
}
void
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 */
@ -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);
}
g_atomic_int_set (&_samples_pending_write, 0);
g_atomic_int_set (&_num_captured_loops, 0);
_samples_pending_write.store (0);
_num_captured_loops.store (0);
_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
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();
if (event_time < 0 || event_time < _first_recordable_sample) {
/* 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) {
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;
timecnt_t 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 {
ci->loop_offset = 0;
}
@ -1003,7 +1004,7 @@ DiskWriter::do_flush (RunContext ctxt, bool force_flush)
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 ||
_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;
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.
*/
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 ()
{
// TODO: actually signal did_read_data to unblock
g_atomic_int_set (&_ffmpeg_should_terminate, 1);
_ffmpeg_should_terminate.store (1);
delete _ffmpeg_exec;
_ffmpeg_exec = 0;
_ffmpeg_conn.disconnect ();
_buffer.reset ();
_read_pos = 0;
g_atomic_int_set (&_ffmpeg_should_terminate, 0);
_ffmpeg_should_terminate.store (0);
}
void
@ -221,7 +221,7 @@ FFMPEGFileImportableSource::did_read_data (std::string data, size_t size)
const char* cur = data.data ();
while (n_samples > 0) {
if (g_atomic_int_get (&_ffmpeg_should_terminate)) {
if (_ffmpeg_should_terminate.load ()) {
break;
}

View File

@ -70,11 +70,11 @@ Graph::Graph (Session& session)
, _graph_empty (true)
, _graph_chain (0)
{
g_atomic_int_set (&_terminal_refcnt, 0);
g_atomic_int_set (&_terminate, 0);
g_atomic_int_set (&_n_workers, 0);
g_atomic_int_set (&_idle_thread_cnt, 0);
g_atomic_int_set (&_trigger_queue_size, 0);
_terminal_refcnt.store (0);
_terminate.store (0);
_n_workers.store (0);
_idle_thread_cnt.store (0);
_trigger_queue_size.store (0);
/* pre-allocate memory */
_trigger_queue.reserve (1024);
@ -124,7 +124,7 @@ Graph::reset_thread_list ()
}
/* 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) {
throw failed_constructor ();
@ -153,7 +153,7 @@ Graph::session_going_away ()
drop_threads ();
/* now drop all references on the nodes. */
g_atomic_int_set (&_trigger_queue_size, 0);
_trigger_queue_size.store (0);
_trigger_queue.clear ();
_graph_chain = 0;
}
@ -162,7 +162,7 @@ void
Graph::drop_threads ()
{
/* Flag threads to terminate */
g_atomic_int_set (&_terminate, 1);
_terminate.store (1);
/* Wake-up sleeping threads */
guint tc = g_atomic_uint_get (&_idle_thread_cnt);
@ -177,8 +177,8 @@ Graph::drop_threads ()
/* join process threads */
AudioEngine::instance ()->join_process_threads ();
g_atomic_int_set (&_n_workers, 0);
g_atomic_int_set (&_idle_thread_cnt, 0);
_n_workers.store (0);
_idle_thread_cnt.store (0);
/* signal main process thread if it's waiting for an already terminated thread */
_callback_done_sem.signal ();
@ -224,7 +224,7 @@ Graph::prep ()
/* Trigger the initial nodes for processing, which are the ones at the `input' end */
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 ());
}
}
@ -232,7 +232,7 @@ Graph::prep ()
void
Graph::trigger (ProcessNode* n)
{
g_atomic_int_inc (&_trigger_queue_size);
_trigger_queue_size.fetch_add (1);
_trigger_queue.push_back (n);
}
@ -242,7 +242,7 @@ Graph::trigger (ProcessNode* n)
void
Graph::reached_terminal_node ()
{
if (g_atomic_int_dec_and_test (&_terminal_refcnt)) {
if (PBD::atomic_dec_and_test (_terminal_refcnt)) {
again:
/* 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 */
_callback_start_sem.wait ();
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
return;
}
@ -280,7 +280,7 @@ Graph::reached_terminal_node ()
*/
prep ();
if (_graph_empty && !g_atomic_int_get (&_terminate)) {
if (_graph_empty && !_terminate.load ()) {
goto again;
}
/* .. continue in worker-thread */
@ -293,7 +293,7 @@ Graph::run_one ()
{
ProcessNode* to_run = NULL;
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
return;
}
@ -315,19 +315,19 @@ Graph::run_one ()
while (!to_run) {
/* 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));
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 goes to sleep\n", pthread_name ()));
_execution_sem.wait ();
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
return;
}
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 */
_trigger_queue.pop_front (to_run);
@ -342,7 +342,7 @@ Graph::run_one ()
Temporal::TempoMap::fetch ();
/* 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);
DEBUG_TRACE (DEBUG::ProcessThreads, string_compose ("%1 has finished run_one()\n", pthread_name ()));
@ -351,7 +351,7 @@ Graph::run_one ()
void
Graph::helper_thread ()
{
g_atomic_int_inc (&_n_workers);
_n_workers.fetch_add (1);
guint id = g_atomic_uint_get (&_n_workers);
/* This is needed for ARDOUR::Session requests called from rt-processors
@ -370,7 +370,7 @@ Graph::helper_thread ()
pt->get_buffers ();
while (!g_atomic_int_get (&_terminate)) {
while (!_terminate.load ()) {
run_one ();
}
@ -406,7 +406,7 @@ again:
DEBUG_TRACE (DEBUG::ProcessThreads, "main thread is awake\n");
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
pt->drop_buffers ();
delete (pt);
return;
@ -416,14 +416,14 @@ again:
* (later this is done by Graph_reached_terminal_node) */
prep ();
if (_graph_empty && !g_atomic_int_get (&_terminate)) {
if (_graph_empty && !_terminate.load ()) {
_callback_done_sem.signal ();
DEBUG_TRACE (DEBUG::ProcessThreads, "main thread sees graph done, goes back to sleep\n");
goto again;
}
/* After setup, the main-thread just becomes a normal worker */
while (!g_atomic_int_get (&_terminate)) {
while (!_terminate.load ()) {
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));
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
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));
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
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));
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
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));
if (g_atomic_int_get (&_terminate)) {
if (_terminate.load ()) {
return 0;
}

View File

@ -18,6 +18,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "pbd/atomic.h"
#include "ardour/graphnode.h"
#include "ardour/graph.h"
#include "ardour/route.h"
@ -49,7 +51,7 @@ GraphActivision::init_refcount (GraphChain const* const g) const
GraphNode::GraphNode (std::shared_ptr<Graph> graph)
: _graph (graph)
{
g_atomic_int_set (&_refcount, 0);
_refcount.store (0);
}
void
@ -71,7 +73,7 @@ void
GraphNode::trigger ()
{
/* 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()
/* reset reference count for next cycle */
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)
, _window_proxy (0)
{
g_atomic_int_set (&_stat_reset, 0);
g_atomic_int_set (&_reset_meters, 0);
_stat_reset.store (0);
_reset_meters.store (0);
if (_plugin) {
setup ();
@ -430,7 +430,8 @@ IOPlug::connect_and_run (samplepos_t start, pframes_t n_samples)
Temporal::TempoMap::update_thread_tempo_map ();
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 ();
}
@ -466,7 +467,8 @@ IOPlug::connect_and_run (samplepos_t start, pframes_t n_samples)
PortSet& ports (_output->ports());
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 ();
auto a = _audio_input_ports.begin ();
@ -503,7 +505,7 @@ IOPlug::connect_and_run (samplepos_t start, pframes_t n_samples)
void
IOPlug::reset_input_meters ()
{
g_atomic_int_set (&_reset_meters, 1);
_reset_meters.store (1);
}
bool
@ -515,7 +517,7 @@ IOPlug::get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, double& a
void
IOPlug::clear_stats ()
{
g_atomic_int_set (&_stat_reset, 1);
_stat_reset.store (1);
}
std::shared_ptr<ReadOnlyControl>

View File

@ -53,8 +53,8 @@ PeakMeter::PeakMeter (Session& s, const std::string& name)
_meter_type = MeterPeak;
_bufcnt = 0;
g_atomic_int_set (&_reset_dpm, 1);
g_atomic_int_set (&_reset_max, 1);
_reset_dpm.store (1);
_reset_max.store (1);
}
PeakMeter::~PeakMeter ()
@ -96,9 +96,10 @@ PeakMeter::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end
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 */
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_midi = min (current_meters.n_midi (), bufs.count ().n_midi ());
@ -202,7 +203,7 @@ void
PeakMeter::reset ()
{
if (_active || _pending_active) {
g_atomic_int_set (&_reset_dpm, 1);
_reset_dpm.store (1);
} else {
for (size_t i = 0; i < _peak_power.size (); ++i) {
_peak_power[i] = -std::numeric_limits<float>::infinity ();
@ -227,7 +228,7 @@ void
PeakMeter::reset_max ()
{
if (_active || _pending_active) {
g_atomic_int_set (&_reset_max, 1);
_reset_max.store (1);
return;
}
for (size_t i = 0; i < _max_peak_signal.size (); ++i) {
@ -361,7 +362,7 @@ PeakMeter::set_max_channels (const ChanCount& chn)
float
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) {
return 0;
} else {

View File

@ -53,7 +53,7 @@ Pannable::Pannable (Session& s, Temporal::TimeDomain td)
{
//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_elevation_control);
@ -161,7 +161,7 @@ Pannable::start_touch (timepos_t const & when)
ac->alist()->start_touch (when);
}
}
g_atomic_int_set (&_touching, 1);
_touching.store (1);
}
void
@ -175,7 +175,7 @@ Pannable::stop_touch (timepos_t const & when)
ac->alist()->stop_touch (when);
}
}
g_atomic_int_set (&_touching, 0);
_touching.store (0);
}
XMLNode&

View File

@ -321,8 +321,8 @@ Playlist::init (bool hide)
add_property (regions);
_xml_node_name = X_("Playlist");
g_atomic_int_set (&block_notifications, 0);
g_atomic_int_set (&ignore_state_changes, 0);
block_notifications.store (0);
ignore_state_changes.store (0);
pending_contents_change = false;
pending_layering = false;
first_set_state = true;
@ -430,28 +430,28 @@ void
Playlist::freeze_locked ()
{
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 */
void
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);
}
void
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 */
void
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);
}
}

View File

@ -92,8 +92,8 @@ PluginInsert::PluginInsert (Session& s, Temporal::TimeDomain td, std::shared_ptr
, _bypass_port (UINT32_MAX)
, _inverted_bypass_enable (false)
{
g_atomic_int_set (&_stat_reset, 0);
g_atomic_int_set (&_flush, 0);
_stat_reset.store (0);
_flush.store (0);
/* the first is the master */
if (plug) {
@ -748,7 +748,7 @@ PluginInsert::deactivate ()
void
PluginInsert::flush ()
{
g_atomic_int_set (&_flush, 1);
_flush.store (1);
}
void
@ -1272,7 +1272,8 @@ PluginInsert::silence (samplecnt_t nframes, samplepos_t start_sample)
ChanCount maxbuf = ChanCount::max (natural_input_streams (), natural_output_streams());
_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 ();
}
@ -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);
}
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 ();
}
@ -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) {
(*i)->flush ();
}
@ -3371,7 +3374,7 @@ PluginInsert::get_stats (PBD::microseconds_t& min, PBD::microseconds_t& max, dou
void
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)

View File

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

View File

@ -257,7 +257,7 @@ PortManager::PortManager ()
, _audio_input_ports (new AudioInputPorts)
, _midi_input_ports (new MIDIInputPorts)
{
g_atomic_int_set (&_reset_meters, 1);
_reset_meters.store (1);
load_port_info ();
}
@ -1910,7 +1910,7 @@ PortManager::check_for_ambiguous_latency (bool log) const
void
PortManager::reset_input_meters ()
{
g_atomic_int_set (&_reset_meters, 1);
_reset_meters.store (1);
}
PortManager::AudioInputPorts
@ -1934,7 +1934,8 @@ PortManager::run_input_meters (pframes_t n_samples, samplecnt_t rate)
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);

View File

@ -23,6 +23,7 @@
#include <cassert>
#include "pbd/atomic.h"
#include "pbd/debug.h"
#include "pbd/enum_convert.h"
#include "pbd/enumwriter.h"
@ -47,7 +48,7 @@ string PresentationInfo::state_node_name = X_("PresentationInfo");
PBD::Signal1<void,PropertyChange const &> PresentationInfo::Change;
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;
int PresentationInfo::selection_counter= 0;
@ -63,7 +64,7 @@ namespace ARDOUR {
void
PresentationInfo::suspend_change_signal ()
{
g_atomic_int_add (&_change_signal_suspended, 1);
_change_signal_suspended.fetch_add (1);
}
void
@ -71,7 +72,7 @@ PresentationInfo::unsuspend_change_signal ()
{
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 */
@ -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);
_pending_static_changes.add (what_changed);
return;

View File

@ -141,9 +141,9 @@ Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType
{
processor_max_streams.reset();
g_atomic_int_set (&_pending_process_reorder, 0);
g_atomic_int_set (&_pending_listen_change, 0);
g_atomic_int_set (&_pending_signals, 0);
_pending_process_reorder.store (0);
_pending_listen_change.store (0);
_pending_signals.store (0);
}
std::weak_ptr<Route>
@ -1015,7 +1015,7 @@ Route::add_processors (const ProcessorList& others, std::shared_ptr<Processor> b
ProcessorList::iterator loc;
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 */
Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
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
* (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()) {
DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
Glib::Threads::RWLock::WriterLock lm (_processor_lock);
g_atomic_int_set (&_pending_process_reorder, 0);
g_atomic_int_set (&_pending_listen_change, 0);
_pending_process_reorder.store (0);
_pending_listen_change.store (0);
apply_processor_order(_pending_processor_order);
_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 = new_order;
g_atomic_int_set (&_pending_process_reorder, 1);
_pending_process_reorder.store (1);
}
return 0;
@ -4102,11 +4102,11 @@ Route::apply_processor_changes_rt ()
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);
if (pwl.locked()) {
g_atomic_int_set (&_pending_process_reorder, 0);
g_atomic_int_set (&_pending_listen_change, 0);
_pending_process_reorder.store (0);
_pending_listen_change.store (0);
apply_processor_order (_pending_processor_order);
_pending_processor_order.clear ();
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);
if (pwl.locked()) {
g_atomic_int_set (&_pending_listen_change, 0);
_pending_listen_change.store (0);
setup_invisible_processors ();
changed = true;
emissions |= EmitRtProcessorChange;
@ -4142,7 +4142,7 @@ Route::apply_processor_changes_rt ()
void
Route::emit_pending_signals ()
{
int sig = g_atomic_int_and (&_pending_signals, 0);
int sig = _pending_signals.fetch_and (0);
if (sig & EmitMeterChanged) {
_meter->emit_configuration_changed();
meter_change (); /* EMIT SIGNAL */
@ -4309,7 +4309,7 @@ Route::listen_position_changed ()
if (c == _monitor_send->input_streams () && AudioEngine::instance()->running()) {
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;
}

View File

@ -46,7 +46,7 @@ CoreSelection::send_selection_change ()
CoreSelection::CoreSelection (Session& s)
: session (s)
{
g_atomic_int_set (&_selection_order, 0);
_selection_order.store (0);
}
CoreSelection::~CoreSelection ()
@ -248,7 +248,7 @@ CoreSelection::set (StripableList& sl)
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) {
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);
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) {
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);
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()) {
return;

View File

@ -46,6 +46,7 @@
#include <boost/algorithm/string/erase.hpp>
#include "pbd/atomic.h"
#include "pbd/basename.h"
#include "pbd/convert.h"
#include "pbd/error.h"
@ -154,7 +155,7 @@ using namespace Temporal;
bool Session::_disable_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::Signal0<int> Session::AskAboutPendingState;
@ -329,21 +330,21 @@ Session::Session (AudioEngine &eng,
, _active_cue (-1)
, tb_with_filled_slots (0)
{
g_atomic_int_set (&_suspend_save, 0);
g_atomic_int_set (&_playback_load, 0);
g_atomic_int_set (&_capture_load, 0);
g_atomic_int_set (&_post_transport_work, 0);
g_atomic_int_set (&_processing_prohibited, Disabled);
g_atomic_int_set (&_record_status, Disabled);
g_atomic_int_set (&_punch_or_loop, NoConstraint);
g_atomic_int_set (&_current_usecs_per_track, 1000);
g_atomic_int_set (&_have_rec_enabled_track, 0);
g_atomic_int_set (&_have_rec_disabled_track, 1);
g_atomic_int_set (&_latency_recompute_pending, 0);
g_atomic_int_set (&_suspend_timecode_transmission, 0);
g_atomic_int_set (&_update_pretty_names, 0);
g_atomic_int_set (&_seek_counter, 0);
g_atomic_int_set (&_butler_seek_counter, 0);
_suspend_save.store (0);
_playback_load.store (0);
_capture_load.store (0);
_post_transport_work.store (PostTransportWork (0));
_processing_prohibited.store (Disabled);
_record_status.store (Disabled);
_punch_or_loop.store (NoConstraint);
_current_usecs_per_track.store (1000);
_have_rec_enabled_track.store (0);
_have_rec_disabled_track.store (1);
_latency_recompute_pending.store (0);
_suspend_timecode_transmission.store (0);
_update_pretty_names.store (0);
_seek_counter.store (0);
_butler_seek_counter.store (0);
created_with = string_compose ("%1 %2", PROGRAM_NAME, revision);
@ -542,19 +543,19 @@ Session::~Session ()
unsigned int
Session::next_name_id ()
{
return g_atomic_int_add (&_name_id_counter, 1);
return _name_id_counter.fetch_add (1);
}
unsigned int
Session::name_id_counter ()
{
return g_atomic_int_get (&_name_id_counter);
return _name_id_counter.load ();
}
void
Session::init_name_id_counter (guint n)
{
g_atomic_int_set (&_name_id_counter, n);
_name_id_counter.store (n);
}
int
@ -874,7 +875,7 @@ Session::destroy ()
void
Session::block_processing()
{
g_atomic_int_set (&_processing_prohibited, 1);
_processing_prohibited.store (1);
/* processing_blocked() is only checked at the beginning
* of the next cycle. So wait until any ongoing
@ -1477,7 +1478,7 @@ Session::punch_active () const
bool
Session::punch_is_possible () const
{
return g_atomic_int_get (&_punch_or_loop) != OnlyLoop;
return _punch_or_loop.load () != OnlyLoop;
}
bool
@ -1489,13 +1490,13 @@ Session::loop_is_possible () const
}
}
#endif
return g_atomic_int_get(&_punch_or_loop) != OnlyPunch;
return _punch_or_loop.load () != OnlyPunch;
}
void
Session::reset_punch_loop_constraint ()
{
if (g_atomic_int_get (&_punch_or_loop) == NoConstraint) {
if (_punch_or_loop.load () == NoConstraint) {
return;
}
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)) {
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) {
PunchLoopConstraintChange (); /* EMIT SIGNAL */
}
@ -1523,7 +1525,8 @@ Session::maybe_allow_only_punch () {
if (!punch_active ()) {
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) {
PunchLoopConstraintChange (); /* EMIT SIGNAL */
}
@ -1927,13 +1930,13 @@ Session::enable_record ()
}
while (1) {
RecordState rs = (RecordState) g_atomic_int_get (&_record_status);
RecordState rs = (RecordState) _record_status.load ();
if (rs == Recording) {
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;
send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordStrobe));
@ -1966,7 +1969,7 @@ Session::disable_record (bool rt_context, bool force)
{
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) {
g_atomic_int_set (&_record_status, Disabled);
@ -1988,7 +1991,9 @@ Session::disable_record (bool rt_context, bool force)
void
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()) {
set_track_monitor_input_status (false);
@ -6290,13 +6295,13 @@ Session::add_automation_list(AutomationList *al)
bool
Session::have_rec_enabled_track () const
{
return g_atomic_int_get (&_have_rec_enabled_track) == 1;
return _have_rec_enabled_track.load () == 1;
}
bool
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 */
@ -6315,11 +6320,11 @@ Session::update_route_record_state ()
++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);
if (g_atomic_int_get (&_have_rec_enabled_track) != old) {
if (_have_rec_enabled_track.load () != old) {
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);
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 ) {
RecordArmStateChanged ();
@ -7291,7 +7296,7 @@ Session::auto_connect_thread_wakeup ()
void
Session::queue_latency_recompute ()
{
g_atomic_int_inc (&_latency_recompute_pending);
_latency_recompute_pending.fetch_add (1);
auto_connect_thread_wakeup ();
}
@ -7394,7 +7399,7 @@ Session::auto_connect (const AutoConnectRequest& ar)
void
Session::auto_connect_thread_start ()
{
if (g_atomic_int_get (&_ac_thread_active)) {
if (_ac_thread_active.load ()) {
return;
}
@ -7404,16 +7409,16 @@ Session::auto_connect_thread_start ()
}
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)) {
g_atomic_int_set (&_ac_thread_active, 0);
_ac_thread_active.store (0);
}
}
void
Session::auto_connect_thread_terminate ()
{
if (!g_atomic_int_get (&_ac_thread_active)) {
if (!_ac_thread_active.load ()) {
return;
}
@ -7429,7 +7434,7 @@ Session::auto_connect_thread_terminate ()
*/
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_mutex_unlock (&_auto_connect_mutex);
@ -7455,7 +7460,7 @@ Session::auto_connect_thread_run ()
pthread_mutex_lock (&_auto_connect_mutex);
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 ()) {
/* Why would we need the process lock?
@ -7485,20 +7490,20 @@ Session::auto_connect_thread_run ()
* calls DiskWriter::set_capture_offset () which
* 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);
if (g_atomic_int_get (&_latency_recompute_pending)) {
if (_latency_recompute_pending.load ()) {
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 ());
if (ap->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) {
@ -7688,13 +7693,13 @@ Session::ProcessorChangeBlocker::ProcessorChangeBlocker (Session* s, bool rc)
: _session (s)
, _reconfigure_on_delete (rc)
{
g_atomic_int_inc (&s->_ignore_route_processor_changes);
PBD::atomic_inc (s->_ignore_route_processor_changes);
}
Session::ProcessorChangeBlocker::~ProcessorChangeBlocker ()
{
if (g_atomic_int_dec_and_test (&_session->_ignore_route_processor_changes)) {
gint type = g_atomic_int_and (&_session->_ignored_a_processor_change, 0);
if (PBD::atomic_dec_and_test (_session->_ignore_route_processor_changes)) {
RouteProcessorChange::Type type = (RouteProcessorChange::Type) _session->_ignored_a_processor_change.fetch_and (0);
if (_reconfigure_on_delete) {
if (type & RouteProcessorChange::GeneralChange) {
_session->route_processors_changed (RouteProcessorChange ());

View File

@ -131,7 +131,7 @@ Session::setup_bundles ()
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 ();
}

View File

@ -122,11 +122,11 @@ Session::overwrite_some_buffers (std::shared_ptr<Route> r, OverwriteReason why)
uint32_t
Session::playback_load ()
{
return (uint32_t) g_atomic_int_get (&_playback_load);
return (uint32_t) _playback_load.load ();
}
uint32_t
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).
*/
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));
@ -1541,7 +1541,7 @@ Session::plan_master_strategy (pframes_t nframes, double master_speed, samplepos
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));

View File

@ -181,7 +181,7 @@ Session::pre_engine_init (string fullpath)
*/
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 (&_playback_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;
}
if (g_atomic_int_get(&_suspend_save)) {
if (_suspend_save.load ()) {
/* 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));
if (pending) {

View File

@ -34,6 +34,7 @@
#include <boost/algorithm/string/erase.hpp>
#include "pbd/atomic.h"
#include "pbd/error.h"
#include "pbd/enumwriter.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;
// Bump seek counter so that any in-process locate in the butler
// thread(s?) can restart.
g_atomic_int_inc (&_seek_counter);
_seek_counter.fetch_add (1);
_last_roll_or_reversal_location = target_sample;
if (!for_loop_end) {
_remaining_latency_preroll = worst_latency_preroll_buffer_size_ceil ();
@ -761,9 +762,9 @@ Session::add_post_transport_work (PostTransportWork ptw)
int tries = 0;
while (tries < 8) {
oldval = (PostTransportWork) g_atomic_int_get (&_post_transport_work);
oldval = _post_transport_work.load ();
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 */
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 rtlocates = g_atomic_int_get (&_seek_counter);
const int butler = _butler_seek_counter.load ();
const int rtlocates = _seek_counter.load ();
const bool will_locate = (butler != rtlocates);
if (ptw & PostTransportStop) {
non_realtime_stop (ptw & PostTransportAbort, on_entry, finished, will_locate);
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;
}
}
@ -1184,7 +1185,7 @@ Session::butler_transport_work (bool have_process_lock)
if (ptw & PostTransportOverWrite) {
non_realtime_overwrite (on_entry, finished, (ptw & PostTransportLoopChanged));
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;
}
}
@ -1193,7 +1194,7 @@ Session::butler_transport_work (bool have_process_lock)
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()));
}
@ -1261,13 +1262,13 @@ Session::non_realtime_locate ()
std::shared_ptr<RouteList> rl = routes.reader();
restart:
sc = g_atomic_int_get (&_seek_counter);
sc = _seek_counter.load ();
tf = _transport_sample;
start = get_microseconds ();
for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i, ++nt) {
(*i)->non_realtime_locate (tf);
if (sc != g_atomic_int_get (&_seek_counter)) {
if (sc != _seek_counter.load ()) {
goto restart;
}
}
@ -1277,7 +1278,7 @@ Session::non_realtime_locate ()
#ifndef NDEBUG
std::cerr << "locate to " << tf << " took " << (end - start) << " usecs for " << nt << " tracks = " << usecs_per_track << " per track\n";
#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);
}
}
@ -1878,8 +1879,8 @@ Session::reset_xrun_count ()
void
Session::route_processors_changed (RouteProcessorChange c)
{
if (g_atomic_int_get (&_ignore_route_processor_changes) > 0) {
g_atomic_int_or (&_ignored_a_processor_change, (int)c.type);
if (_ignore_route_processor_changes.load () > 0) {
(void) _ignored_a_processor_change.fetch_or (c.type);
return;
}
@ -1948,7 +1949,7 @@ Session::request_resume_timecode_transmission ()
bool
Session::timecode_transmission_suspended () const
{
return g_atomic_int_get (&_suspend_timecode_transmission) == 1;
return _suspend_timecode_transmission.load () == 1;
}
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)
, _level (0)
{
g_atomic_int_set (&_use_count, 0);
_use_count.store (0);
_analysed = false;
_timestamp = 0;
@ -82,7 +82,7 @@ Source::Source (Session& s, const XMLNode& node)
, _have_natural_position (false)
, _level (0)
{
g_atomic_int_set (&_use_count, 0);
_use_count.store (0);
_analysed = false;
_timestamp = 0;
@ -440,21 +440,21 @@ Source::set_allow_remove_if_empty (bool yn)
void
Source::inc_use_count ()
{
g_atomic_int_inc (&_use_count);
_use_count.fetch_add (1);
}
void
Source::dec_use_count ()
{
#ifndef NDEBUG
gint oldval = g_atomic_int_add (&_use_count, -1);
int oldval = _use_count.fetch_sub (1);
if (oldval <= 0) {
cerr << "Bad use dec for " << name() << endl;
abort ();
}
assert (oldval > 0);
#else
g_atomic_int_add (&_use_count, -1);
_use_count.fetch_sub (1);
#endif
try {

View File

@ -26,6 +26,8 @@
#include "ardour/vst3_host.h"
#include "pbd/atomic.h"
#ifndef VST3_SCANNER_APP
#include "ardour/debug.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 ()
{
g_atomic_int_set (&_cnt, 1);
_cnt.store (1);
}
uint32
RefObject::addRef ()
{
g_atomic_int_inc (&_cnt);
return g_atomic_int_get (&_cnt);
_cnt.fetch_add (1);
return _cnt.load ();
}
uint32
RefObject::release ()
{
if (g_atomic_int_dec_and_test (&_cnt)) {
if (PBD::atomic_dec_and_test (_cnt)) {
delete this;
return 0;
}
return g_atomic_int_get (&_cnt);
return _cnt.load ();
}
/* ****************************************************************************/

View File

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

View File

@ -68,7 +68,7 @@ class TmpFileRt
% 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
("Could not write data to ringbuffer/output file (%1%)")
% SndfileHandle::strError()));

View File

@ -1020,7 +1020,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
}
_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,
&_main_thread, pthread_process, this)) {
@ -2084,7 +2084,8 @@ AlsaAudioBackend::main_process_thread ()
bool connections_changed = false;
bool ports_changed = false;
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;
}
if (!_port_connection_queue.empty ()) {

View File

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

View File

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

View File

@ -639,7 +639,7 @@ CoreAudioBackend::_start (bool for_latency_measurement)
_preinit = true;
_run = true;
g_atomic_int_set (&_port_change_flag, 0);
_port_change_flag.store (0);
if (_midi_driver_option == _("CoreMidi")) {
_midiio->set_enabled(true);
@ -697,7 +697,7 @@ CoreAudioBackend::_start (bool for_latency_measurement)
engine.reconnect_ports ();
// force an initial registration_callback() & latency re-compute
g_atomic_int_set (&_port_change_flag, 1);
_port_change_flag.store (1);
pre_process ();
_dsp_load_calc.reset ();
@ -1026,7 +1026,7 @@ CoreAudioBackend::coremidi_rediscover()
#ifndef NDEBUG
printf("unregister MIDI Output: %s\n", (*it)->name().c_str());
#endif
g_atomic_int_set (&_port_change_flag, 1);
_port_change_flag.store (1);
unregister_port((*it));
it = _system_midi_out.erase(it);
}
@ -1046,7 +1046,7 @@ CoreAudioBackend::coremidi_rediscover()
#ifndef NDEBUG
printf("unregister MIDI Input: %s\n", (*it)->name().c_str());
#endif
g_atomic_int_set (&_port_change_flag, 1);
_port_change_flag.store (1);
unregister_port((*it));
it = _system_midi_in.erase(it);
}
@ -1072,7 +1072,7 @@ CoreAudioBackend::coremidi_rediscover()
BackendPortPtr pp = std::dynamic_pointer_cast<BackendPort>(p);
pp->set_hw_port_name(_midiio->port_name(i, true));
_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) {
@ -1095,7 +1095,7 @@ CoreAudioBackend::coremidi_rediscover()
BackendPortPtr pp = std::dynamic_pointer_cast<BackendPort>(p);
pp->set_hw_port_name(_midiio->port_name(i, false));
_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 ();
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)) {
PBD::error << _("DummyAudioBackend: cannot start.") << endmsg;
@ -1008,7 +1008,8 @@ DummyAudioBackend::main_process_thread ()
bool connections_changed = false;
bool ports_changed = false;
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;
}
if (!_port_connection_queue.empty ()) {

View File

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

View File

@ -618,7 +618,7 @@ PulseAudioBackend::_start (bool /*for_latency_measurement*/)
engine.reconnect_ports ();
_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,
&_main_thread, pthread_process, this)) {
@ -1091,7 +1091,8 @@ PulseAudioBackend::main_process_thread ()
bool connections_changed = false;
bool ports_changed = false;
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;
}
if (!_port_connection_queue.empty ()) {

View File

@ -19,26 +19,27 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <atomic>
#include <glib.h>
#include "pbd/g_atomic_compat.h"
#include "temporal/beats.h"
#include "evoral/Event.h"
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_counter()
{
return g_atomic_int_get (&_event_id_counter);
return _event_id_counter.load ();
}
void
init_event_id_counter(event_id_t n)
{
g_atomic_int_set (&_event_id_counter, n);
_event_id_counter.store (n);
}
event_id_t
@ -53,7 +54,7 @@ next_event_id ()
*
* 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

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

View File

@ -20,6 +20,7 @@
#ifndef __pbd_event_loop_h__
#define __pbd_event_loop_h__
#include <atomic>
#include <string>
#include <vector>
#include <map>
@ -58,19 +59,19 @@ public:
struct InvalidationRecord {
std::list<BaseRequestObject*> requests;
PBD::EventLoop* event_loop;
gint _valid;
gint _ref;
std::atomic<int> _valid;
std::atomic<int> _ref;
const char* file;
int line;
InvalidationRecord() : event_loop (0), _valid (1), _ref (0) {}
void invalidate () { g_atomic_int_set (&_valid, 0); }
bool valid () { return g_atomic_int_get (&_valid) == 1; }
void invalidate () { _valid.store (0); }
bool valid () { return _valid.load () == 1; }
void ref () { g_atomic_int_inc (&_ref); }
void unref () { (void) g_atomic_int_dec_and_test (&_ref); }
bool in_use () { return g_atomic_int_get (&_ref) > 0; }
int use_count () { return g_atomic_int_get (&_ref); }
void ref () { _ref.fetch_add (1); }
void unref () { (void) _ref.fetch_sub (1); }
bool in_use () { return _ref.load () > 0; }
int use_count () { return _ref.load (); }
};
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>
#else
# include <glib.h>
# include "pbd/g_atomic_compat.h"
# define MPMC_QUEUE_TYPE GATOMIC_QUAL guint
# define MPMC_QUEUE_TYPE std::atomic<unsigned int>
#endif
namespace PBD {
@ -99,8 +98,8 @@ public:
for (size_t i = 0; i <= _buffer_mask; ++i) {
g_atomic_int_set (&_buffer[i]._sequence, i);
}
g_atomic_int_set (&_enqueue_pos, 0);
g_atomic_int_set (&_dequeue_pos, 0);
_enqueue_pos.store (0);
_dequeue_pos.store (0);
#endif
}
@ -111,7 +110,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC
size_t pos = _enqueue_pos.load (std::memory_order_relaxed);
#else
guint pos = g_atomic_int_get (&_enqueue_pos);
guint pos = _enqueue_pos.load ();
#endif
for (;;) {
cell = &_buffer[pos & _buffer_mask];
@ -136,7 +135,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC
pos = _enqueue_pos.load (std::memory_order_relaxed);
#else
pos = g_atomic_int_get (&_enqueue_pos);
pos = _enqueue_pos.load ();
#endif
}
}
@ -158,7 +157,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC
size_t pos = _dequeue_pos.load (std::memory_order_relaxed);
#else
guint pos = g_atomic_int_get (&_dequeue_pos);
guint pos = _dequeue_pos.load ();
#endif
for (;;) {
cell = &_buffer[pos & _buffer_mask];
@ -183,7 +182,7 @@ public:
#ifdef MPMC_USE_STD_ATOMIC
pos = _dequeue_pos.load (std::memory_order_relaxed);
#else
pos = g_atomic_int_get (&_dequeue_pos);
pos = _dequeue_pos.load ();
#endif
}
}

View File

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

View File

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

View File

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

View File

@ -23,6 +23,7 @@
#ifndef __pbd_stateful_h__
#define __pbd_stateful_h__
#include <atomic>
#include <string>
#include <list>
#include <cassert>
@ -32,7 +33,6 @@
#include "pbd/xml++.h"
#include "pbd/property_basics.h"
#include "pbd/signals.h"
#include "pbd/g_atomic_compat.h"
class XMLNode;
@ -105,7 +105,7 @@ class LIBPBD_API Stateful {
virtual void suspend_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:
@ -142,7 +142,7 @@ class LIBPBD_API Stateful {
static Glib::Threads::Private<bool> _regenerate_xml_or_string_ids;
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);
};

View File

@ -87,7 +87,7 @@ Pool::alloc ()
if (free_list.read (&ptr, 1) < 1) {
PBD::stacktrace (std::cerr, 20);
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 ();
for (size_t i = 0; i < free_list.bufsize (); ++i) {
_dump (i, _block[i]);

View File

@ -24,6 +24,7 @@
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
#include "pbd/atomic.h"
#include "pbd/debug.h"
#include "pbd/stateful.h"
#include "pbd/types_convert.h"
@ -48,7 +49,7 @@ Stateful::Stateful ()
, _instant_xml (nullptr)
, _properties (new OwnedPropertyList)
{
g_atomic_int_set (&_stateful_frozen, 0);
_stateful_frozen.store (0);
}
Stateful::~Stateful ()
@ -298,7 +299,7 @@ Stateful::send_change (const PropertyChange& what_changed)
void
Stateful::suspend_property_changes ()
{
g_atomic_int_add (&_stateful_frozen, 1);
_stateful_frozen.fetch_add (1);
}
void
@ -309,7 +310,7 @@ Stateful::resume_property_changes ()
{
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;
}

View File

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

View File

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