Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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