Skip to content

Commit

Permalink
rtcheck: Added rtcheck on macOS and added this check to the allocatio…
Browse files Browse the repository at this point in the history
…n test
  • Loading branch information
drowaudio committed Jun 11, 2024
1 parent b107dd2 commit e62e1b4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
31 changes: 30 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if (APPLE)

# Uncomment to produce a universal binary
# set(CMAKE_OSX_ARCHITECTURES arm64 x86_64)
set(PLUGINVAL_ENABLE_RTCHECK ON)
endif()

# Uncomment to enable tsan
Expand All @@ -19,7 +20,20 @@ endif()
set_property(GLOBAL PROPERTY USE_FOLDERS YES)
option(JUCE_ENABLE_MODULE_SOURCE_GROUPS "Enable Module Source Groups" ON)

option(PLUGINVAL_FETCH_JUCE "Fetch JUCE along with PluginVal" ON)
if(PLUGINVAL_ENABLE_RTCHECK)
Include(FetchContent)
FetchContent_Declare(rtcheck
GIT_REPOSITORY https://github.com/Tracktion/rtcheck.git
GIT_TAG origin/main
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/rtcheck)
FetchContent_MakeAvailable(rtcheck)

# execute_process(COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/rtcheck-build)
# execute_process(COMMAND cmake -B ${CMAKE_CURRENT_BINARY_DIR}/rtcheck/build -S ${CMAKE_CURRENT_BINARY_DIR}/rtcheck)
# execute_process(COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR}/rtcheck)
endif()

option(PLUGINVAL_FETCH_JUCE "Fetch JUCE along with pluginval" ON)

if(PLUGINVAL_FETCH_JUCE)
add_subdirectory(modules/juce)
Expand Down Expand Up @@ -85,6 +99,7 @@ target_compile_definitions(pluginval PRIVATE
JUCE_MODAL_LOOPS_PERMITTED=1
JUCE_REPORT_APP_USAGE=0
JUCE_GUI_BASICS_INCLUDE_XHEADERS=1
$<$<BOOL:${PLUGINVAL_ENABLE_RTCHECK}>:PLUGINVAL_ENABLE_RTCHECK=1>
VERSION="${CURRENT_VERSION}")

target_link_libraries(pluginval PRIVATE
Expand All @@ -98,6 +113,20 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
-static-libstdc++)
endif()

if (PLUGINVAL_ENABLE_RTCHECK)
target_link_libraries(pluginval PRIVATE
rtcheck)

if (APPLE)
add_custom_command(TARGET pluginval POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Executable path: $<TARGET_FILE_DIR:pluginval>")
add_custom_command(TARGET pluginval POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/_deps/rtcheck-build/src/librtcheck.dylib
$<TARGET_FILE_DIR:pluginval>/../Libraries/librtcheck.dylib)
endif ()
endif()

set (cmdline_docs_out "${CMAKE_CURRENT_LIST_DIR}/docs/Command line options.md")

add_custom_command (OUTPUT "${cmdline_docs_out}"
Expand Down
33 changes: 33 additions & 0 deletions Source/RTCheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*==============================================================================
Copyright 2018 by Tracktion Corporation.
For more information visit www.tracktion.com
You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
pluginval IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================*/

#pragma once

#if PLUGINVAL_ENABLE_RTCHECK
#include <rtcheck.h>
#define RTC_REALTIME_CONTEXT rtc::realtime_context rc##__LINE__; rtc::disable_checks_for_thread (static_cast<uint64_t>(rtc::check_flags::pthread_mutex_lock) | static_cast<uint64_t>(rtc::check_flags::pthread_mutex_unlock));

#define RTC_REALTIME_CONTEXT_IF_LEVEL_10(level) \
std::optional<rtc::realtime_context> rc; \
\
if (level >= 10) \
{ \
rc.emplace(); \
rtc::disable_checks_for_thread (static_cast<uint64_t>(rtc::check_flags::pthread_mutex_lock) \
| static_cast<uint64_t>(rtc::check_flags::pthread_mutex_unlock)); \
}

#else
#define RTC_REALTIME_CONTEXT
#endif
2 changes: 2 additions & 0 deletions Source/tests/ExtremeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "../PluginTests.h"
#include "../TestUtilities.h"
#include "../RTCheck.h"

//==============================================================================
struct AllocationsInRealTimeThreadTest : public PluginTest
Expand Down Expand Up @@ -66,6 +67,7 @@ struct AllocationsInRealTimeThreadTest : public PluginTest
fillNoise (ab);

{
RTC_REALTIME_CONTEXT_IF_LEVEL_10(ut.getOptions().strictnessLevel)
ScopedAllocationDisabler sad;
instance.processBlock (ab, mb);
}
Expand Down

0 comments on commit e62e1b4

Please sign in to comment.