25 #define TY_AUTO_MUTEX_NAME _mutex
28 #ifndef QT_THREAD_SUPPORT
29 #define QT_THREAD_SUPPORT 1
33 #include <QWaitCondition>
43 static void sleep(
unsigned long secs)
45 return QThread::sleep(secs);
47 static void msleep(
unsigned long msecs)
49 return QThread::msleep(msecs);
51 static void usleep(
unsigned long usecs)
53 return QThread::usleep(usecs);
58 #define TY_AUTO_MUTEX mutable QMutex TY_AUTO_MUTEX_NAME;
59 #define TY_LOCK_AUTO_MUTEX TY_AUTO_MUTEX_NAME.lock();
60 #define TY_UNLOCK_AUTO_MUTEX TY_AUTO_MUTEX_NAME.unlock();
61 #define TY_OMUTEXLOCKER_AUTO_MUTEX OMutexLocker locker(TY_AUTO_MUTEX_NAME);
63 #define TY_MUTEX(name) mutable QMutex name;
64 #define TY_LOCK_MUTEX(name) name.lock();
65 #define TY_UNLOCK_MUTEX(name) name.unlock();
66 #define TY_OMUTEXLOCKER_MUTEX(name) OMutexLocker locker(name);
68 #define TY_STATIC_MUTEX(name) static QMutex name;
69 #define TY_STATIC_MUTEX_INSTANCE(name) QMutex name;
71 #define TY_AUTO_SHARED_MUTEX mutable QMutex* TY_AUTO_MUTEX_NAME;
72 #define TY_NEW_AUTO_SHARED_MUTEX TY_AUTO_MUTEX_NAME = new QMutex();
73 #define TY_DELETE_AUTO_SHARED_MUTEX delete TY_AUTO_MUTEX_NAME;
74 #define TY_LOCK_AUTO_SHARED_MUTEX TY_AUTO_MUTEX_NAME->lock();
75 #define TY_UNLOCK_AUTO_SHARED_MUTEX TY_AUTO_MUTEX_NAME->unlock();
76 #define TY_OMUTEXLOCKER_AUTO_SHARED_MUTEX OMutexLocker locker(*TY_AUTO_MUTEX_NAME);
78 #define TY_SHARED_MUTEX(name) mutable QMutex* name;
79 #define TY_NEW_SHARED_MUTEX(name) name = new QMutex();
80 #define TY_DELETE_SHARED_MUTEX(name) delete name;
81 #define TY_LOCK_SHARED_MUTEX(name) name->lock();
82 #define TY_UNLOCK_SHARED_MUTEX(name) name->unlock();
83 #define TY_OMUTEXLOCKER_SHARED_MUTEX(name) OMutexLocker locker(*name);
114 _mutex =
const_cast<QMutex*
>(&mutex);
167 class OTask :
public IRefCount,
public QWaitCondition,
public QMutex
258 class OThreadPool :
public std::vector<OSlaveThread*>,
public QWaitCondition,
public QMutex
304 std::queue<LPOTask>
_tasks;
SmartPtr< OTask > LPOTask
Smart Pointer sur OTask.
#define TY_LOCK_SHARED_MUTEX(name)
#define TY_UNLOCK_SHARED_MUTEX(name)
Class used as RAII object (Resource Acquisition Is Initialization)
~OMutexLocker()
Destructor.
OMutexLocker(QMutex &mutex)
Constructors.
OMutexLocker(const QMutex &mutex)
This class defines a thread for running tasks in a threads collection. Slave thread for the threads c...
~OSlaveThread()
Destroy the slave thread; wait for the end of the thread.
OSlaveThread(OThreadPool *pool)
Build a slave thread for a threads collection.
OThreadPool * _pool
Pointer on the parent threads collection.
Access to sleep protected methods of the QThread class.
static void usleep(unsigned long usecs)
static void msleep(unsigned long msecs)
static void sleep(unsigned long secs)
Task of a threads collection.
virtual ~OTask()
Destructor : waits for the end of the task to destroy it.
bool _running
Running flag.
bool _completed
Completed flag.
OTask()
Default constructor.
bool _canceled
Cancel flag.
Slave threads collection.
unsigned int _totalCount
Total number of tasks to run.
unsigned int getTotalCount() const
void begin(unsigned int count)
OThreadPool(unsigned int slaves)
Build a threads collection and allocate "slaves" thread.
unsigned int _counter
Total number of ended tasks.
virtual void push(OTask *task)
std::queue< LPOTask > _tasks
Tasks queue.
unsigned int getCount() const
void stop()
Cancel the pending tasks.
virtual ~OThreadPool()
Destructor.