Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBartosz Taudul <wolf.pld@gmail.com>2017-12-10 22:36:10 +0300
committerBartosz Taudul <wolf.pld@gmail.com>2017-12-10 22:36:10 +0300
commit171e962f97a6afa73b726a621ab6f683af3284ee (patch)
tree86b0456d207777e17514f7c9884bffc93be53e9b /test
parent0f2d41413f52540e0a0958ea55fcb5cd040a17cc (diff)
Shared mutex test.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/test.cpp31
2 files changed, 32 insertions, 1 deletions
diff --git a/test/Makefile b/test/Makefile
index e9e01a16..14ee2202 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,6 +1,6 @@
OPTFLAGS := -g3 -fmerge-constants
CFLAGS := $(OPTFLAGS) -Wall -DTRACY_ENABLE
-CXXFLAGS := $(CFLAGS) -std=gnu++11
+CXXFLAGS := $(CFLAGS) -std=gnu++17
DEFINES +=
INCLUDES :=
LIBS := -lpthread
diff --git a/test/test.cpp b/test/test.cpp
index 1750a45c..48114107 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -1,6 +1,7 @@
#include <chrono>
#include <mutex>
#include <thread>
+#include <shared_mutex>
#include "../Tracy.hpp"
#include "../common/TracySystem.hpp"
@@ -138,6 +139,28 @@ void DepthTest()
}
}
+static std::shared_mutex sharedMutex;
+
+void SharedRead()
+{
+ for(;;)
+ {
+ std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
+ std::shared_lock<std::shared_mutex> lock( sharedMutex );
+ std::this_thread::sleep_for( std::chrono::milliseconds( 4 ) );
+ }
+}
+
+void SharedWrite()
+{
+ for(;;)
+ {
+ std::this_thread::sleep_for( std::chrono::milliseconds( 4 ) );
+ std::unique_lock<std::shared_mutex> lock( sharedMutex );
+ std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
+ }
+}
+
int main()
{
auto t1 = std::thread( TestFunction );
@@ -153,6 +176,10 @@ int main()
auto t11 = std::thread( DepthTest );
auto t12 = std::thread( RecLock );
auto t13 = std::thread( RecLock );
+ auto t14 = std::thread( SharedRead );
+ auto t15 = std::thread( SharedRead );
+ auto t16 = std::thread( SharedRead );
+ auto t17 = std::thread( SharedWrite );
tracy::SetThreadName( t1, "First thread" );
tracy::SetThreadName( t2, "Second thread" );
@@ -167,6 +194,10 @@ int main()
tracy::SetThreadName( t11, "Depth test" );
tracy::SetThreadName( t12, "Recursive mtx 1" );
tracy::SetThreadName( t13, "Recursive mtx 2" );
+ tracy::SetThreadName( t14, "Shared read 1" );
+ tracy::SetThreadName( t15, "Shared read 2" );
+ tracy::SetThreadName( t16, "Shared read 3" );
+ tracy::SetThreadName( t17, "Shared write 1" );
for(;;)
{