Skip to content

Commit

Permalink
Update semaphore and dpf
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Mar 7, 2024
1 parent ef92781 commit b200856
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dpf
Submodule dpf updated 75 files
+24 −4 Makefile.base.mk
+47 −9 Makefile.plugins.mk
+52 −1 cmake/DPF-plugin.cmake
+17 −13 dgl/Base.hpp
+2 −2 dgl/EventHandlers.hpp
+1 −0 dgl/Makefile
+1 −0 dgl/Window.hpp
+33 −9 dgl/src/ApplicationPrivateData.cpp
+6 −0 dgl/src/ApplicationPrivateData.hpp
+7 −7 dgl/src/Cairo.cpp
+5 −5 dgl/src/EventHandlers.cpp
+13 −13 dgl/src/Layout.cpp
+11 −11 dgl/src/OpenGL.cpp
+2 −2 dgl/src/SubWidget.cpp
+27 −17 dgl/src/Window.cpp
+13 −7 dgl/src/WindowPrivateData.cpp
+11 −7 dgl/src/WindowPrivateData.hpp
+1 −1 dgl/src/pugl-upstream
+25 −15 dgl/src/pugl.cpp
+7 −2 distrho/DistrhoDetails.hpp
+30 −1 distrho/DistrhoInfo.hpp
+19 −2 distrho/DistrhoPlugin.hpp
+6 −2 distrho/DistrhoPluginMain.cpp
+7 −2 distrho/DistrhoUIMain.cpp
+58 −4 distrho/DistrhoUtils.hpp
+38 −3 distrho/extra/FileBrowserDialogImpl.cpp
+3 −0 distrho/src/DistrhoDefines.h
+2 −1 distrho/src/DistrhoPlugin.cpp
+3,173 −0 distrho/src/DistrhoPluginAU.cpp
+16 −24 distrho/src/DistrhoPluginCLAP.cpp
+66 −14 distrho/src/DistrhoPluginChecks.h
+281 −0 distrho/src/DistrhoPluginExport.cpp
+44 −10 distrho/src/DistrhoPluginInternal.hpp
+11 −5 distrho/src/DistrhoPluginJACK.cpp
+11 −23 distrho/src/DistrhoPluginLV2.cpp
+6 −4 distrho/src/DistrhoPluginLV2export.cpp
+1 −1 distrho/src/DistrhoPluginVST.hpp
+25 −29 distrho/src/DistrhoPluginVST2.cpp
+49 −43 distrho/src/DistrhoPluginVST3.cpp
+3 −3 distrho/src/DistrhoUI.cpp
+502 −0 distrho/src/DistrhoUIAU.mm
+12 −3 distrho/src/DistrhoUIDSSI.cpp
+5 −2 distrho/src/DistrhoUIInternal.hpp
+4 −1 distrho/src/DistrhoUILV2.cpp
+31 −12 distrho/src/DistrhoUIPrivateData.hpp
+6 −4 distrho/src/DistrhoUIVST3.cpp
+5 −3 distrho/src/DistrhoUtils.cpp
+1 −10 examples/CairoUI/CairoExamplePlugin.cpp
+17 −1 examples/CairoUI/DistrhoPluginInfo.h
+1 −1 examples/CairoUI/Makefile
+4 −1 examples/Info/DistrhoPluginInfo.h
+1 −10 examples/Info/InfoExamplePlugin.cpp
+16 −6 examples/Info/InfoExampleUI.cpp
+1 −0 examples/Info/Makefile
+4 −1 examples/Meters/DistrhoPluginInfo.h
+1 −10 examples/Meters/ExamplePluginMeters.cpp
+1 −0 examples/Meters/Makefile
+4 −1 examples/MidiThrough/DistrhoPluginInfo.h
+1 −0 examples/MidiThrough/Makefile
+1 −10 examples/MidiThrough/MidiThroughExamplePlugin.cpp
+4 −1 examples/Parameters/DistrhoPluginInfo.h
+1 −10 examples/Parameters/ExamplePluginParameters.cpp
+6 −0 examples/Parameters/ExampleUIParameters.cpp
+1 −0 examples/Parameters/Makefile
+4 −1 examples/SendNote/DistrhoPluginInfo.h
+1 −0 examples/SendNote/Makefile
+1 −10 examples/SendNote/SendNoteExamplePlugin.cpp
+4 −1 examples/States/DistrhoPluginInfo.h
+1 −10 examples/States/ExamplePluginStates.cpp
+1 −0 examples/States/Makefile
+7 −0 utils/au-services-restart.sh
+1 −1 utils/generate-ttl.sh
+14 −5 utils/package-osx-bundles.sh
+139 −0 utils/state2json.cpp
+1 −0 utils/symbols/au.exp
103 changes: 77 additions & 26 deletions plugins/common/Semaphore.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2023 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
* SPDX-License-Identifier: ISC
*/

Expand All @@ -16,6 +16,15 @@
# ifndef NOMINMAX
# define NOMINMAX
# endif
# ifndef NOKERNEL
# define NOKERNEL
# endif
# ifndef NOSERVICE
# define NOSERVICE
# endif
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <winsock2.h>
# include <windows.h>
#else
Expand All @@ -30,75 +39,117 @@ START_NAMESPACE_DISTRHO
class Semaphore
{
public:
Semaphore(const int initialValue = 0)
Semaphore(const uint16_t initialValue = 0)
#if defined(DISTRHO_OS_MAC)
: task(mach_task_self()),
sem(nullptr)
#elif defined(DISTRHO_OS_WINDOWS)
: handle(INVALID_HANDLE_VALUE)
#else
: sem()
#endif
{
#if defined(DISTRHO_OS_MAC)
task = mach_task_self();
DISTRHO_SAFE_ASSERT_RETURN(semaphore_create(task, &sem, SYNC_POLICY_FIFO, initialValue) == KERN_SUCCESS,);
DISTRHO_SAFE_ASSERT_RETURN(semaphore_create(task,
&sem,
SYNC_POLICY_FIFO,
static_cast<int>(initialValue)) == KERN_SUCCESS,);
#elif defined(DISTRHO_OS_WINDOWS)
handle = ::CreateSemaphoreA(nullptr, initialValue, std::max(initialValue, 1), nullptr);
handle = CreateSemaphoreA(nullptr, initialValue, LONG_MAX, nullptr);
DISTRHO_SAFE_ASSERT_RETURN(handle != INVALID_HANDLE_VALUE,);
#else
DISTRHO_SAFE_ASSERT_RETURN(::sem_init(&sem, 0, initialValue) == 0,);
DISTRHO_SAFE_ASSERT_RETURN(sem_init(&sem, 0, initialValue) == 0,);
#endif
}

~Semaphore()
{
#if defined(DISTRHO_OS_MAC)
::semaphore_destroy(task, sem);
semaphore_destroy(task, sem);
#elif defined(DISTRHO_OS_WINDOWS)
::CloseHandle(handle);
CloseHandle(handle);
#else
::sem_destroy(&sem);
sem_destroy(&sem);
#endif
}

void post()
{
#if defined(DISTRHO_OS_MAC)
::semaphore_signal(sem);
semaphore_signal(sem);
#elif defined(DISTRHO_OS_WINDOWS)
::ReleaseSemaphore(handle, 1, nullptr);
ReleaseSemaphore(handle, 1, nullptr);
#else
::sem_post(&sem);
sem_post(&sem);
#endif
}

bool wait()
{
#if defined(DISTRHO_OS_MAC)
return ::semaphore_wait(sem) == KERN_SUCCESS;
return semaphore_wait(sem) == KERN_SUCCESS;
#elif defined(DISTRHO_OS_WINDOWS)
return ::WaitForSingleObject(handle, INFINITE) == WAIT_OBJECT_0;
return WaitForSingleObject(handle, INFINITE) == WAIT_OBJECT_0;
#else
return ::sem_wait(&sem) == 0;
return sem_wait(&sem) == 0;
#endif
}

bool timedWait(const uint numSecs)
bool tryWait()
{
#if defined(DISTRHO_OS_MAC)
const struct mach_timespec time = { numSecs, 0 };
return ::semaphore_timedwait(sem, time) == KERN_SUCCESS;
const mach_timespec_t zero = { 0, 0 };
return semaphore_timedwait(sem, zero) == KERN_SUCCESS;
#elif defined(DISTRHO_OS_WINDOWS)
return ::WaitForSingleObject(handle, numSecs * 1000) == WAIT_OBJECT_0;
return WaitForSingleObject(handle, 0) == WAIT_OBJECT_0;
#else
return sem_trywait(&sem) == 0;
#endif
}

bool timedWait(const uint seconds, const uint nanoseconds)
{
#if defined(DISTRHO_OS_MAC)
const mach_timespec_t time = { seconds, static_cast<clock_res_t>(nanoseconds) };
return semaphore_timedwait(sem, time) == KERN_SUCCESS;
#elif defined(DISTRHO_OS_WINDOWS)
const uint milliseconds = seconds * 1000U + nanoseconds / 1000000U;
return WaitForSingleObject(handle, milliseconds) == WAIT_OBJECT_0;
#else
struct timespec timeout;
::clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_sec += numSecs;
return ::sem_timedwait(&sem, &timeout) == 0;
DISTRHO_SAFE_ASSERT_RETURN(clock_gettime(CLOCK_REALTIME, &timeout) == 0, false);

timeout.tv_sec += seconds;
timeout.tv_nsec += nanoseconds;
if (timeout.tv_nsec >= 1000000000LL)
{
++timeout.tv_sec;
timeout.tv_nsec -= 1000000000LL;
}

for (int r;;)
{
r = sem_timedwait(&sem, &timeout);

if (r < 0)
r = errno;

if (r == EINTR)
continue;

return r == 0;
}
#endif
}

private:
#if defined(DISTRHO_OS_MAC)
::mach_port_t task;
::semaphore_t sem;
mach_port_t task;
semaphore_t sem;
#elif defined(DISTRHO_OS_WINDOWS)
::HANDLE handle;
HANDLE handle;
#else
::sem_t sem;
sem_t sem;
#endif
};

Expand Down

0 comments on commit b200856

Please sign in to comment.