/*
* Thread.h
* Rocket_Man
*
* Created by John Ryland on 29/06/09.
* Copyright 2009 InvertedLogic. All rights reserved.
*
*/
#ifndef THREAD_H
#define THREAD_H
#include <stdint.h>
#include <pthread.h>
class Thread
{
public:
#define OpenALThread_SET_PRIORITY 0
#define OpenALThread_SCHEDULED_PRIORITY 1
typedef void *(*ThreadRoutine)(void* inParameter);
enum
{
kMinThreadPriority = 1,
kMaxThreadPriority = 63,
kDefaultThreadPriority = 31
};
Thread(ThreadRoutine inThreadRoutine, void* inParameter);
~Thread();
bool isRunning() const;
void setAutoDelete(bool b);
void setPriority(uint32_t inPriority, bool inFixedPriority);
void start();
protected:
static void *entry(Thread *thread);
static uint32_t getScheduledPriority(pthread_t inThread, int inPriorityKind);
pthread_t mPThread;
uint32_t mSpawningThreadPriority;
ThreadRoutine mThreadRoutine;
void* mThreadParameter;
int32_t mPriority;
bool mFixedPriority;
bool mAutoDelete; // delete self when thread terminates
};
#endif // THREAD_H