1
/* $Id: thread_os2.cpp 15764 2009-03-18 19:47:05Z rubidium $ */
3
/** @file thread_os2.cpp OS/2 implementation of Threads. */
13
* OS/2 version for ThreadObject.
15
class ThreadObject_OS2 : public ThreadObject {
17
TID thread; ///< System thread identifier.
18
OTTDThreadFunc proc; ///< External thread procedure.
19
void *param; ///< Parameter for the external thread procedure.
20
bool self_destruct; ///< Free ourselves when done?
24
* Create a thread and start it, calling proc(param).
26
ThreadObject_OS2(OTTDThreadFunc proc, void *param, bool self_destruct) :
30
self_destruct(self_destruct)
32
thread = _beginthread(stThreadProc, NULL, 32768, this);
35
/* virtual */ bool Exit()
41
/* virtual */ void Join()
43
DosWaitThread(&this->thread, DCWW_WAIT);
48
* On thread creation, this function is called, which calls the real startup
49
* function. This to get back into the correct instance again.
51
static void stThreadProc(void *thr)
53
((ThreadObject_OS2 *)thr)->ThreadProc();
57
* A new thread is created, and this function is called. Call the custom
58
* function of the creator of the thread.
62
/* Call the proc of the creator to continue this thread */
64
this->proc(this->param);
65
} catch (OTTDThreadExitSignal e) {
77
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
79
ThreadObject *to = new ThreadObject_OS2(proc, param, thread == NULL);
80
if (thread != NULL) *thread = to;
85
* OS/2 version of ThreadMutex.
87
class ThreadMutex_OS2 : public ThreadMutex {
94
DosCreateMutexSem(NULL, &mutex, 0, FALSE);
97
/* virtual */ ~ThreadMutex_OS2()
99
DosCloseMutexSem(mutex);
102
/* virtual */ void BeginCritical()
104
DosRequestMutexSem(mutex, (unsigned long) SEM_INDEFINITE_WAIT);
107
/* virtual */ void EndCritical()
109
DosReleaseMutexSem(mutex);
113
/* static */ ThreadMutex *ThreadMutex::New()
115
return new ThreadMutex_OS2();