2011-09-27 17:48:46 +00:00
|
|
|
// This code is in the public domain -- castano@gmail.com
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef NV_THREAD_THREAD_H
|
|
|
|
#define NV_THREAD_THREAD_H
|
|
|
|
|
|
|
|
#include "nvthread.h"
|
|
|
|
|
|
|
|
#include "nvcore/Ptr.h"
|
|
|
|
|
|
|
|
namespace nv
|
|
|
|
{
|
|
|
|
typedef void ThreadFunc(void * arg);
|
|
|
|
|
2011-09-27 18:12:32 +00:00
|
|
|
class NVTHREAD_CLASS Thread
|
|
|
|
{
|
|
|
|
NV_FORBID_COPY(Thread);
|
|
|
|
public:
|
|
|
|
Thread();
|
|
|
|
~Thread();
|
2011-09-27 17:48:46 +00:00
|
|
|
|
2011-09-28 01:45:08 +00:00
|
|
|
void start(ThreadFunc * func, void * arg);
|
|
|
|
void wait();
|
2011-09-27 17:48:46 +00:00
|
|
|
|
2011-09-28 01:45:08 +00:00
|
|
|
bool isRunning() const;
|
2011-09-27 17:48:46 +00:00
|
|
|
|
2011-09-28 01:45:08 +00:00
|
|
|
static void spinWait(uint count);
|
|
|
|
static void yield();
|
|
|
|
static void sleep(uint ms);
|
2011-09-27 17:48:46 +00:00
|
|
|
|
2011-09-28 01:45:08 +00:00
|
|
|
static void wait(Thread * threads, uint count);
|
2011-09-27 17:48:46 +00:00
|
|
|
|
2011-09-27 18:12:32 +00:00
|
|
|
private:
|
|
|
|
|
2011-09-28 01:45:08 +00:00
|
|
|
struct Private;
|
|
|
|
AutoPtr<Private> p;
|
2011-09-27 18:12:32 +00:00
|
|
|
|
|
|
|
public: // @@ Why public? Also in private?!
|
2011-09-27 17:48:46 +00:00
|
|
|
ThreadFunc * func;
|
|
|
|
void * arg;
|
|
|
|
|
2011-09-27 18:12:32 +00:00
|
|
|
};
|
2011-09-27 17:48:46 +00:00
|
|
|
|
|
|
|
} // nv namespace
|
|
|
|
|
|
|
|
#endif // NV_THREAD_THREAD_H
|