utils.hpp (845B)
1 #pragma once 2 3 #include <atomic> 4 #include <string> 5 6 #include "rack.hpp" 7 8 using namespace rack; 9 10 namespace bogaudio { 11 12 template <typename TModule, typename TModuleWidget, typename... Tags> 13 Model* createModel( 14 const char* slug, 15 const char* name, 16 const char* description, 17 Tags... tags 18 ) { 19 // params besides slug are obsolete here, but see scripts/modules_to_plugin_json.rb 20 return rack::createModel<TModule, TModuleWidget>(slug); 21 } 22 23 // https://stackoverflow.com/questions/26583433/c11-implementation-of-spinlock-using-atomic 24 struct SpinLock { 25 std::atomic_flag locked = ATOMIC_FLAG_INIT ; 26 27 inline void lock() { 28 while (locked.test_and_set(std::memory_order_acquire)) {} 29 } 30 31 inline void unlock() { 32 locked.clear(std::memory_order_release); 33 } 34 }; 35 36 std::string format(const char* fmt, ...); 37 38 } // namespace bogaudio