Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 518 lines (438 sloc) 10.961 kb
a3e1b1c @ko1 * Merge YARV
ko1 authored
1 /* -*-c-*- */
2 /**********************************************************************
3
c334a09 @ko1 * common.mk, *.ci: renamed to *.c.
ko1 authored
4 thread_win32.c -
a3e1b1c @ko1 * Merge YARV
ko1 authored
5
6 $Author$
7 $Date$
8
d907cbc @ko1 * blockinlining.c, compile.c, compile.h, debug.c, debug.h,
ko1 authored
9 Copyright (C) 2004-2007 Koichi Sasada
a3e1b1c @ko1 * Merge YARV
ko1 authored
10
11 **********************************************************************/
12
13 #ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
14
15 #include <process.h>
16
17 #define WIN32_WAIT_TIMEOUT 10 /* 10 ms */
18 #undef Sleep
19
20 #define native_thread_yield() Sleep(0)
ae317b5 @ko1 * yarvcore.h, thread.c: fix to use pthread on cygwin.
ko1 authored
21 #define remove_signal_thread_list(th)
a3e1b1c @ko1 * Merge YARV
ko1 authored
22
6fc746d @nobu * thread.c (is_ruby_native_thread): check properly. [ruby-dev:31166]
nobu authored
23 static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
24
25 static rb_thread_t *
26 ruby_thread_from_native(void)
27 {
28 return TlsGetValue(ruby_native_thread_key);
29 }
30
31 static int
32 ruby_thread_set_native(rb_thread_t *th)
33 {
34 return TlsSetValue(ruby_native_thread_key, th);
35 }
36
a3e1b1c @ko1 * Merge YARV
ko1 authored
37 static void
6fc746d @nobu * thread.c (is_ruby_native_thread): check properly. [ruby-dev:31166]
nobu authored
38 Init_native_thread(void)
a3e1b1c @ko1 * Merge YARV
ko1 authored
39 {
9c57438 @ko1 * blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
ko1 authored
40 rb_thread_t *th = GET_THREAD();
6fc746d @nobu * thread.c (is_ruby_native_thread): check properly. [ruby-dev:31166]
nobu authored
41
42 ruby_native_thread_key = TlsAlloc();
a3e1b1c @ko1 * Merge YARV
ko1 authored
43 DuplicateHandle(GetCurrentProcess(),
44 GetCurrentThread(),
45 GetCurrentProcess(),
46 &th->thread_id, 0, FALSE, DUPLICATE_SAME_ACCESS);
47
48 th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
49
50 thread_debug("initial thread (th: %p, thid: %p, event: %p)\n",
51 th, GET_THREAD()->thread_id,
52 th->native_thread_data.interrupt_event);
53 }
54
55 static void
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
56 w32_error(void)
a3e1b1c @ko1 * Merge YARV
ko1 authored
57 {
58 LPVOID lpMsgBuf;
59 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
60 FORMAT_MESSAGE_FROM_SYSTEM |
61 FORMAT_MESSAGE_IGNORE_INSERTS,
62 NULL,
63 GetLastError(),
64 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
65 (LPTSTR) & lpMsgBuf, 0, NULL);
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
66 rb_bug("%s", lpMsgBuf);
67 }
68
69 static void
70 w32_set_event(HANDLE handle)
71 {
72 if (SetEvent(handle) == 0) {
73 w32_error();
74 }
75 }
76
77 static void
78 w32_reset_event(HANDLE handle)
79 {
80 if (ResetEvent(handle) == 0) {
81 w32_error();
82 }
a3e1b1c @ko1 * Merge YARV
ko1 authored
83 }
84
85 static int
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
86 w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th)
a3e1b1c @ko1 * Merge YARV
ko1 authored
87 {
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
88 HANDLE *targets = events;
00f60d0 @unak * thread_win32.ci (w32_wait_events): check whether interrupt_event is
unak authored
89 HANDLE intr;
a3e1b1c @ko1 * Merge YARV
ko1 authored
90 DWORD ret;
91
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
92 thread_debug(" w32_wait_events events:%p, count:%d, timeout:%ld, th:%p\n",
93 events, count, timeout, th);
00f60d0 @unak * thread_win32.ci (w32_wait_events): check whether interrupt_event is
unak authored
94 if (th && (intr = th->native_thread_data.interrupt_event)) {
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
95 w32_reset_event(intr);
a3e1b1c @ko1 * Merge YARV
ko1 authored
96 if (th->interrupt_flag) {
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
97 w32_set_event(intr);
a3e1b1c @ko1 * Merge YARV
ko1 authored
98 }
99
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
100 targets = ALLOCA_N(HANDLE, count + 1);
101 memcpy(targets, events, sizeof(HANDLE) * count);
102
103 targets[count++] = intr;
a3e1b1c @ko1 * Merge YARV
ko1 authored
104 thread_debug(" * handle: %p (count: %d, intr)\n", intr, count);
105 }
106
107 thread_debug(" WaitForMultipleObjects start (count: %d)\n", count);
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
108 ret = WaitForMultipleObjects(count, targets, FALSE, timeout);
a3e1b1c @ko1 * Merge YARV
ko1 authored
109 thread_debug(" WaitForMultipleObjects end (ret: %d)\n", ret);
110
111 if (ret == WAIT_OBJECT_0 + count - 1 && th) {
112 errno = EINTR;
113 }
114 if (ret == -1 && THREAD_DEBUG) {
115 int i;
116 DWORD dmy;
117 for (i = 0; i < count; i++) {
118 thread_debug(" * error handle %d - %s\n", i,
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
119 GetHandleInformation(targets[i], &dmy) ? "OK" : "NG");
a3e1b1c @ko1 * Merge YARV
ko1 authored
120 }
121 }
122 return ret;
123 }
124
3453b2b @ko1 * gc.h, vm_core.h: decl of rb_gc_save_machine_context()
ko1 authored
125 static void ubf_handle(void *ptr);
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
126 #define ubf_select ubf_handle
127
128 int
c034fce @nobu * process.c (rb_waitpid_blocking, rb_waitpid): use UBF feature.
nobu authored
129 rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
130 {
131 return w32_wait_events(events, num, timeout, GET_THREAD());
132 }
133
134 int
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
135 rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
136 {
137 int ret;
138
3453b2b @ko1 * gc.h, vm_core.h: decl of rb_gc_save_machine_context()
ko1 authored
139 BLOCKING_REGION(ret = rb_w32_wait_events_blocking(events, num, timeout),
140 ubf_handle, GET_THREAD());
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
141 return ret;
142 }
143
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
144 static void
145 w32_close_handle(HANDLE handle)
146 {
147 if (CloseHandle(handle) == 0) {
148 w32_error();
149 }
150 }
151
152 static void
153 w32_resume_thread(HANDLE handle)
154 {
155 if (ResumeThread(handle) == -1) {
156 w32_error();
157 }
158 }
159
2840fa6 @nobu * common.mk: inverted rules order.
nobu authored
160 #ifdef _MSC_VER
161 #define HAVE__BEGINTHREADEX 1
162 #else
163 #undef HAVE__BEGINTHREADEX
164 #endif
165
166 #ifdef HAVE__BEGINTHREADEX
167 #define start_thread (HANDLE)_beginthreadex
168 typedef unsigned long (_stdcall *w32_thread_start_func)(void*);
169 #else
170 #define start_thread CreateThread
171 typedef LPTHREAD_START_ROUTINE w32_thread_start_func;
172 #endif
173
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
174 static HANDLE
2840fa6 @nobu * common.mk: inverted rules order.
nobu authored
175 w32_create_thread(DWORD stack_size, w32_thread_start_func func, void *val)
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
176 {
2840fa6 @nobu * common.mk: inverted rules order.
nobu authored
177 return start_thread(0, stack_size, func, val, CREATE_SUSPENDED, 0);
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
178 }
179
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
180 int
181 rb_w32_sleep(unsigned long msec)
182 {
183 return w32_wait_events(0, 0, msec, GET_THREAD());
184 }
185
186 int WINAPI
187 rb_w32_Sleep(unsigned long msec)
188 {
189 int ret;
190
3453b2b @ko1 * gc.h, vm_core.h: decl of rb_gc_save_machine_context()
ko1 authored
191 BLOCKING_REGION(ret = rb_w32_sleep(msec),
192 ubf_handle, GET_THREAD());
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
193 return ret;
194 }
ae317b5 @ko1 * yarvcore.h, thread.c: fix to use pthread on cygwin.
ko1 authored
195
a3e1b1c @ko1 * Merge YARV
ko1 authored
196 static void
9c57438 @ko1 * blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
ko1 authored
197 native_sleep(rb_thread_t *th, struct timeval *tv)
a3e1b1c @ko1 * Merge YARV
ko1 authored
198 {
199 DWORD msec;
200 if (tv) {
201 msec = tv->tv_sec * 1000 + tv->tv_usec / 1000;
202 }
203 else {
204 msec = INFINITE;
205 }
206
207 GVL_UNLOCK_BEGIN();
208 {
209 DWORD ret;
210 int status = th->status;
5f0b8af @ko1 * vm_core.h, thread.c, cont.c: add RUBY_VM_SET_INTERRUPT(),
ko1 authored
211
a3e1b1c @ko1 * Merge YARV
ko1 authored
212 th->status = THREAD_STOPPED;
ae317b5 @ko1 * yarvcore.h, thread.c: fix to use pthread on cygwin.
ko1 authored
213 th->unblock_function = ubf_handle;
3453b2b @ko1 * gc.h, vm_core.h: decl of rb_gc_save_machine_context()
ko1 authored
214 th->unblock_function_arg = th;
5f0b8af @ko1 * vm_core.h, thread.c, cont.c: add RUBY_VM_SET_INTERRUPT(),
ko1 authored
215
216 if (RUBY_VM_INTERRUPTED(th)) {
217 /* interrupted. return immediate */
218 }
219 else {
220 thread_debug("native_sleep start (%d)\n", (int)msec);
221 ret = w32_wait_events(0, 0, msec, th);
222 thread_debug("native_sleep done (%d)\n", ret);
223 }
224
ae317b5 @ko1 * yarvcore.h, thread.c: fix to use pthread on cygwin.
ko1 authored
225 th->unblock_function = 0;
3453b2b @ko1 * gc.h, vm_core.h: decl of rb_gc_save_machine_context()
ko1 authored
226 th->unblock_function_arg = 0;
a3e1b1c @ko1 * Merge YARV
ko1 authored
227 th->status = status;
228 }
229 GVL_UNLOCK_END();
5f0b8af @ko1 * vm_core.h, thread.c, cont.c: add RUBY_VM_SET_INTERRUPT(),
ko1 authored
230 RUBY_VM_CHECK_INTS();
a3e1b1c @ko1 * Merge YARV
ko1 authored
231 }
232
233 int
8ee7d07 @ko1 * blockinlining.c, compile.c, compile.h, error.c, eval.c,
ko1 authored
234 native_mutex_lock(rb_thread_lock_t *lock)
a3e1b1c @ko1 * Merge YARV
ko1 authored
235 {
236 #if USE_WIN32_MUTEX
237 DWORD result;
238 while (1) {
239 thread_debug("native_mutex_lock: %p\n", *lock);
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
240 result = w32_wait_events(&*lock, 1, INFINITE, 0);
a3e1b1c @ko1 * Merge YARV
ko1 authored
241 switch (result) {
99d65b1 @nobu * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
nobu authored
242 case WAIT_OBJECT_0:
a3e1b1c @ko1 * Merge YARV
ko1 authored
243 /* get mutex object */
244 thread_debug("acquire mutex: %p\n", *lock);
245 return 0;
99d65b1 @nobu * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
nobu authored
246 case WAIT_OBJECT_0 + 1:
a3e1b1c @ko1 * Merge YARV
ko1 authored
247 /* interrupt */
248 errno = EINTR;
249 thread_debug("acquire mutex interrupted: %p\n", *lock);
250 return 0;
99d65b1 @nobu * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
nobu authored
251 case WAIT_TIMEOUT:
a3e1b1c @ko1 * Merge YARV
ko1 authored
252 thread_debug("timeout mutex: %p\n", *lock);
253 break;
99d65b1 @nobu * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
nobu authored
254 case WAIT_ABANDONED:
a3e1b1c @ko1 * Merge YARV
ko1 authored
255 rb_bug("win32_mutex_lock: WAIT_ABANDONED");
256 break;
99d65b1 @nobu * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
nobu authored
257 default:
a3e1b1c @ko1 * Merge YARV
ko1 authored
258 rb_bug("win32_mutex_lock: unknown result (%d)", result);
259 break;
260 }
261 }
262 return 0;
263 #else
264 EnterCriticalSection(lock);
265 return 0;
266 #endif
267 }
268
269 int
8ee7d07 @ko1 * blockinlining.c, compile.c, compile.h, error.c, eval.c,
ko1 authored
270 native_mutex_unlock(rb_thread_lock_t *lock)
a3e1b1c @ko1 * Merge YARV
ko1 authored
271 {
272 #if USE_WIN32_MUTEX
273 thread_debug("release mutex: %p\n", *lock);
274 return ReleaseMutex(*lock);
275 #else
276 LeaveCriticalSection(lock);
277 return 0;
278 #endif
279 }
280
281 int
8ee7d07 @ko1 * blockinlining.c, compile.c, compile.h, error.c, eval.c,
ko1 authored
282 native_mutex_trylock(rb_thread_lock_t *lock)
a3e1b1c @ko1 * Merge YARV
ko1 authored
283 {
35eb542 @nobu * thread_win32.ci: fixed typo.
nobu authored
284 #if USE_WIN32_MUTEX
a3e1b1c @ko1 * Merge YARV
ko1 authored
285 int result;
286 thread_debug("native_mutex_trylock: %p\n", *lock);
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
287 result = w32_wait_events(&*lock, 1, 1, 0);
a3e1b1c @ko1 * Merge YARV
ko1 authored
288 thread_debug("native_mutex_trylock result: %d\n", result);
289 switch (result) {
99d65b1 @nobu * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
nobu authored
290 case WAIT_OBJECT_0:
a3e1b1c @ko1 * Merge YARV
ko1 authored
291 return 0;
99d65b1 @nobu * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
nobu authored
292 case WAIT_TIMEOUT:
a3e1b1c @ko1 * Merge YARV
ko1 authored
293 return EBUSY;
294 }
295 return EINVAL;
296 #else
297 return TryEnterCriticalSection(lock) == 0;
298 #endif
299 }
300
301 void
8ee7d07 @ko1 * blockinlining.c, compile.c, compile.h, error.c, eval.c,
ko1 authored
302 native_mutex_initialize(rb_thread_lock_t *lock)
a3e1b1c @ko1 * Merge YARV
ko1 authored
303 {
35eb542 @nobu * thread_win32.ci: fixed typo.
nobu authored
304 #if USE_WIN32_MUTEX
a3e1b1c @ko1 * Merge YARV
ko1 authored
305 *lock = CreateMutex(NULL, FALSE, NULL);
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
306 if (*lock == NULL) {
307 w32_error();
308 }
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
309 /* thread_debug("initialize mutex: %p\n", *lock); */
a3e1b1c @ko1 * Merge YARV
ko1 authored
310 #else
311 InitializeCriticalSection(lock);
312 #endif
313 }
314
a902624 @ko1 * thread.c, thread_pthread.ci, thread_win32.ci (thread_start_func_1):
ko1 authored
315 void
316 native_mutex_destroy(rb_thread_lock_t *lock)
317 {
35eb542 @nobu * thread_win32.ci: fixed typo.
nobu authored
318 #if USE_WIN32_MUTEX
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
319 w32_close_handle(lock);
320 #else
321 DeleteCriticalSection(lock);
322 #endif
a902624 @ko1 * thread.c, thread_pthread.ci, thread_win32.ci (thread_start_func_1):
ko1 authored
323 }
324
6244e50 @ko1 * thread.c: fix Mutex to be interruptable lock.
ko1 authored
325 struct cond_event_entry {
326 struct cond_event_entry* next;
327 HANDLE event;
328 };
329
330 struct rb_thread_cond_struct {
331 struct cond_event_entry *next;
332 struct cond_event_entry *last;
333 };
334
335 void
336 native_cond_signal(rb_thread_cond_t *cond)
337 {
338 /* cond is guarded by mutex */
339 struct cond_event_entry *e = cond->next;
340
341 if (e) {
342 cond->next = e->next;
343 SetEvent(e->event);
344 }
345 else {
346 rb_bug("native_cond_signal: no pending threads");
347 }
348 }
349
350 void
351 native_cond_broadcast(rb_thread_cond_t *cond)
352 {
353 /* cond is guarded by mutex */
354 struct cond_event_entry *e = cond->next;
355 cond->next = 0;
356
357 while (e) {
358 SetEvent(e->event);
359 e = e->next;
360 }
361 }
362
363 void
364 native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex)
365 {
366 DWORD r;
367 struct cond_event_entry entry;
368
369 entry.next = 0;
370 entry.event = CreateEvent(0, FALSE, FALSE, 0);
371
372 /* cond is guarded by mutex */
373 if (cond->next) {
374 cond->last->next = &entry;
375 cond->last = &entry;
376 }
377 else {
378 cond->next = &entry;
379 cond->last = &entry;
380 }
381
382 native_mutex_unlock(mutex);
383 {
384 r = WaitForSingleObject(entry.event, INFINITE);
385 if (r != WAIT_OBJECT_0) {
386 rb_bug("native_cond_wait: WaitForSingleObject returns %d", r);
387 }
388 }
389 native_mutex_lock(mutex);
390
391 w32_close_handle(entry.event);
392 }
393
394 void
395 native_cond_initialize(rb_thread_cond_t *cond)
396 {
397 cond->next = 0;
398 cond->last = 0;
399 }
400
401 void
402 native_cond_destroy(rb_thread_cond_t *cond)
403 {
404 /* */
405 }
a902624 @ko1 * thread.c, thread_pthread.ci, thread_win32.ci (thread_start_func_1):
ko1 authored
406
407 static void
408 native_thread_destroy(rb_thread_t *th)
409 {
00f60d0 @unak * thread_win32.ci (w32_wait_events): check whether interrupt_event is
unak authored
410 HANDLE intr = th->native_thread_data.interrupt_event;
411 thread_debug("close handle - intr: %p, thid: %p\n", intr, th->thread_id);
412 th->native_thread_data.interrupt_event = 0;
413 w32_close_handle(intr);
a902624 @ko1 * thread.c, thread_pthread.ci, thread_win32.ci (thread_start_func_1):
ko1 authored
414 }
a3e1b1c @ko1 * Merge YARV
ko1 authored
415
2840fa6 @nobu * common.mk: inverted rules order.
nobu authored
416 static unsigned long _stdcall
a3e1b1c @ko1 * Merge YARV
ko1 authored
417 thread_start_func_1(void *th_ptr)
418 {
9c57438 @ko1 * blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
ko1 authored
419 rb_thread_t *th = th_ptr;
a3e1b1c @ko1 * Merge YARV
ko1 authored
420 VALUE stack_start;
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
421 volatile HANDLE thread_id = th->thread_id;
422
423 th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
a3e1b1c @ko1 * Merge YARV
ko1 authored
424
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
425 /* run */
a3e1b1c @ko1 * Merge YARV
ko1 authored
426 thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th,
427 th->thread_id, th->native_thread_data.interrupt_event);
0fcf8e1 @nobu * thread_pthread.ci (thread_start_func_2): not use a directive inside
nobu authored
428 thread_start_func_2(th, &stack_start, 0);
a3e1b1c @ko1 * Merge YARV
ko1 authored
429
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
430 w32_close_handle(thread_id);
a3e1b1c @ko1 * Merge YARV
ko1 authored
431 thread_debug("thread deleted (th: %p)\n", th);
432 return 0;
433 }
434
17f4486 @akr extern rb_gc_stack_maxsize.
akr authored
435 extern size_t rb_gc_stack_maxsize;
436
a3e1b1c @ko1 * Merge YARV
ko1 authored
437 static int
9c57438 @ko1 * blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
ko1 authored
438 native_thread_create(rb_thread_t *th)
a3e1b1c @ko1 * Merge YARV
ko1 authored
439 {
a902624 @ko1 * thread.c, thread_pthread.ci, thread_win32.ci (thread_start_func_1):
ko1 authored
440 size_t stack_size = 4 * 1024; /* 4KB */
441 th->thread_id = w32_create_thread(stack_size, thread_start_func_1, th);
a3e1b1c @ko1 * Merge YARV
ko1 authored
442
c392e6e @akr * thread_win32.ci (native_thread_create): initialize
akr authored
443 th->machine_stack_maxsize = rb_gc_stack_maxsize; /* not tested. */
4f13113 @akr * vm_core.h (rb_thread_t): new member machine_stack_maxsize and
akr authored
444
a902624 @ko1 * thread.c, thread_pthread.ci, thread_win32.ci (thread_start_func_1):
ko1 authored
445 if ((th->thread_id) == 0) {
446 st_delete_wrap(th->vm->living_threads, th->self);
a3e1b1c @ko1 * Merge YARV
ko1 authored
447 rb_raise(rb_eThreadError, "can't create Thread (%d)", errno);
448 }
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
449
450 w32_resume_thread(th->thread_id);
451
a3e1b1c @ko1 * Merge YARV
ko1 authored
452 if (THREAD_DEBUG) {
453 Sleep(0);
454 thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %d\n",
455 th, th->thread_id,
456 th->native_thread_data.interrupt_event, stack_size);
457 }
458 return 0;
459 }
460
461 static void
84f8da1 @ko1 * thread.c (rb_thread_stop_timer_thread(), rb_thread_reset_timer_thread(...
ko1 authored
462 native_thread_join(HANDLE th)
463 {
bb022be @unak * thread.c (rb_thread_polling): check interrupts here.
unak authored
464 w32_wait_events(&th, 1, 0, 0);
84f8da1 @ko1 * thread.c (rb_thread_stop_timer_thread(), rb_thread_reset_timer_thread(...
ko1 authored
465 }
466
467 static void
9c57438 @ko1 * blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
ko1 authored
468 native_thread_apply_priority(rb_thread_t *th)
a3e1b1c @ko1 * Merge YARV
ko1 authored
469 {
470 int priority = th->priority;
471 if (th->priority > 0) {
472 priority = THREAD_PRIORITY_ABOVE_NORMAL;
473 }
474 else if (th->priority < 0) {
475 priority = THREAD_PRIORITY_BELOW_NORMAL;
476 }
477 else {
478 priority = THREAD_PRIORITY_NORMAL;
479 }
480
481 SetThreadPriority(th->thread_id, priority);
482 }
483
484 static void
3453b2b @ko1 * gc.h, vm_core.h: decl of rb_gc_save_machine_context()
ko1 authored
485 ubf_handle(void *ptr)
a3e1b1c @ko1 * Merge YARV
ko1 authored
486 {
3453b2b @ko1 * gc.h, vm_core.h: decl of rb_gc_save_machine_context()
ko1 authored
487 rb_thread_t *th = (rb_thread_t *)ptr;
ae317b5 @ko1 * yarvcore.h, thread.c: fix to use pthread on cygwin.
ko1 authored
488 thread_debug("ubf_handle: %p\n", th);
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
489 w32_set_event(th->native_thread_data.interrupt_event);
a3e1b1c @ko1 * Merge YARV
ko1 authored
490 }
491
492 static void timer_thread_function(void);
493
84f8da1 @ko1 * thread.c (rb_thread_stop_timer_thread(), rb_thread_reset_timer_thread(...
ko1 authored
494 static HANDLE timer_thread_id = 0;
a3e1b1c @ko1 * Merge YARV
ko1 authored
495
2840fa6 @nobu * common.mk: inverted rules order.
nobu authored
496 static unsigned long _stdcall
a3e1b1c @ko1 * Merge YARV
ko1 authored
497 timer_thread_func(void *dummy)
498 {
499 thread_debug("timer_thread\n");
500 while (system_working) {
501 Sleep(WIN32_WAIT_TIMEOUT);
502 timer_thread_function();
503 }
504 thread_debug("timer killed\n");
505 return 0;
506 }
507
508 void
509 rb_thread_create_timer_thread(void)
510 {
84f8da1 @ko1 * thread.c (rb_thread_stop_timer_thread(), rb_thread_reset_timer_thread(...
ko1 authored
511 if (timer_thread_id == 0) {
512 timer_thread_id = w32_create_thread(1024, timer_thread_func, 0);
a5abb1c @ko1 * thread_win32.ci (w32_show_error_message): renamed to w32_error.
ko1 authored
513 w32_resume_thread(timer_thread_id);
a3e1b1c @ko1 * Merge YARV
ko1 authored
514 }
515 }
516
517 #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
Something went wrong with that request. Please try again.