equal
deleted
inserted
replaced
1 /* $Id$ */ |
1 /* $Id$ */ |
2 |
2 |
3 #include "stdafx.h" |
3 #include "stdafx.h" |
4 #include "thread.h" |
4 #include "thread.h" |
5 #include <stdlib.h> |
5 #include <stdlib.h> |
|
6 #include "helpers.hpp" |
6 |
7 |
7 #if defined(__AMIGA__) || defined(__MORPHOS__) || defined(NO_THREADS) |
8 #if defined(__AMIGA__) || defined(__MORPHOS__) || defined(NO_THREADS) |
8 OTTDThread *OTTDCreateThread(OTTDThreadFunc function, void *arg) { return NULL; } |
9 OTTDThread *OTTDCreateThread(OTTDThreadFunc function, void *arg) { return NULL; } |
9 void *OTTDJoinThread(OTTDThread *t) { return NULL; } |
10 void *OTTDJoinThread(OTTDThread *t) { return NULL; } |
10 void OTTDExitThread(void) { NOT_REACHED(); }; |
11 void OTTDExitThread(void) { NOT_REACHED(); }; |
22 void* ret; |
23 void* ret; |
23 }; |
24 }; |
24 |
25 |
25 static void Proxy(void* arg) |
26 static void Proxy(void* arg) |
26 { |
27 { |
27 OTTDThread* t = arg; |
28 OTTDThread* t = (OTTDThread*)arg; |
28 t->ret = t->func(t->arg); |
29 t->ret = t->func(t->arg); |
29 } |
30 } |
30 |
31 |
31 OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) |
32 OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) |
32 { |
33 { |
33 OTTDThread* t = malloc(sizeof(*t)); |
34 OTTDThread* t; |
|
35 MallocT(&t, 1); |
34 |
36 |
35 if (t == NULL) return NULL; |
37 if (t == NULL) return NULL; |
36 |
38 |
37 t->func = function; |
39 t->func = function; |
38 t->arg = arg; |
40 t->arg = arg; |
39 t->thread = _beginthread(Proxy, NULL, 32768, t); |
41 t->thread = _beginthread(Proxy, NULL, 32768, t); |
40 if (t->thread != -1) { |
42 if (t->thread != (TID)-1) { |
41 return t; |
43 return t; |
42 } else { |
44 } else { |
43 free(t); |
45 free(t); |
44 return NULL; |
46 return NULL; |
45 } |
47 } |
70 pthread_t thread; |
72 pthread_t thread; |
71 }; |
73 }; |
72 |
74 |
73 OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) |
75 OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) |
74 { |
76 { |
75 OTTDThread* t = malloc(sizeof(*t)); |
77 OTTDThread* t; |
|
78 MallocT(&t, 1); |
76 |
79 |
77 if (t == NULL) return NULL; |
80 if (t == NULL) return NULL; |
78 |
81 |
79 if (pthread_create(&t->thread, NULL, function, arg) == 0) { |
82 if (pthread_create(&t->thread, NULL, function, arg) == 0) { |
80 return t; |
83 return t; |
111 void* ret; |
114 void* ret; |
112 }; |
115 }; |
113 |
116 |
114 static DWORD WINAPI Proxy(LPVOID arg) |
117 static DWORD WINAPI Proxy(LPVOID arg) |
115 { |
118 { |
116 OTTDThread* t = arg; |
119 OTTDThread* t = (OTTDThread*)arg; |
117 t->ret = t->func(t->arg); |
120 t->ret = t->func(t->arg); |
118 return 0; |
121 return 0; |
119 } |
122 } |
120 |
123 |
121 OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) |
124 OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) |
122 { |
125 { |
123 OTTDThread* t = malloc(sizeof(*t)); |
126 OTTDThread* t; |
|
127 MallocT(&t, 1); |
124 DWORD dwThreadId; |
128 DWORD dwThreadId; |
125 |
129 |
126 if (t == NULL) return NULL; |
130 if (t == NULL) return NULL; |
127 |
131 |
128 t->func = function; |
132 t->func = function; |