Skip to content
Snippets Groups Projects
Verified Commit 4004c765 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Fixed events by using mutex for older GCC as alternative to semaphores

parent a874aabb
No related branches found
No related tags found
No related merge requests found
Pipeline #27491 passed
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment