Skip to content

Commit ee1649c

Browse files
committed
wip: thread annotations
1 parent 186326a commit ee1649c

49 files changed

Lines changed: 641 additions & 381 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/toolchain-aarch64-linux-android.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
7777
# CXX_FLAGS += -lstdc++
7878

7979
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE -march=armv8-a -mtune=cortex-a78" CACHE STRING "Toolchain CFLAGS")
80-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING "Toolchain CXXFLAGS")
80+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS" CACHE STRING "Toolchain CXXFLAGS")
8181
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie -static-libstdc++" CACHE STRING "Toolchain LDFLAGS")
8282
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++" CACHE STRING "Toolchain LDFLAGS")
8383

build/toolchain-arm7-linux-android.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
8989
# LDFLAGS must have -Wl,--no-warn-mismatch
9090
#
9191
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 -fPIE" CACHE STRING "Toolchain CFLAGS")
92-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING "Toolchain CXXFLAGS")
92+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS" CACHE STRING "Toolchain CXXFLAGS")
9393
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -march=armv7-a -Wl,--no-warn-mismatch -L${TOOLCHAIN}/arm-linux-androideabi/lib/armv7-a -static-libstdc++ -fPIE -pie" CACHE STRING "Toolchain LDFLAGS")
9494
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -march=armv7-a -Wl,--no-warn-mismatch -L${TOOLCHAIN}/arm-linux-androideabi/lib/armv7-a -static-libstdc++" CACHE STRING "Toolchain LDFLAGS")
9595
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

build/toolchain-x86-linux-android.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
7373

7474
# compiler and linker flags
7575
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE" CACHE STRING "Toolchain CFLAGS")
76-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING "Toolchain CXXFLAGS")
76+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS" CACHE STRING "Toolchain CXXFLAGS")
7777
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-warn-mismatch -L${TOOLCHAIN}/i686-linux-android/lib64/ -static-libstdc++ -fPIE -pie" CACHE STRING "Toolchain LDFLAGS")
7878
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-warn-mismatch -L${TOOLCHAIN}/i686-linux-android/lib64/ -static-libstdc++" CACHE STRING "Toolchain LDFLAGS")
7979
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

build/toolchain-x86_64-linux-android.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
7373

7474
# compiler and linker flags
7575
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE" CACHE STRING "Toolchain CFLAGS")
76-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING "Toolchain CXXFLAGS")
76+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS" CACHE STRING "Toolchain CXXFLAGS")
7777
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-warn-mismatch -L${TOOLCHAIN}/x86_64-linux-android/lib64/ -static-libstdc++ -fPIE -pie" CACHE STRING "Toolchain LDFLAGS")
7878
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-warn-mismatch -L${TOOLCHAIN}/x86_64-linux-android/lib64/ -static-libstdc++" CACHE STRING "Toolchain LDFLAGS")
7979
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

filament/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,10 @@ target_compile_options(${TARGET} PRIVATE
803803
$<$<PLATFORM_ID:Linux>:${LINUX_COMPILER_FLAGS}>
804804
)
805805

806+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
807+
target_compile_options(${TARGET} PRIVATE -Wthread-safety)
808+
endif()
809+
806810
target_link_libraries(${TARGET} PRIVATE
807811
$<$<AND:$<PLATFORM_ID:Linux>,$<CONFIG:Release>>:${LINUX_LINKER_OPTIMIZATION_FLAGS}>
808812
)

filament/backend/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ target_compile_options(${TARGET} PRIVATE
536536
$<$<AND:$<PLATFORM_ID:Darwin>,$<CONFIG:Release>>:${DARWIN_OPTIMIZATION_FLAGS}>
537537
)
538538

539+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
540+
target_compile_options(${TARGET} PRIVATE -Wthread-safety)
541+
endif()
542+
539543
if (FILAMENT_SUPPORTS_METAL)
540544
target_compile_definitions(${TARGET} PRIVATE $<$<BOOL:${FILAMENT_METAL_PROFILING}>:FILAMENT_METAL_PROFILING>)
541545
endif()

filament/backend/include/backend/Platform.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
#include <utils/Invocable.h>
2525
#include <utils/Mutex.h>
2626

27-
#include <stddef.h>
28-
#include <stdint.h>
29-
3027
#include <atomic>
3128
#include <memory>
3229
#include <mutex>
3330

31+
#include <stddef.h>
32+
#include <stdint.h>
33+
3434
namespace utils {
3535
class FeatureFlagManager;
3636
}
@@ -634,10 +634,10 @@ class UTILS_PUBLIC Platform {
634634
void debugUpdateStat(const char* UTILS_NONNULL key, utils::CString stringValue);
635635

636636
private:
637-
std::shared_ptr<InsertBlobFunc> mInsertBlob;
638-
std::shared_ptr<RetrieveBlobFunc> mRetrieveBlob;
639-
std::shared_ptr<DebugUpdateStatFunc> mDebugUpdateStat;
640637
mutable utils::Mutex mMutex;
638+
std::shared_ptr<InsertBlobFunc> mInsertBlob UTILS_GUARDED_BY(mMutex);
639+
std::shared_ptr<RetrieveBlobFunc> mRetrieveBlob UTILS_GUARDED_BY(mMutex);
640+
std::shared_ptr<DebugUpdateStatFunc> mDebugUpdateStat UTILS_GUARDED_BY(mMutex);
641641
};
642642

643643
} // namespace filament

filament/backend/include/private/backend/CommandBufferQueue.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
#define TNT_FILAMENT_BACKEND_PRIVATE_COMMANDBUFFERQUEUE_H
1919

2020
#include "private/backend/CircularBuffer.h"
21-
2221
#include <utils/Condition.h>
2322
#include <utils/Mutex.h>
23+
#include <utils/compiler.h>
2424

25-
#include <vector>
26-
#include <exception>
2725
#include <atomic>
26+
#include <condition_variable>
27+
#include <exception>
28+
#include <mutex>
29+
#include <vector>
2830

2931
#include <stddef.h>
3032
#include <stdint.h>
@@ -54,7 +56,10 @@ class CommandBufferQueue {
5456

5557
size_t getCapacity() const noexcept { return mRequiredSize; }
5658

57-
size_t getHighWatermark() const noexcept { return mHighWatermark; }
59+
size_t getHighWatermark() const noexcept {
60+
std::lock_guard const lock(mLock);
61+
return mHighWatermark;
62+
}
5863

5964
// wait for commands to be available and returns an array containing these commands
6065
std::vector<Range> waitForCommands() const;
@@ -103,13 +108,13 @@ class CommandBufferQueue {
103108

104109
// space available in the circular buffer
105110

106-
mutable utils::Mutex mLock;
107-
mutable utils::Condition mCondition;
108-
mutable std::vector<Range> mCommandBuffersToExecute;
109-
size_t mFreeSpace = 0;
110-
size_t mHighWatermark = 0;
111-
uint32_t mExitRequested = 0;
112-
bool mPaused = false;
111+
mutable std::mutex mLock;
112+
mutable std::condition_variable mCondition;
113+
mutable std::vector<Range> mCommandBuffersToExecute UTILS_GUARDED_BY(mLock);
114+
size_t mFreeSpace UTILS_GUARDED_BY(mLock) = 0;
115+
size_t mHighWatermark UTILS_GUARDED_BY(mLock) = 0;
116+
uint32_t mExitRequested UTILS_GUARDED_BY(mLock) = 0;
117+
bool mPaused UTILS_GUARDED_BY(mLock) = false;
113118

114119
static constexpr uint32_t EXIT_REQUESTED = 0x31415926;
115120

filament/backend/include/private/backend/HandleAllocator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DebugTag {
6262
// driver thread, but it can be accessed from any thread, because it's called from handle_cast<>
6363
// which is used by synchronous calls.
6464
mutable utils::Mutex mDebugTagLock;
65-
tsl::robin_map<HandleBase::HandleId, utils::ImmutableCString> mDebugTags;
65+
tsl::robin_map<HandleBase::HandleId, utils::ImmutableCString> mDebugTags UTILS_GUARDED_BY(mDebugTagLock);
6666
};
6767

6868
/*
@@ -394,7 +394,7 @@ class HandleAllocator : public DebugTag {
394394

395395
// Below is only used when running out of space in the HandleArena
396396
mutable utils::Mutex mLock;
397-
tsl::robin_map<HandleBase::HandleId, void*> mOverflowMap;
397+
tsl::robin_map<HandleBase::HandleId, void*> mOverflowMap UTILS_GUARDED_BY(mLock);
398398
std::atomic<HandleBase::HandleId> mId = 0;
399399

400400
// constants

filament/backend/include/private/backend/VirtualMachineEnv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class VirtualMachineEnv {
5252
JNIEnv* getEnvironmentSlow();
5353

5454
static utils::Mutex sLock;
55-
static JavaVM* sVirtualMachine;
55+
static JavaVM* sVirtualMachine UTILS_GUARDED_BY(sLock);
5656
static JavaVM* getVirtualMachine();
5757

5858
JNIEnv* mJniEnv = nullptr;

0 commit comments

Comments
 (0)