Replaced glib mutex by QMutex

This commit is contained in:
Michaël Lemaire 2013-10-20 15:01:57 +02:00
parent 4ee1c4f7e1
commit 25d14a43ce
6 changed files with 84 additions and 35 deletions

View file

@ -9,6 +9,7 @@
#include "system.h" #include "system.h"
#include "PictureFile.h" #include "PictureFile.h"
#include "Thread.h" #include "Thread.h"
#include "Mutex.h"
typedef struct typedef struct
{ {

View file

@ -17,39 +17,6 @@ int systemGetFileSize(const char* path);
#ifdef HAVE_GLIB #ifdef HAVE_GLIB
#include <glib.h> #include <glib.h>
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) static inline void timeSleepMs(unsigned long ms)
{ {
g_usleep(ms * 1000); g_usleep(ms * 1000);

View file

@ -3,6 +3,7 @@
#include <assert.h> #include <assert.h>
#include "../system.h" #include "../system.h"
#include "Thread.h" #include "Thread.h"
#include "Mutex.h"
#define PARALLEL_MAX_THREADS 20 #define PARALLEL_MAX_THREADS 20

27
src/system/Mutex.cpp Normal file
View file

@ -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();
}

51
src/system/Mutex.h Normal file
View file

@ -0,0 +1,51 @@
#ifndef MUTEX_H
#define MUTEX_H
#include "system_global.h"
#ifdef __cplusplus
#include <QMutex>
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

View file

@ -13,12 +13,14 @@ DEFINES += SYSTEM_LIBRARY
SOURCES += \ SOURCES += \
PictureFile.cpp \ PictureFile.cpp \
Thread.cpp Thread.cpp \
Mutex.cpp
HEADERS +=\ HEADERS +=\
system_global.h \ system_global.h \
PictureFile.h \ PictureFile.h \
Thread.h Thread.h \
Mutex.h
unix:!symbian { unix:!symbian {
maemo5 { maemo5 {