Updated to mime the QThread & related classes interface

This commit is contained in:
Paolo Cignoni 2011-12-14 17:39:38 +00:00
parent ebc522f182
commit 2aa0988989
4 changed files with 192 additions and 144 deletions

View File

@ -3,9 +3,22 @@
#ifdef QT_CORE_LIB #ifdef QT_CORE_LIB
#include <QSemaphore>
tyepdef QSemaphore mt::Semaphore; #include <QThread.h>
#include <QMutex.h>
#include <QSemaphore.h>
namespace mt{
typedef QThread thread;
typedef QMutex mutex;
typedef QMutexLocker mutexlocker;
typedef QSemaphore semaphore;
//cache.h, token.h
//QAtomicInt
}//namespace
#else #else
@ -18,6 +31,9 @@ tyepdef QSemaphore mt::Semaphore;
#include "scoped_read_lock.h" #include "scoped_read_lock.h"
#include "scoped_write_lock.h" #include "scoped_write_lock.h"
namespace mt{
typedef scoped_mutex_lock mutexlocker;
}
#endif #endif
#endif // MT_MT_H #endif // MT_MT_H

View File

@ -25,6 +25,14 @@ class scoped_mutex_lock
this->mtx.unlock(); this->mtx.unlock();
} }
//jnoguera 14-12-2011
//method added to mime QMutexLocker
scoped_mutex_lock(mutex * m) : mtx( *m )
{
this->mtx.lock();
}
protected: protected:
mutex & mtx; mutex & mtx;

View File

@ -3,6 +3,7 @@
#include "base.h" #include "base.h"
#include <iostream>
#include <semaphore.h> #include <semaphore.h>
namespace mt namespace mt
@ -54,7 +55,30 @@ class semaphore
return (sem_trywait(&(this->s)) == 0); return (sem_trywait(&(this->s)) == 0);
} }
//jnoguera 11-Nov-2011 //methods added for conforming to the QT implementation
//jnoguera 14-12-2011
void release(int n=1)
{
if(n != 1)
std::cout << "Error, mt::semaphore.release() not supported\n";
sem_post(&(this->s));
}
void acquire(int n=1)
{
if(n != 1)
std::cout << "Error, mt::semaphore.tryAcquire() not supported\n";
sem_wait(&(this->s));
}
bool tryAcquire(int n=1)
{
if(n != 1)
std::cout << "Error, mt::semaphore.tryAcquire() not supported\n";
return (sem_trywait(&(this->s)) == 0);
}
int available() int available()
{ {
int value; int value;