From 25d14a43ce3450db52561c1da6bfd928a8a98fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 20 Oct 2013 15:01:57 +0200 Subject: [PATCH] Replaced glib mutex by QMutex --- src/rendering/render.c | 1 + src/rendering/system.h | 33 ---------------------- src/rendering/tools/parallel.c | 1 + src/system/Mutex.cpp | 27 ++++++++++++++++++ src/system/Mutex.h | 51 ++++++++++++++++++++++++++++++++++ src/system/system.pro | 6 ++-- 6 files changed, 84 insertions(+), 35 deletions(-) create mode 100644 src/system/Mutex.cpp create mode 100644 src/system/Mutex.h diff --git a/src/rendering/render.c b/src/rendering/render.c index 72bf829..6dc3039 100644 --- a/src/rendering/render.c +++ b/src/rendering/render.c @@ -9,6 +9,7 @@ #include "system.h" #include "PictureFile.h" #include "Thread.h" +#include "Mutex.h" typedef struct { diff --git a/src/rendering/system.h b/src/rendering/system.h index 1515c15..ac6dcf4 100644 --- a/src/rendering/system.h +++ b/src/rendering/system.h @@ -17,39 +17,6 @@ int systemGetFileSize(const char* path); #ifdef HAVE_GLIB #include -typedef GMutex Mutex; - -static inline Mutex* mutexCreate() -{ -#ifdef GLIB_VERSION_2_32 - Mutex* mutex = malloc(sizeof(Mutex)); - g_mutex_init(mutex); - return mutex; -#else - return g_mutex_new(); -#endif -} - -static inline void mutexDestroy(Mutex* mutex) -{ -#ifdef GLIB_VERSION_2_32 - g_mutex_clear(mutex); - free(mutex); -#else - g_mutex_free(mutex); -#endif -} - -static inline void mutexAcquire(Mutex* mutex) -{ - g_mutex_lock(mutex); -} - -static inline void mutexRelease(Mutex* mutex) -{ - g_mutex_unlock(mutex); -} - static inline void timeSleepMs(unsigned long ms) { g_usleep(ms * 1000); diff --git a/src/rendering/tools/parallel.c b/src/rendering/tools/parallel.c index 52f74b9..7edd103 100644 --- a/src/rendering/tools/parallel.c +++ b/src/rendering/tools/parallel.c @@ -3,6 +3,7 @@ #include #include "../system.h" #include "Thread.h" +#include "Mutex.h" #define PARALLEL_MAX_THREADS 20 diff --git a/src/system/Mutex.cpp b/src/system/Mutex.cpp new file mode 100644 index 0000000..da3b23e --- /dev/null +++ b/src/system/Mutex.cpp @@ -0,0 +1,27 @@ +#include "Mutex.h" + +Mutex::Mutex() +{ +} + +// Transitional C-API + +Mutex* mutexCreate() +{ + return new Mutex(); +} + +void mutexDestroy(Mutex* mutex) +{ + delete mutex; +} + +void mutexAcquire(Mutex* mutex) +{ + mutex->acquire(); +} + +void mutexRelease(Mutex* mutex) +{ + mutex->release(); +} diff --git a/src/system/Mutex.h b/src/system/Mutex.h new file mode 100644 index 0000000..1ca2312 --- /dev/null +++ b/src/system/Mutex.h @@ -0,0 +1,51 @@ +#ifndef MUTEX_H +#define MUTEX_H + +#include "system_global.h" + +#ifdef __cplusplus + +#include + +namespace paysages +{ +namespace system +{ + +/*! + * \brief System mutex + */ +class Mutex: private QMutex +{ +public: + /*! + * \brief Create a new mutex + */ + Mutex(); + + inline void acquire() {QMutex::lock();} + inline void release() {QMutex::unlock();} +}; + +} +} + +extern "C" { +#endif + +// Transitional C-API + +#ifndef __cplusplus +typedef struct Mutex Mutex; +#endif + +Mutex* mutexCreate(); +void mutexDestroy(Mutex* mutex); +void mutexAcquire(Mutex* mutex); +void mutexRelease(Mutex* mutex); + +#ifdef __cplusplus +} +#endif + +#endif // MUTEX_H diff --git a/src/system/system.pro b/src/system/system.pro index bf2a8dc..c1c8f2e 100644 --- a/src/system/system.pro +++ b/src/system/system.pro @@ -13,12 +13,14 @@ DEFINES += SYSTEM_LIBRARY SOURCES += \ PictureFile.cpp \ - Thread.cpp + Thread.cpp \ + Mutex.cpp HEADERS +=\ system_global.h \ PictureFile.h \ - Thread.h + Thread.h \ + Mutex.h unix:!symbian { maemo5 {