13
0

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

This commit is contained in:
Paul Davis 2023-02-17 00:31:31 -07:00
parent 4ba4cd69ff
commit c304edd253
5 changed files with 19 additions and 15 deletions

View File

@ -64,7 +64,7 @@ MidiTracer::MidiTracer ()
, collect_button (_("Enabled"))
, delta_time_button (_("Delta times"))
{
g_atomic_int_set (&_update_queued, 0);
_update_queued.store (0);
std::string portname (string_compose(X_("x-MIDI-tracer-%1"), ++window_count));
std::shared_ptr<ARDOUR::Port> port = AudioEngine::instance()->register_input_port (DataType::MIDI, portname, false, PortFlags (IsInput | Hidden | IsTerminal));
@ -511,7 +511,8 @@ MidiTracer::tracer (Parser&, MIDI::byte* msg, size_t len, samplecnt_t now)
fifo.write (&buf, 1);
if (g_atomic_int_compare_and_exchange (&_update_queued, 0, 1)) {
int canderef (0);
if (_update_queued.compare_exchange_strong (canderef, 1)) {
gui_context()->call_slot (invalidator (*this), boost::bind (&MidiTracer::update, this));
}
}
@ -520,7 +521,7 @@ void
MidiTracer::update ()
{
bool updated = false;
g_atomic_int_set (&_update_queued, 0);
_update_queued.store (0);
RefPtr<TextBuffer> buf (text.get_buffer());

View File

@ -22,6 +22,8 @@
#ifndef __ardour_gtk_midi_tracer_h__
#define __ardour_gtk_midi_tracer_h__
#include <atomic>
#include <gtkmm/textview.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/togglebutton.h>
@ -35,7 +37,6 @@
#include "pbd/signals.h"
#include "pbd/ringbuffer.h"
#include "pbd/pool.h"
#include "pbd/g_atomic_compat.h"
#include "midi++/types.h"
#include "ardour_window.h"
@ -75,7 +76,7 @@ private:
* equal to 0 when an update is not queued. May temporarily be negative if a
* update is handled before it was noted that it had just been queued.
*/
GATOMIC_QUAL gint _update_queued;
std::atomic<int> _update_queued;
PBD::RingBuffer<char *> fifo;
PBD::Pool buffer_pool;

View File

@ -36,7 +36,7 @@ ARDOUR::DataType PublicEditor::pbdid_dragged_dt = ARDOUR::DataType::NIL;
PublicEditor::PublicEditor (Gtk::Widget& content)
: Tabbable (content, _("Editor"), X_("editor"))
{
g_atomic_int_set (&_suspend_route_redisplay_counter, 0);
_suspend_route_redisplay_counter.store (0);
}
PublicEditor::~PublicEditor()

View File

@ -32,6 +32,7 @@
#include "gtk2ardour-config.h"
#endif
#include <atomic>
#include <map>
#include <string>
@ -44,7 +45,6 @@
#include <sigc++/signal.h>
#include "pbd/statefuldestructible.h"
#include "pbd/g_atomic_compat.h"
#include "temporal/beats.h"
@ -585,18 +585,18 @@ protected:
virtual void resume_route_redisplay () = 0;
virtual void _commit_tempo_map_edit (Temporal::TempoMap::WritableSharedPtr&, bool with_update) = 0;
GATOMIC_QUAL gint _suspend_route_redisplay_counter;
std::atomic<int> _suspend_route_redisplay_counter;
};
class DisplaySuspender {
public:
DisplaySuspender() {
if (g_atomic_int_add (&PublicEditor::instance()._suspend_route_redisplay_counter, 1) == 0) {
if (PublicEditor::instance()._suspend_route_redisplay_counter.fetch_add (1) == 0) {
PublicEditor::instance().suspend_route_redisplay ();
}
}
~DisplaySuspender () {
if (g_atomic_int_dec_and_test (&PublicEditor::instance()._suspend_route_redisplay_counter)) {
if (PBD::atomic_dec_and_test (PublicEditor::instance()._suspend_route_redisplay_counter)) {
PublicEditor::instance().resume_route_redisplay ();
}
}

View File

@ -17,12 +17,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <atomic>
#include "timers.h"
#include "pbd/atomic.h"
#include "pbd/timer.h"
#include "pbd/debug.h"
#include "pbd/compose.h"
#include "pbd/g_atomic_compat.h"
#include "debug.h"
@ -89,7 +91,7 @@ public:
, super_rapid(40)
, fps(40)
{
g_atomic_int_set (&_suspend_counter, 0);
_suspend_counter.store (0);
#ifndef NDEBUG
second.connect (sigc::mem_fun (*this, &UITimers::on_second_timer));
#endif
@ -101,7 +103,7 @@ public:
StandardTimer super_rapid;
StandardTimer fps;
GATOMIC_QUAL gint _suspend_counter;
std::atomic<int> _suspend_counter;
#ifndef NDEBUG
std::vector<int64_t> rapid_eps_count;
@ -213,7 +215,7 @@ fps_connect(const sigc::slot<void>& slot)
TimerSuspender::TimerSuspender ()
{
if (g_atomic_int_add (&get_timers()._suspend_counter, 1) == 0) {
if (get_timers()._suspend_counter.fetch_add (1) == 0) {
get_timers().rapid.suspend();
get_timers().super_rapid.suspend();
get_timers().fps.suspend();
@ -222,7 +224,7 @@ TimerSuspender::TimerSuspender ()
TimerSuspender::~TimerSuspender ()
{
if (g_atomic_int_dec_and_test (&get_timers()._suspend_counter)) {
if (PBD::atomic_dec_and_test (get_timers()._suspend_counter)) {
get_timers().rapid.resume();
get_timers().super_rapid.resume();
get_timers().fps.resume();