summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/settings.h6
-rw-r--r--test/atomictest.cc189
2 files changed, 102 insertions, 93 deletions
diff --git a/src/settings.h b/src/settings.h
index 89f898c..0b73cf2 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -77,7 +77,7 @@ struct Settings
Atomic<bool> enable_velocity_randomiser{false};
Atomic<float> velocity_randomiser_weight{0.1f};
- Atomic<double> samplerate{44100.0};
+ Atomic<float> samplerate{44100.0};
Atomic<std::size_t> buffer_size{1024}; // Only used to show in the UI.
Atomic<bool> enable_resampling{true};
@@ -117,7 +117,7 @@ struct SettingsGetter
SettingRef<bool> enable_velocity_randomiser;
SettingRef<float> velocity_randomiser_weight;
- SettingRef<double> samplerate;
+ SettingRef<float> samplerate;
SettingRef<std::size_t> buffer_size;
SettingRef<bool> enable_resampling;
@@ -189,7 +189,7 @@ public:
Notifier<bool> enable_velocity_randomiser;
Notifier<float> velocity_randomiser_weight;
- Notifier<double> samplerate;
+ Notifier<float> samplerate;
Notifier<std::size_t> buffer_size;
Notifier<bool> enable_resampling;
diff --git a/test/atomictest.cc b/test/atomictest.cc
index 89c0295..9d2220c 100644
--- a/test/atomictest.cc
+++ b/test/atomictest.cc
@@ -29,8 +29,8 @@
#include <atomic.h>
class AtomicTest
- : public CppUnit::TestFixture {
-
+ : public CppUnit::TestFixture
+{
CPPUNIT_TEST_SUITE(AtomicTest);
CPPUNIT_TEST(podAtomicsUseStandardImpl);
CPPUNIT_TEST(nonPodAtomicsUseOwnImpl);
@@ -42,95 +42,104 @@ class AtomicTest
CPPUNIT_TEST(nonPodAtomicCanBeValueAssigned);
CPPUNIT_TEST(podAtomicsAreLockFree);
CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {}
- void tearDown() {}
-
- void podAtomicsUseStandardImpl() {
- CPPUNIT_ASSERT(isUsingStandardImpl<bool>());
- CPPUNIT_ASSERT(isUsingStandardImpl<unsigned short int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<short int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<unsigned int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<long int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long long int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<long long int>());
- CPPUNIT_ASSERT(isUsingStandardImpl<float>());
- CPPUNIT_ASSERT(isUsingStandardImpl<double>());
- CPPUNIT_ASSERT(isUsingStandardImpl<long double>());
- }
-
- void nonPodAtomicsUseOwnImpl() {
- CPPUNIT_ASSERT(!isUsingStandardImpl<std::string>());
- }
-
- void podAtomicCanBeDefaultInitialized() {
- Atomic<int> i;
- // note: i is initialized with garbage
- (void)i; // prevent compiler 'unused' warning
- }
-
- void nonPodAtomicCanBeDefaultInitialized() {
- Atomic<std::string> s;
- CPPUNIT_ASSERT_EQUAL(s.load(), std::string{});
- }
-
- void podAtomicCanBeValueInitialized() {
- Atomic<int> i{5};
- CPPUNIT_ASSERT_EQUAL(i.load(), 5);
- }
-
- void nonPodAtomicCanBeValueInitialized() {
- Atomic<std::string> s{"hello world"};
- CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"});
- }
-
- void podAtomicCanBeValueAssigned() {
- Atomic<int> i;
- i = 5;
- CPPUNIT_ASSERT_EQUAL(i.load(), 5);
- }
-
- void nonPodAtomicCanBeValueAssigned() {
- Atomic<std::string> s;
- s = "hello world";
- CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"});
- }
-
- void podAtomicsAreLockFree() {
- CPPUNIT_ASSERT(isLockFree<bool>());
- CPPUNIT_ASSERT(isLockFree<unsigned short int>());
- CPPUNIT_ASSERT(isLockFree<short int>());
- CPPUNIT_ASSERT(isLockFree<unsigned int>());
- CPPUNIT_ASSERT(isLockFree<int>());
- CPPUNIT_ASSERT(isLockFree<unsigned long int>());
- CPPUNIT_ASSERT(isLockFree<long int>());
- CPPUNIT_ASSERT(isLockFree<unsigned long long int>());
- CPPUNIT_ASSERT(isLockFree<long long int>());
- CPPUNIT_ASSERT(isLockFree<float>());
- CPPUNIT_ASSERT(isLockFree<double>());
-
- // compile error: undefined reference to `__atomic_is_lock_free'
- //CPPUNIT_ASSERT(isLockFree<long double>());
- }
-
- // todo: further testing
-
- private:
- template <typename T>
- bool isUsingStandardImpl() {
- return std::is_base_of<std::atomic<T>, Atomic<T>>::value;
- }
-
- template <typename T>
- bool isLockFree() {
- Atomic<T> a;
- return a.is_lock_free();
- }
+
+public:
+ void setUp() {}
+ void tearDown() {}
+
+ void podAtomicsUseStandardImpl()
+ {
+ CPPUNIT_ASSERT(isUsingStandardImpl<bool>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned short int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<short int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<float>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<double>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long double>());
+ }
+
+ void nonPodAtomicsUseOwnImpl()
+ {
+ CPPUNIT_ASSERT(!isUsingStandardImpl<std::string>());
+ }
+
+ void podAtomicCanBeDefaultInitialized()
+ {
+ Atomic<int> i;
+ // note: i is initialized with garbage
+ (void)i; // prevent compiler 'unused' warning
+ }
+
+ void nonPodAtomicCanBeDefaultInitialized()
+ {
+ Atomic<std::string> s;
+ CPPUNIT_ASSERT_EQUAL(s.load(), std::string{});
+ }
+
+ void podAtomicCanBeValueInitialized()
+ {
+ Atomic<int> i{5};
+ CPPUNIT_ASSERT_EQUAL(i.load(), 5);
+ }
+
+ void nonPodAtomicCanBeValueInitialized()
+ {
+ Atomic<std::string> s{"hello world"};
+ CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"});
+ }
+
+ void podAtomicCanBeValueAssigned()
+ {
+ Atomic<int> i;
+ i = 5;
+ CPPUNIT_ASSERT_EQUAL(i.load(), 5);
+ }
+
+ void nonPodAtomicCanBeValueAssigned()
+ {
+ Atomic<std::string> s;
+ s = "hello world";
+ CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"});
+ }
+
+ void podAtomicsAreLockFree()
+ {
+ CPPUNIT_ASSERT(isLockFree<bool>());
+ CPPUNIT_ASSERT(isLockFree<unsigned short int>());
+ CPPUNIT_ASSERT(isLockFree<short int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned int>());
+ CPPUNIT_ASSERT(isLockFree<int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned long int>());
+ CPPUNIT_ASSERT(isLockFree<long int>());
+ CPPUNIT_ASSERT(isLockFree<float>());
+ CPPUNIT_ASSERT(isLockFree<std::size_t>());
+
+ // NOTE: Not lock free on small systems
+ //CPPUNIT_ASSERT(isLockFree<unsigned long long int>());
+ //CPPUNIT_ASSERT(isLockFree<long long int>());
+ //CPPUNIT_ASSERT(isLockFree<double>());
+ //CPPUNIT_ASSERT(isLockFree<long double>());
+ }
+
+private:
+ template <typename T>
+ bool isUsingStandardImpl()
+ {
+ return std::is_base_of<std::atomic<T>, Atomic<T>>::value;
+ }
+
+ template <typename T>
+ bool isLockFree()
+ {
+ Atomic<T> a;
+ return a.is_lock_free();
+ }
};
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(AtomicTest);
-