tron@2285: /* $Id$ */ tron@2285: tron@2285: #ifndef THREAD_H tron@2285: #define THREAD_H tron@2285: rubidium@6574: struct OTTDThread; tron@2285: truelight@4298: typedef void* (*OTTDThreadFunc)(void*); tron@2285: truelight@4298: OTTDThread* OTTDCreateThread(OTTDThreadFunc, void*); truelight@4300: void* OTTDJoinThread(OTTDThread*); rubidium@6573: void OTTDExitThread(); tron@2285: KUDr@9514: KUDr@9514: /** KUDr@9514: * C++ thread wrapper interface KUDr@9514: */ KUDr@9514: struct ThreadObject { KUDr@9514: /** Virtual destructor to allow 'delete' operator to work properly. */ KUDr@9514: virtual ~ThreadObject() {}; KUDr@9514: /** Returns true if thread is running. */ KUDr@9514: virtual bool IsRunning() = 0; KUDr@9514: /** Waits for the thread exit. Returns true if thread exited. */ KUDr@9514: virtual bool WaitForStop() = 0; KUDr@9514: /** Returns true if this Thread Object belongs to the current (calling) thread. */ KUDr@9514: virtual bool IsCurrent() = 0; KUDr@9514: /** Returns thread id of the thread associated to this Thread Object. */ KUDr@9514: virtual uint Id() = 0; KUDr@9514: /** Begin thread execution by calling given procedure and passing given parameter to it. */ KUDr@9514: virtual bool Begin(void (CDECL *proc)(void*), void *param) = 0; KUDr@9514: /** Used to construct new instance of thread object. */ KUDr@9514: static ThreadObject* New(); KUDr@9514: /** Returns thread object instance that belongs to the current (calling) thread. */ KUDr@9514: static ThreadObject* Current(); KUDr@9514: /** Returns thread id of the current (calling) thread. */ KUDr@9514: static uint CurrentId(); KUDr@9514: }; KUDr@9514: KUDr@9514: /** KUDr@9514: * Event object that is signaled manually by Set() and reset automatically when thread passes Wait(). KUDr@9514: */ KUDr@9514: struct AutoResetEvent { KUDr@9514: /** Virtual destructor to allow 'delete' operator to work properly. */ KUDr@9514: virtual ~AutoResetEvent() {}; KUDr@9514: /** Set the event state to signaled so that one thread can pass the Wait() method. */ KUDr@9514: virtual void Set() = 0; KUDr@9514: /** Wait until event is signaled by calling Set() */ KUDr@9514: virtual void Wait() = 0; KUDr@9514: /** Used to construct new instance of event object. */ KUDr@9514: static AutoResetEvent* New(); KUDr@9514: }; KUDr@9514: KUDr@9514: Darkvater@2380: #endif /* THREAD_H */