Give up on mod mutex, not the right tool; Add screenshot to manual

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-02-10 22:51:08 +00:00
parent c9fd262e75
commit bd038fef75
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
3 changed files with 6 additions and 40 deletions

View file

@ -8,6 +8,8 @@ This document briefly describes how to use Cardinal with a [MOD device](https://
It is intended for this documentation to be part of the plugin bundle when installed from the It is intended for this documentation to be part of the plugin bundle when installed from the
[MOD Plugin store](https://pedalboards.moddevices.com/plugins). [MOD Plugin store](https://pedalboards.moddevices.com/plugins).
![Screenshot](../src/MOD/CardinalFX.lv2/modgui/screenshot.png "Screenshot")
## Plugin overview ## Plugin overview
Cardinal is a free and open-source virtual modular synthesizer plugin,. Cardinal is a free and open-source virtual modular synthesizer plugin,.

View file

@ -19,14 +19,6 @@
#include <pthread.h> #include <pthread.h>
#ifdef __MOD_DEVICES__
#include <linux/futex.h>
#include <sys/time.h>
#include <errno.h>
#include <syscall.h>
#include <unistd.h>
#endif
/* replace Rack's mutex with our own custom one, which can do priority inversion. */ /* replace Rack's mutex with our own custom one, which can do priority inversion. */
namespace rack { namespace rack {
@ -34,11 +26,7 @@ namespace rack {
struct SharedMutex { struct SharedMutex {
pthread_mutex_t readLock; pthread_mutex_t readLock;
#ifdef __MOD_DEVICES__
int writeLock;
#else
pthread_mutex_t writeLock; pthread_mutex_t writeLock;
#endif
SharedMutex() noexcept { SharedMutex() noexcept {
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
@ -48,52 +36,28 @@ struct SharedMutex {
pthread_mutex_init(&readLock, &attr); pthread_mutex_init(&readLock, &attr);
pthread_mutexattr_destroy(&attr); pthread_mutexattr_destroy(&attr);
#ifdef __MOD_DEVICES__
writeLock = 1;
#else
pthread_mutexattr_t attr2; pthread_mutexattr_t attr2;
pthread_mutexattr_init(&attr2); pthread_mutexattr_init(&attr2);
pthread_mutexattr_setprotocol(&attr2, PTHREAD_PRIO_NONE); pthread_mutexattr_setprotocol(&attr2, PTHREAD_PRIO_NONE);
pthread_mutexattr_settype(&attr2, PTHREAD_MUTEX_NORMAL); pthread_mutexattr_settype(&attr2, PTHREAD_MUTEX_NORMAL);
pthread_mutex_init(&writeLock, &attr2); pthread_mutex_init(&writeLock, &attr2);
pthread_mutexattr_destroy(&attr2); pthread_mutexattr_destroy(&attr2);
#endif
} }
~SharedMutex() noexcept { ~SharedMutex() noexcept {
pthread_mutex_destroy(&readLock); pthread_mutex_destroy(&readLock);
#ifndef __MOD_DEVICES__
pthread_mutex_destroy(&writeLock); pthread_mutex_destroy(&writeLock);
#endif
} }
// for std::lock_guard usage, writers lock // for std::lock_guard usage, writers lock
void lock() noexcept { void lock() noexcept {
#ifdef __MOD_DEVICES__
for (;;)
{
if (__sync_bool_compare_and_swap(&writeLock, 1, 0))
return;
if (syscall(__NR_futex, &writeLock, FUTEX_WAIT_PRIVATE, 0, nullptr, nullptr, 0) != 0)
{
if (errno != EAGAIN && errno != EINTR)
return;
}
}
#else
pthread_mutex_lock(&writeLock);
#endif
pthread_mutex_lock(&readLock); pthread_mutex_lock(&readLock);
pthread_mutex_lock(&writeLock);
} }
void unlock() noexcept { void unlock() noexcept {
pthread_mutex_unlock(&readLock);
#ifdef __MOD_DEVICES__
if (__sync_bool_compare_and_swap(&writeLock, 0, 1))
syscall(__NR_futex, &writeLock, FUTEX_WAKE_PRIVATE, 1, nullptr, nullptr, 0);
#else
pthread_mutex_unlock(&writeLock); pthread_mutex_unlock(&writeLock);
#endif pthread_mutex_unlock(&readLock);
} }
// for SharedLock usage, readers lock // for SharedLock usage, readers lock

View file

@ -307,7 +307,7 @@ $(TARGET_DIR)/$(NAME).lv2/mod%: ../MOD/$(NAME).lv2/mod%
$(SILENT)ln -sf $(abspath $<) $@ $(SILENT)ln -sf $(abspath $<) $@
$(TARGET_DIR)/$(NAME).lv2/modgui/documentation.pdf: ../../doc/MODDEVICES.md $(TARGET_DIR)/$(NAME).lv2/modgui $(TARGET_DIR)/$(NAME).lv2/modgui/documentation.pdf: ../../doc/MODDEVICES.md $(TARGET_DIR)/$(NAME).lv2/modgui
pandoc $< -o $@ (cd ../../doc/ && pandoc MODDEVICES.md -f markdown+implicit_figures -o $(abspath $@))
endif endif
$(TARGET_DIR)/$(NAME).vst/resources/%: ../Rack/res/% $(TARGET_DIR)/$(NAME).vst/resources/%: ../Rack/res/%