thread_os2.cpp
Go to the documentation of this file.00001
00002
00005 #include "stdafx.h"
00006 #include "thread.h"
00007
00008 #if 0
00009 #include "debug.h"
00010 #include "core/alloc_func.hpp"
00011 #include <stdlib.h>
00012
00013 #define INCL_DOS
00014 #include <os2.h>
00015 #include <process.h>
00016
00017 struct OTTDThread {
00018 TID thread;
00019 OTTDThreadFunc func;
00020 void *arg;
00021 void *ret;
00022 };
00023
00024 static void Proxy(void *arg)
00025 {
00026 OTTDThread *t = (OTTDThread *)arg;
00027 t->ret = t->func(t->arg);
00028 }
00029
00030 OTTDThread *OTTDCreateThread(OTTDThreadFunc function, void *arg)
00031 {
00032 OTTDThread *t = MallocT<OTTDThread>(1);
00033
00034 t->func = function;
00035 t->arg = arg;
00036 t->thread = _beginthread(Proxy, NULL, 32768, t);
00037 if (t->thread != (TID)-1) {
00038 return t;
00039 } else {
00040 free(t);
00041 return NULL;
00042 }
00043 }
00044
00045 void *OTTDJoinThread(OTTDThread *t)
00046 {
00047 if (t == NULL) return NULL;
00048
00049 DosWaitThread(&t->thread, DCWW_WAIT);
00050 void *ret = t->ret;
00051 free(t);
00052 return ret;
00053 }
00054
00055 void OTTDExitThread()
00056 {
00057 _endthread();
00058 }
00059
00060 #endif
00061
00062 ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
00063 {
00064 if (thread != NULL) *thread = NULL;
00065 return false;
00066 }