src/thread.h
author glx
Sun, 08 Apr 2007 14:46:55 +0000
branchnoai
changeset 9574 698395509d12
parent 9514 e31710af1ca0
child 9694 e72987579514
permissions -rw-r--r--
(svn r9575) [NoAI] -Sync with trunk r9504:9574
/* $Id$ */

/** @file thread.h */

#ifndef THREAD_H
#define THREAD_H

struct OTTDThread;

typedef void* (*OTTDThreadFunc)(void*);

OTTDThread* OTTDCreateThread(OTTDThreadFunc, void*);
void*       OTTDJoinThread(OTTDThread*);
void        OTTDExitThread();


/**
 * C++ thread wrapper interface
 */
struct ThreadObject {
	/** Virtual destructor to allow 'delete' operator to work properly. */
	virtual ~ThreadObject() {};
	/** Returns true if thread is running. */
	virtual bool IsRunning() = 0;
	/** Waits for the thread exit. Returns true if thread exited. */
	virtual bool WaitForStop() = 0;
	/** Returns true if this Thread Object belongs to the current (calling) thread. */
	virtual bool IsCurrent() = 0;
	/** Returns thread id of the thread associated to this Thread Object. */
	virtual uint Id() = 0;
	/** Begin thread execution by calling given procedure and passing given parameter to it. */
	virtual bool Begin(void (CDECL *proc)(void*), void *param) = 0;
	/** Used to construct new instance of thread object. */
	static ThreadObject* New();
	/** Returns thread object instance that belongs to the current (calling) thread. */
	static ThreadObject* Current();
	/** Returns thread id of the current (calling) thread. */
	static uint CurrentId();
};

/**
 * Event object that is signaled manually by Set() and reset automatically when thread passes Wait().
 */
struct AutoResetEvent {
	/** Virtual destructor to allow 'delete' operator to work properly. */
	virtual ~AutoResetEvent() {};
	/** Set the event state to signaled so that one thread can pass the Wait() method. */
	virtual void Set() = 0;
	/** Wait until event is signaled by calling Set() */
	virtual void Wait() = 0;
	/** Used to construct new instance of event object. */
	static AutoResetEvent* New();
};


#endif /* THREAD_H */