src/thread_os2.cpp
author truebrain
Mon, 16 Jun 2008 14:43:19 +0000
branchnoai
changeset 10978 13fd0364b2c6
parent 10172 f93d3b7df6c8
permissions -rw-r--r--
(svn r13532) [NoAI] -Fix: in MultiPlayer SignID wasn't set correctly, causing weird effects. Code is now more unified, which should avoid simular effects in the future (tnx to glx for initial patch)
9857
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
     1
/* $Id$ */
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
     2
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
     3
/** @file thread_os2.cpp OS2 implementation of Threads. */
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
     4
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
     5
#include "stdafx.h"
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
     6
#include "thread.h"
10172
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
     7
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
     8
#if 0
9857
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
     9
#include "debug.h"
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    10
#include "core/alloc_func.hpp"
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    11
#include <stdlib.h>
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    12
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    13
#define INCL_DOS
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    14
#include <os2.h>
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    15
#include <process.h>
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    16
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    17
struct OTTDThread {
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    18
	TID thread;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    19
	OTTDThreadFunc func;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    20
	void *arg;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    21
	void *ret;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    22
};
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    23
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    24
static void Proxy(void *arg)
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    25
{
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    26
	OTTDThread *t = (OTTDThread *)arg;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    27
	t->ret = t->func(t->arg);
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    28
}
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    29
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    30
OTTDThread *OTTDCreateThread(OTTDThreadFunc function, void *arg)
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    31
{
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    32
	OTTDThread *t = MallocT<OTTDThread>(1);
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    33
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    34
	t->func = function;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    35
	t->arg  = arg;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    36
	t->thread = _beginthread(Proxy, NULL, 32768, t);
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    37
	if (t->thread != (TID)-1) {
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    38
		return t;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    39
	} else {
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    40
		free(t);
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    41
		return NULL;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    42
	}
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    43
}
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    44
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    45
void *OTTDJoinThread(OTTDThread *t)
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    46
{
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    47
	if (t == NULL) return NULL;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    48
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    49
	DosWaitThread(&t->thread, DCWW_WAIT);
10171
d4397d599d78 (svn r12702) [NoAI] -Codechange: some coding style cleanups.
rubidium
parents: 9857
diff changeset
    50
	void *ret = t->ret;
9857
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    51
	free(t);
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    52
	return ret;
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    53
}
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    54
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    55
void OTTDExitThread()
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    56
{
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    57
	_endthread();
7adb6a846add (svn r12529) [NoAI] -Change: split thread.cpp into 4 files, one for each OS
truebrain
parents:
diff changeset
    58
}
10172
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    59
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    60
#endif
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    61
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    62
/* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param)
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    63
{
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    64
	return NULL;
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    65
}
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    66
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    67
/* static */ ThreadObject *ThreadObject::AttachCurrent()
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    68
{
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    69
	return NULL;
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    70
}
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    71
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    72
/* static */ uint ThreadObject::CurrentId()
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    73
{
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    74
	return -1;
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    75
}
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    76
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    77
/* static */ ThreadSemaphore *ThreadSemaphore::New()
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    78
{
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    79
	return NULL;
f93d3b7df6c8 (svn r12703) [NoAI] -Codechange: move the remaining thread functions to use the new thread infrastructure.
rubidium
parents: 10171
diff changeset
    80
}