From 4004c765b299b5f8bccd85fc5b1cd335ec473860 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Tue, 28 Sep 2021 19:34:05 +0200
Subject: [PATCH] Fixed events by using mutex for older GCC as alternative to
 semaphores

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 CMakeLists.txt         |  4 ++--
 include/vkcv/Event.hpp | 26 +++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6f3c000f..1af81b59 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,8 +42,8 @@ if (vkcv_build_debug)
 	endif()
 endif()
 
-if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0.0"))
-	set(vkcv_flags ${vkcv_flags} " -std=c++2a -std=gnu++2a")
+if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.0.0"))
+	list(APPEND vkcv_definitions __NO_SEMAPHORES__)
 endif()
 
 # configure everything to use the required dependencies
diff --git a/include/vkcv/Event.hpp b/include/vkcv/Event.hpp
index edb8131a..0a5cc1f0 100644
--- a/include/vkcv/Event.hpp
+++ b/include/vkcv/Event.hpp
@@ -3,8 +3,12 @@
 #include <functional>
 
 #ifndef __MINGW32__
+#ifdef __NO_SEMAPHORES__
+#include <mutex>
+#else
 #include <semaphore>
 #endif
+#endif
 
 #include <vector>
 
@@ -34,7 +38,11 @@ namespace vkcv {
         uint32_t m_id_counter;
 	
 #ifndef __MINGW32__
+#ifdef __NO_SEMAPHORES__
+		std::mutex m_mutex;
+#else
 		std::binary_semaphore m_semaphore;
+#endif
 #endif
 
     public:
@@ -84,7 +92,11 @@ namespace vkcv {
          */
         void lock() {
 #ifndef __MINGW32__
+#ifdef __NO_SEMAPHORES__
+			m_mutex.lock();
+#else
 			m_semaphore.acquire();
+#endif
 #endif
         }
 	
@@ -93,15 +105,27 @@ namespace vkcv {
 		*/
         void unlock() {
 #ifndef __MINGW32__
+#ifdef __NO_SEMAPHORES__
+			m_mutex.unlock();
+#else
 			m_semaphore.release();
+#endif
 #endif
         }
 
         explicit event(bool locked = false)
 #ifndef __MINGW32__
+#ifndef __NO_SEMAPHORES__
 		: m_semaphore(locked? 1 : 0)
 #endif
-		{}
+#endif
+		{
+#ifndef __MINGW32__
+#ifdef __NO_SEMAPHORES__
+			if (locked) m_mutex.lock();
+#endif
+#endif
+		}
 
         event(const event &other) = delete;
 
-- 
GitLab