2013-10-20 12:53:53 +00:00
|
|
|
#ifndef THREAD_H
|
|
|
|
#define THREAD_H
|
|
|
|
|
|
|
|
#include "system_global.h"
|
|
|
|
|
|
|
|
typedef void* (*ThreadFunction)(void* data);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
namespace paysages
|
|
|
|
{
|
|
|
|
namespace system
|
|
|
|
{
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief System thread
|
|
|
|
*/
|
2013-10-20 13:24:58 +00:00
|
|
|
class SYSTEMSHARED_EXPORT Thread: private QThread
|
2013-10-20 12:53:53 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
* \brief Create a new thread
|
|
|
|
* \param function Function to call inside the thread once it is started
|
|
|
|
*
|
|
|
|
* The thread is not started automatically. A call to method start() needs to be done.
|
|
|
|
*/
|
|
|
|
Thread(ThreadFunction function);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Start the thread
|
|
|
|
* \param data User data to pass to the threaded function
|
|
|
|
*/
|
|
|
|
void start(void* data);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Wait for the thread to end, and collect its result.
|
|
|
|
* \return The value returned by the threaded function.
|
|
|
|
*/
|
|
|
|
void* join();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ThreadFunction function;
|
|
|
|
void* data;
|
|
|
|
void* result;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Transitional C-API
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
typedef struct Thread Thread;
|
|
|
|
#endif
|
|
|
|
|
2013-10-20 13:24:58 +00:00
|
|
|
SYSTEMSHARED_EXPORT Thread* threadCreate(ThreadFunction function, void* data);
|
|
|
|
SYSTEMSHARED_EXPORT void* threadJoin(Thread* thread);
|
2013-10-20 12:53:53 +00:00
|
|
|
|
2013-10-20 13:24:58 +00:00
|
|
|
SYSTEMSHARED_EXPORT void timeSleepMs(unsigned long ms);
|
2013-10-20 13:07:12 +00:00
|
|
|
|
2013-10-20 12:53:53 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // THREAD_H
|