Provide the spin mutex as internal library
This commit is contained in:
parent
e178ae25e6
commit
c110acc966
9 changed files with 79 additions and 9 deletions
|
|
@ -117,7 +117,7 @@ SFIZZ_SOURCES = \
|
||||||
src/sfizz/Synth.cpp \
|
src/sfizz/Synth.cpp \
|
||||||
src/sfizz/SynthMessaging.cpp \
|
src/sfizz/SynthMessaging.cpp \
|
||||||
src/sfizz/Tuning.cpp \
|
src/sfizz/Tuning.cpp \
|
||||||
src/sfizz/utility/SpinMutex.cpp \
|
src/sfizz/utility/spin_mutex/SpinMutex.cpp \
|
||||||
src/sfizz/Voice.cpp \
|
src/sfizz/Voice.cpp \
|
||||||
src/sfizz/VoiceManager.cpp \
|
src/sfizz/VoiceManager.cpp \
|
||||||
src/sfizz/VoiceStealing.cpp \
|
src/sfizz/VoiceStealing.cpp \
|
||||||
|
|
@ -126,7 +126,9 @@ SFIZZ_SOURCES = \
|
||||||
|
|
||||||
### Other internal
|
### Other internal
|
||||||
|
|
||||||
SFIZZ_C_FLAGS += -I$(SFIZZ_DIR)/src/sfizz
|
SFIZZ_C_FLAGS += \
|
||||||
|
-I$(SFIZZ_DIR)/src/sfizz \
|
||||||
|
-I$(SFIZZ_DIR)/src/sfizz/utility/spin_mutex
|
||||||
|
|
||||||
# Pkg-config dependency
|
# Pkg-config dependency
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ set(SFIZZ_HEADERS
|
||||||
sfizz/Curve.h
|
sfizz/Curve.h
|
||||||
sfizz/Debug.h
|
sfizz/Debug.h
|
||||||
sfizz/utility/NumericId.h
|
sfizz/utility/NumericId.h
|
||||||
sfizz/utility/SpinMutex.h
|
|
||||||
sfizz/utility/XmlHelpers.h
|
sfizz/utility/XmlHelpers.h
|
||||||
sfizz/modulations/ModId.h
|
sfizz/modulations/ModId.h
|
||||||
sfizz/modulations/ModKey.h
|
sfizz/modulations/ModKey.h
|
||||||
|
|
@ -163,7 +162,6 @@ set(SFIZZ_SOURCES
|
||||||
sfizz/modulations/sources/FlexEnvelope.cpp
|
sfizz/modulations/sources/FlexEnvelope.cpp
|
||||||
sfizz/modulations/sources/ADSREnvelope.cpp
|
sfizz/modulations/sources/ADSREnvelope.cpp
|
||||||
sfizz/modulations/sources/LFO.cpp
|
sfizz/modulations/sources/LFO.cpp
|
||||||
sfizz/utility/SpinMutex.cpp
|
|
||||||
sfizz/effects/Nothing.cpp
|
sfizz/effects/Nothing.cpp
|
||||||
sfizz/effects/Filter.cpp
|
sfizz/effects/Filter.cpp
|
||||||
sfizz/effects/Eq.cpp
|
sfizz/effects/Eq.cpp
|
||||||
|
|
@ -239,13 +237,23 @@ target_sources(sfizz_messaging PRIVATE
|
||||||
target_include_directories(sfizz_messaging PUBLIC ".")
|
target_include_directories(sfizz_messaging PUBLIC ".")
|
||||||
target_link_libraries(sfizz_messaging PUBLIC absl::strings)
|
target_link_libraries(sfizz_messaging PUBLIC absl::strings)
|
||||||
|
|
||||||
|
# Sfizz spinlock mutex
|
||||||
|
add_library(sfizz_spin_mutex STATIC
|
||||||
|
sfizz/utility/spin_mutex/spin_mutex.h
|
||||||
|
sfizz/utility/spin_mutex/spin_mutex.cpp
|
||||||
|
sfizz/utility/spin_mutex/SpinMutex.h
|
||||||
|
sfizz/utility/spin_mutex/SpinMutex.cpp)
|
||||||
|
target_include_directories(sfizz_spin_mutex PUBLIC sfizz/utility/spin_mutex)
|
||||||
|
target_link_libraries(sfizz_spin_mutex PRIVATE sfizz::atomic_queue)
|
||||||
|
add_library(sfizz::spin_mutex ALIAS sfizz_spin_mutex)
|
||||||
|
|
||||||
# Sfizz internals (use this for testing)
|
# Sfizz internals (use this for testing)
|
||||||
add_library(sfizz_internal STATIC)
|
add_library(sfizz_internal STATIC)
|
||||||
add_library(sfizz::internal ALIAS sfizz_internal)
|
add_library(sfizz::internal ALIAS sfizz_internal)
|
||||||
target_sources(sfizz_internal PRIVATE ${SFIZZ_HEADERS} ${SFIZZ_SOURCES} ${FAUST_FILES})
|
target_sources(sfizz_internal PRIVATE ${SFIZZ_HEADERS} ${SFIZZ_SOURCES} ${FAUST_FILES})
|
||||||
target_include_directories(sfizz_internal PUBLIC "." "sfizz")
|
target_include_directories(sfizz_internal PUBLIC "." "sfizz")
|
||||||
target_link_libraries(sfizz_internal
|
target_link_libraries(sfizz_internal
|
||||||
PUBLIC absl::strings absl::span sfizz::filesystem sfizz::atomic_queue
|
PUBLIC absl::strings absl::span sfizz::filesystem sfizz::atomic_queue sfizz::spin_mutex
|
||||||
PRIVATE sfizz::parser sfizz::messaging absl::flat_hash_map Threads::Threads st_audiofile sfizz::pugixml sfizz::spline sfizz::tunings sfizz::hiir sfizz::kissfft sfizz::cephes sfizz::cpuid sfizz::threadpool sfizz::jsl sfizz::atomic)
|
PRIVATE sfizz::parser sfizz::messaging absl::flat_hash_map Threads::Threads st_audiofile sfizz::pugixml sfizz::spline sfizz::tunings sfizz::hiir sfizz::kissfft sfizz::cephes sfizz::cpuid sfizz::threadpool sfizz::jsl sfizz::atomic)
|
||||||
if(SFIZZ_USE_SNDFILE)
|
if(SFIZZ_USE_SNDFILE)
|
||||||
target_compile_definitions(sfizz_internal PUBLIC "SFIZZ_USE_SNDFILE=1")
|
target_compile_definitions(sfizz_internal PUBLIC "SFIZZ_USE_SNDFILE=1")
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
#include "FileId.h"
|
#include "FileId.h"
|
||||||
#include "FileMetadata.h"
|
#include "FileMetadata.h"
|
||||||
#include "SIMDHelpers.h"
|
#include "SIMDHelpers.h"
|
||||||
#include "utility/SpinMutex.h"
|
#include <SpinMutex.h>
|
||||||
#include "ghc/fs_std.hpp"
|
#include "ghc/fs_std.hpp"
|
||||||
#include <absl/container/flat_hash_map.h>
|
#include <absl/container/flat_hash_map.h>
|
||||||
#include <absl/types/optional.h>
|
#include <absl/types/optional.h>
|
||||||
|
|
@ -43,7 +43,6 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include "utility/SpinMutex.h"
|
|
||||||
class ThreadPool;
|
class ThreadPool;
|
||||||
|
|
||||||
namespace sfz {
|
namespace sfz {
|
||||||
|
|
|
||||||
37
src/sfizz/utility/spin_mutex/spin_mutex.cpp
Normal file
37
src/sfizz/utility/spin_mutex/spin_mutex.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||||
|
// license. You should have receive a LICENSE.md file along with the code.
|
||||||
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
|
#include "spin_mutex.h"
|
||||||
|
#include "SpinMutex.h"
|
||||||
|
|
||||||
|
struct spin_mutex_ {
|
||||||
|
SpinMutex mtx;
|
||||||
|
};
|
||||||
|
|
||||||
|
spin_mutex_t* spin_mutex_create()
|
||||||
|
{
|
||||||
|
return new spin_mutex_t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spin_mutex_destroy(spin_mutex_t* mtx)
|
||||||
|
{
|
||||||
|
delete mtx;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spin_mutex_lock(spin_mutex_t* mtx)
|
||||||
|
{
|
||||||
|
mtx->mtx.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void spin_mutex_unlock(spin_mutex_t* mtx)
|
||||||
|
{
|
||||||
|
mtx->mtx.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool spin_mutex_trylock(spin_mutex_t* mtx)
|
||||||
|
{
|
||||||
|
return mtx->mtx.try_lock();
|
||||||
|
}
|
||||||
24
src/sfizz/utility/spin_mutex/spin_mutex.h
Normal file
24
src/sfizz/utility/spin_mutex/spin_mutex.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||||
|
// license. You should have receive a LICENSE.md file along with the code.
|
||||||
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct spin_mutex_ spin_mutex_t;
|
||||||
|
|
||||||
|
spin_mutex_t* spin_mutex_create();
|
||||||
|
void spin_mutex_destroy(spin_mutex_t* mtx);
|
||||||
|
void spin_mutex_lock(spin_mutex_t* mtx);
|
||||||
|
void spin_mutex_unlock(spin_mutex_t* mtx);
|
||||||
|
bool spin_mutex_trylock(spin_mutex_t* mtx);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
@ -46,7 +46,7 @@ set(SFIZZ_TEST_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(sfizz_tests ${SFIZZ_TEST_SOURCES})
|
add_executable(sfizz_tests ${SFIZZ_TEST_SOURCES})
|
||||||
target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::jsl)
|
target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::spin_mutex sfizz::jsl)
|
||||||
sfizz_enable_lto_if_needed(sfizz_tests)
|
sfizz_enable_lto_if_needed(sfizz_tests)
|
||||||
sfizz_enable_fast_math(sfizz_tests)
|
sfizz_enable_fast_math(sfizz_tests)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
// license. You should have receive a LICENSE.md file along with the code.
|
// license. You should have receive a LICENSE.md file along with the code.
|
||||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
#include "sfizz/utility/SpinMutex.h"
|
|
||||||
#include "catch2/catch.hpp"
|
#include "catch2/catch.hpp"
|
||||||
|
#include <SpinMutex.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue