From 30b579feb4ec174a8a6b842c90ea6156a79aa4c7 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 25 Feb 2020 15:23:53 +0100 Subject: [PATCH] Add stdatomic.h compatibility for MSVC --- lv2/atomic_compat.h | 64 +++++++++++++++++++++++++++++++++++++++++++++ lv2/sfizz.c | 9 ++++--- 2 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 lv2/atomic_compat.h diff --git a/lv2/atomic_compat.h b/lv2/atomic_compat.h new file mode 100644 index 00000000..0778356b --- /dev/null +++ b/lv2/atomic_compat.h @@ -0,0 +1,64 @@ +/* + SPDX-License-Identifier: ISC + + Sfizz LV2 plugin + + Copyright 2019-2020, Paul Ferrand + + This file was based on skeleton and example code from the LV2 plugin + distribution available at http://lv2plug.in/ + + The LV2 sample plugins have the following copyright and notice, which are + extended to the current work: + Copyright 2011-2016 David Robillard + Copyright 2011 Gabriel M. Beddingfield + Copyright 2011 James Morris + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + Compiling this plugin statically against libsndfile implies distributing it + under the terms of the LGPL v3 license. See the LICENSE.md file for more + information. If you did not receive a LICENSE.md file, inform the current + maintainer. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#if defined(__cplusplus) + +#include + +#elif defined(_MSC_VER) + +#include + +typedef volatile int atomic_int; + +inline int atomic_exchange(atomic_int *d, int x) +{ + return _InterlockedExchange((volatile long *)d, (long)x); +} + +inline void atomic_store(atomic_int *d, int x) +{ + _InterlockedExchange((volatile long *)d, (long)x); +} + +inline int atomic_load(const atomic_int *d) +{ + return _InterlockedOr((volatile long *)d, 0); +} + +#else + +#include + +#endif diff --git a/lv2/sfizz.c b/lv2/sfizz.c index 279295a7..0b2f6402 100644 --- a/lv2/sfizz.c +++ b/lv2/sfizz.c @@ -53,9 +53,10 @@ #include #include #include -#include #include +#include "atomic_compat.h" + #define DEFAULT_SFZ_FILE "/home/paul/Documents/AVL_Percussions/AVL_Drumkits_Percussion-1.0-Alt.sfz" #define SFIZZ_URI "http://sfztools.github.io/sfizz" #define SFIZZ_PREFIX SFIZZ_URI "#" @@ -149,7 +150,7 @@ typedef struct int max_block_size; int sample_counter; float sample_rate; - _Atomic(bool) must_update_midnam; + atomic_int must_update_midnam; } sfizz_plugin_t; enum @@ -693,7 +694,7 @@ run(LV2_Handle instance, uint32_t sample_count) // Render the block sfizz_render_block(self->synth, self->output_buffers, 2, (int)sample_count); - if (self->midnam && atomic_exchange(&self->must_update_midnam, false)) + if (self->midnam && atomic_exchange(&self->must_update_midnam, 0)) { self->midnam->update(self->midnam->handle); } @@ -784,7 +785,7 @@ sfizz_lv2_update_file_info(sfizz_plugin_t* self, const char* file_path) lv2_log_note(&self->logger, "[sfizz] Number of groups: %d\n", sfizz_get_num_groups(self->synth)); lv2_log_note(&self->logger, "[sfizz] Number of regions: %d\n", sfizz_get_num_regions(self->synth)); - atomic_store(&self->must_update_midnam, true); + atomic_store(&self->must_update_midnam, 1); } static LV2_State_Status