2005-08-05 09:15:41 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file thread.h Base of all threads. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2005-08-05 09:15:41 +00:00
|
|
|
#ifndef THREAD_H
|
|
|
|
#define THREAD_H
|
|
|
|
|
2008-06-08 10:51:36 +00:00
|
|
|
typedef void (*OTTDThreadFunc)(void *);
|
2005-08-05 09:15:41 +00:00
|
|
|
|
2009-01-12 14:31:49 +00:00
|
|
|
class OTTDThreadExitSignal { };
|
|
|
|
|
2008-04-14 19:54:33 +00:00
|
|
|
/**
|
|
|
|
* A Thread Object which works on all our supported OSes.
|
|
|
|
*/
|
|
|
|
class ThreadObject {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Virtual destructor to allow 'delete' operator to work properly.
|
|
|
|
*/
|
|
|
|
virtual ~ThreadObject() {};
|
2005-08-05 09:15:41 +00:00
|
|
|
|
2008-04-14 19:54:33 +00:00
|
|
|
/**
|
|
|
|
* Exit this thread.
|
|
|
|
*/
|
|
|
|
virtual bool Exit() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Join this thread.
|
|
|
|
*/
|
2008-06-08 10:51:36 +00:00
|
|
|
virtual void Join() = 0;
|
2008-04-14 19:54:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a thread; proc will be called as first function inside the thread,
|
|
|
|
* with optinal params.
|
|
|
|
* @param proc The procedure to call inside the thread.
|
|
|
|
* @param param The params to give with 'proc'.
|
2009-01-20 03:12:46 +00:00
|
|
|
* @param thread Place to store a pointer to the thread in. May be NULL.
|
2008-04-14 19:54:33 +00:00
|
|
|
* @return True if the thread was started correctly.
|
|
|
|
*/
|
2009-01-20 03:12:46 +00:00
|
|
|
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL);
|
2008-04-14 19:54:33 +00:00
|
|
|
};
|
2005-08-05 09:15:41 +00:00
|
|
|
|
2009-01-20 03:44:43 +00:00
|
|
|
/**
|
|
|
|
* Cross-platform Mutex
|
|
|
|
*/
|
|
|
|
class ThreadMutex {
|
|
|
|
public:
|
|
|
|
static ThreadMutex *New();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual Destructor to avoid compiler warnings.
|
|
|
|
*/
|
|
|
|
virtual ~ThreadMutex() {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Begin the critical section
|
|
|
|
*/
|
|
|
|
virtual void BeginCritical() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* End of the critical section
|
|
|
|
*/
|
|
|
|
virtual void EndCritical() = 0;
|
|
|
|
};
|
|
|
|
|
2005-09-02 16:05:59 +00:00
|
|
|
#endif /* THREAD_H */
|