Danbias/Code/Misc/Thread/OysterThread.h

94 lines
2.6 KiB
C
Raw Normal View History

2013-11-26 21:51:40 +01:00
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef MISC_OYSTER_THREAD_H
#define MISC_OYSTER_THREAD_H
#include "IThreadObject.h"
2014-01-07 10:26:09 +01:00
namespace Oyster
{
namespace Thread
{
2014-01-07 10:26:09 +01:00
/**
* Inherit this class to get threading compatibility.
*/
class IThreadObject
{
public:
/**
* Override this to get notified when the thread is started.
*/
virtual void ThreadEntry() { }
/**
* Override this to get notified when the thread is about to exit.
*/
virtual void ThreadExit() { }
/**
* This function is required to get threading working.
* Note that this function is NOT thread safe.
* OBS! Do not highjack the looping.
*/
virtual bool DoWork ( ) = 0;
};
typedef bool (*ThreadFnc)(void);
enum OYSTER_THREAD_ERROR
{
OYSTER_THREAD_ERROR_SUCCESS,
2013-12-19 12:32:23 +01:00
OYSTER_THREAD_ERROR_ThreadAlreadyCreated,
OYSTER_THREAD_ERROR_ThreadCreationFailed,
OYSTER_THREAD_ERROR_ThreadNotCreated,
OYSTER_THREAD_ERROR_ThreadHasNoWorker,
OYSTER_THREAD_ERROR_ThreadCannotWaintOnItselfe,
OYSTER_THREAD_ERROR_ThreadCannotBeWaitedOn,
OYSTER_THREAD_ERROR_ThreadIsDead,
OYSTER_THREAD_ERROR_FAILED,
};
2013-12-13 23:47:16 +01:00
enum OYSTER_THREAD_PRIORITY
{
OYSTER_THREAD_PRIORITY_1, //!< High
OYSTER_THREAD_PRIORITY_2, //!< Medium
OYSTER_THREAD_PRIORITY_3, //!< Low
};
class OysterThread
{
private:
struct PrivateData;
PrivateData *privateData;
public:
OysterThread();
2013-11-27 21:47:32 +01:00
OysterThread(const OysterThread& original);
const OysterThread& operator=(const OysterThread& original);
virtual~OysterThread();
2013-12-19 12:32:23 +01:00
OYSTER_THREAD_ERROR Create(IThreadObject* worker, bool start, bool detach = false);
2014-01-07 10:26:09 +01:00
OYSTER_THREAD_ERROR Create(ThreadFnc worker, bool start, bool detach = false);
//OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackObject<bool, void>* worker, bool start, bool detach = false);
//OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackFunction<bool, void>::FNC worker, bool start, bool detach = false);
OYSTER_THREAD_ERROR Start();
OYSTER_THREAD_ERROR Stop();
2013-12-19 12:32:23 +01:00
OYSTER_THREAD_ERROR Pause();
OYSTER_THREAD_ERROR Pause(int mSec);
OYSTER_THREAD_ERROR Resume();
2014-01-07 10:26:09 +01:00
OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0);
OYSTER_THREAD_ERROR SetWorker(ThreadFnc worker = 0);
OYSTER_THREAD_ERROR Terminate();
2013-12-19 12:32:23 +01:00
OYSTER_THREAD_ERROR Wait();
OYSTER_THREAD_ERROR Wait(int mSec);
OYSTER_THREAD_ERROR Swap(const OysterThread* other);
2013-12-19 12:32:23 +01:00
void SetPriority(OYSTER_THREAD_PRIORITY priority);
bool IsActive();
bool IsCreated() const;
2013-12-19 12:32:23 +01:00
};
}
}
2013-11-26 21:51:40 +01:00
#endif // !MISC_OYSTER_THREAD_H