Add stdatomic.h compatibility for MSVC
This commit is contained in:
parent
c9380186ba
commit
30b579feb4
2 changed files with 69 additions and 4 deletions
64
lv2/atomic_compat.h
Normal file
64
lv2/atomic_compat.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
SPDX-License-Identifier: ISC
|
||||
|
||||
Sfizz LV2 plugin
|
||||
|
||||
Copyright 2019-2020, Paul Ferrand <paul@ferrand.cc>
|
||||
|
||||
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 <d@drobilla.net>
|
||||
Copyright 2011 Gabriel M. Beddingfield <gabriel@teuton.org>
|
||||
Copyright 2011 James Morris <jwm.art.net@gmail.com>
|
||||
|
||||
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 <atomic>
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
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 <stdatomic.h>
|
||||
|
||||
#endif
|
||||
|
|
@ -53,9 +53,10 @@
|
|||
#include <sfizz.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdatomic.h>
|
||||
#include <string.h>
|
||||
|
||||
#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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue