Ruby  2.1.10p492(2016-04-01revision54464)
thread_win32.c
Go to the documentation of this file.
1 /* -*-c-*- */
2 /**********************************************************************
3 
4  thread_win32.c -
5 
6  $Author: nagachika $
7 
8  Copyright (C) 2004-2007 Koichi Sasada
9 
10 **********************************************************************/
11 
12 #ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
13 
14 #include <process.h>
15 
16 #define TIME_QUANTUM_USEC (10 * 1000)
17 #define RB_CONDATTR_CLOCK_MONOTONIC 1 /* no effect */
18 
19 #undef Sleep
20 
21 #define native_thread_yield() Sleep(0)
22 #define remove_signal_thread_list(th)
23 
24 static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
25 
26 static int w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th);
27 static int native_mutex_lock(rb_nativethread_lock_t *lock);
28 static int native_mutex_unlock(rb_nativethread_lock_t *lock);
29 
30 static void
31 w32_error(const char *func)
32 {
33  LPVOID lpMsgBuf;
34  DWORD err = GetLastError();
35  if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
36  FORMAT_MESSAGE_FROM_SYSTEM |
37  FORMAT_MESSAGE_IGNORE_INSERTS,
38  NULL,
39  err,
40  MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
41  (LPTSTR) & lpMsgBuf, 0, NULL) == 0)
42  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
43  FORMAT_MESSAGE_FROM_SYSTEM |
44  FORMAT_MESSAGE_IGNORE_INSERTS,
45  NULL,
46  err,
47  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
48  (LPTSTR) & lpMsgBuf, 0, NULL);
49  rb_bug("%s: %s", func, (char*)lpMsgBuf);
50 }
51 
52 static int
53 w32_mutex_lock(HANDLE lock)
54 {
55  DWORD result;
56  while (1) {
57  thread_debug("native_mutex_lock: %p\n", lock);
58  result = w32_wait_events(&lock, 1, INFINITE, 0);
59  switch (result) {
60  case WAIT_OBJECT_0:
61  /* get mutex object */
62  thread_debug("acquire mutex: %p\n", lock);
63  return 0;
64  case WAIT_OBJECT_0 + 1:
65  /* interrupt */
66  errno = EINTR;
67  thread_debug("acquire mutex interrupted: %p\n", lock);
68  return 0;
69  case WAIT_TIMEOUT:
70  thread_debug("timeout mutex: %p\n", lock);
71  break;
72  case WAIT_ABANDONED:
73  rb_bug("win32_mutex_lock: WAIT_ABANDONED");
74  break;
75  default:
76  rb_bug("win32_mutex_lock: unknown result (%ld)", result);
77  break;
78  }
79  }
80  return 0;
81 }
82 
83 static HANDLE
84 w32_mutex_create(void)
85 {
86  HANDLE lock = CreateMutex(NULL, FALSE, NULL);
87  if (lock == NULL) {
88  w32_error("native_mutex_initialize");
89  }
90  return lock;
91 }
92 
93 #define GVL_DEBUG 0
94 
95 static void
96 gvl_acquire(rb_vm_t *vm, rb_thread_t *th)
97 {
98  w32_mutex_lock(vm->gvl.lock);
99  if (GVL_DEBUG) fprintf(stderr, "gvl acquire (%p): acquire\n", th);
100 }
101 
102 static void
103 gvl_release(rb_vm_t *vm)
104 {
105  ReleaseMutex(vm->gvl.lock);
106 }
107 
108 static void
109 gvl_yield(rb_vm_t *vm, rb_thread_t *th)
110 {
111  gvl_release(th->vm);
112  native_thread_yield();
113  gvl_acquire(vm, th);
114 }
115 
116 
117 static void
118 gvl_atfork(rb_vm_t *vm)
119 {
120  rb_bug("gvl_atfork() is called on win32");
121 }
122 
123 static void
124 gvl_init(rb_vm_t *vm)
125 {
126  if (GVL_DEBUG) fprintf(stderr, "gvl init\n");
127  vm->gvl.lock = w32_mutex_create();
128 }
129 
130 static void
131 gvl_destroy(rb_vm_t *vm)
132 {
133  if (GVL_DEBUG) fprintf(stderr, "gvl destroy\n");
134  CloseHandle(vm->gvl.lock);
135 }
136 
137 static rb_thread_t *
138 ruby_thread_from_native(void)
139 {
140  return TlsGetValue(ruby_native_thread_key);
141 }
142 
143 static int
144 ruby_thread_set_native(rb_thread_t *th)
145 {
146  return TlsSetValue(ruby_native_thread_key, th);
147 }
148 
149 void
150 Init_native_thread(void)
151 {
152  rb_thread_t *th = GET_THREAD();
153 
154  ruby_native_thread_key = TlsAlloc();
155  ruby_thread_set_native(th);
156  DuplicateHandle(GetCurrentProcess(),
157  GetCurrentThread(),
158  GetCurrentProcess(),
159  &th->thread_id, 0, FALSE, DUPLICATE_SAME_ACCESS);
160 
161  th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
162 
163  thread_debug("initial thread (th: %p, thid: %p, event: %p)\n",
164  th, GET_THREAD()->thread_id,
166 }
167 
168 static void
169 w32_set_event(HANDLE handle)
170 {
171  if (SetEvent(handle) == 0) {
172  w32_error("w32_set_event");
173  }
174 }
175 
176 static void
177 w32_reset_event(HANDLE handle)
178 {
179  if (ResetEvent(handle) == 0) {
180  w32_error("w32_reset_event");
181  }
182 }
183 
184 static int
185 w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th)
186 {
187  HANDLE *targets = events;
188  HANDLE intr;
189  DWORD ret;
190 
191  thread_debug(" w32_wait_events events:%p, count:%d, timeout:%ld, th:%p\n",
192  events, count, timeout, th);
193  if (th && (intr = th->native_thread_data.interrupt_event)) {
194  gvl_acquire(th->vm, th);
195  if (intr == th->native_thread_data.interrupt_event) {
196  w32_reset_event(intr);
197  if (RUBY_VM_INTERRUPTED(th)) {
198  w32_set_event(intr);
199  }
200 
201  targets = ALLOCA_N(HANDLE, count + 1);
202  memcpy(targets, events, sizeof(HANDLE) * count);
203 
204  targets[count++] = intr;
205  thread_debug(" * handle: %p (count: %d, intr)\n", intr, count);
206  }
207  gvl_release(th->vm);
208  }
209 
210  thread_debug(" WaitForMultipleObjects start (count: %d)\n", count);
211  ret = WaitForMultipleObjects(count, targets, FALSE, timeout);
212  thread_debug(" WaitForMultipleObjects end (ret: %lu)\n", ret);
213 
214  if (ret == (DWORD)(WAIT_OBJECT_0 + count - 1) && th) {
215  errno = EINTR;
216  }
217  if (ret == WAIT_FAILED && THREAD_DEBUG) {
218  int i;
219  DWORD dmy;
220  for (i = 0; i < count; i++) {
221  thread_debug(" * error handle %d - %s\n", i,
222  GetHandleInformation(targets[i], &dmy) ? "OK" : "NG");
223  }
224  }
225  return ret;
226 }
227 
228 static void ubf_handle(void *ptr);
229 #define ubf_select ubf_handle
230 
231 int
232 rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
233 {
234  return w32_wait_events(events, num, timeout, ruby_thread_from_native());
235 }
236 
237 int
238 rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
239 {
240  int ret;
241 
242  BLOCKING_REGION(ret = rb_w32_wait_events_blocking(events, num, timeout),
243  ubf_handle, ruby_thread_from_native(), FALSE);
244  return ret;
245 }
246 
247 static void
248 w32_close_handle(HANDLE handle)
249 {
250  if (CloseHandle(handle) == 0) {
251  w32_error("w32_close_handle");
252  }
253 }
254 
255 static void
256 w32_resume_thread(HANDLE handle)
257 {
258  if (ResumeThread(handle) == (DWORD)-1) {
259  w32_error("w32_resume_thread");
260  }
261 }
262 
263 #ifdef _MSC_VER
264 #define HAVE__BEGINTHREADEX 1
265 #else
266 #undef HAVE__BEGINTHREADEX
267 #endif
268 
269 #ifdef HAVE__BEGINTHREADEX
270 #define start_thread (HANDLE)_beginthreadex
271 #define thread_errno errno
272 typedef unsigned long (__stdcall *w32_thread_start_func)(void*);
273 #else
274 #define start_thread CreateThread
275 #define thread_errno rb_w32_map_errno(GetLastError())
276 typedef LPTHREAD_START_ROUTINE w32_thread_start_func;
277 #endif
278 
279 static HANDLE
280 w32_create_thread(DWORD stack_size, w32_thread_start_func func, void *val)
281 {
282  return start_thread(0, stack_size, func, val, CREATE_SUSPENDED, 0);
283 }
284 
285 int
286 rb_w32_sleep(unsigned long msec)
287 {
288  return w32_wait_events(0, 0, msec, ruby_thread_from_native());
289 }
290 
291 int WINAPI
292 rb_w32_Sleep(unsigned long msec)
293 {
294  int ret;
295 
296  BLOCKING_REGION(ret = rb_w32_sleep(msec),
297  ubf_handle, ruby_thread_from_native(), FALSE);
298  return ret;
299 }
300 
301 static void
302 native_sleep(rb_thread_t *th, struct timeval *tv)
303 {
304  const volatile DWORD msec = (tv) ?
305  (DWORD)(tv->tv_sec * 1000 + tv->tv_usec / 1000) : INFINITE;
306 
308  {
309  DWORD ret;
310 
311  native_mutex_lock(&th->interrupt_lock);
312  th->unblock.func = ubf_handle;
313  th->unblock.arg = th;
314  native_mutex_unlock(&th->interrupt_lock);
315 
316  if (RUBY_VM_INTERRUPTED(th)) {
317  /* interrupted. return immediate */
318  }
319  else {
320  thread_debug("native_sleep start (%lu)\n", msec);
321  ret = w32_wait_events(0, 0, msec, th);
322  thread_debug("native_sleep done (%lu)\n", ret);
323  }
324 
325  native_mutex_lock(&th->interrupt_lock);
326  th->unblock.func = 0;
327  th->unblock.arg = 0;
328  native_mutex_unlock(&th->interrupt_lock);
329  }
330  GVL_UNLOCK_END();
331 }
332 
333 static int
334 native_mutex_lock(rb_nativethread_lock_t *lock)
335 {
336 #if USE_WIN32_MUTEX
337  w32_mutex_lock(lock->mutex);
338 #else
339  EnterCriticalSection(&lock->crit);
340 #endif
341  return 0;
342 }
343 
344 static int
345 native_mutex_unlock(rb_nativethread_lock_t *lock)
346 {
347 #if USE_WIN32_MUTEX
348  thread_debug("release mutex: %p\n", lock->mutex);
349  return ReleaseMutex(lock->mutex);
350 #else
351  LeaveCriticalSection(&lock->crit);
352  return 0;
353 #endif
354 }
355 
356 static int
357 native_mutex_trylock(rb_nativethread_lock_t *lock)
358 {
359 #if USE_WIN32_MUTEX
360  int result;
361  thread_debug("native_mutex_trylock: %p\n", lock->mutex);
362  result = w32_wait_events(&lock->mutex, 1, 1, 0);
363  thread_debug("native_mutex_trylock result: %d\n", result);
364  switch (result) {
365  case WAIT_OBJECT_0:
366  return 0;
367  case WAIT_TIMEOUT:
368  return EBUSY;
369  }
370  return EINVAL;
371 #else
372  return TryEnterCriticalSection(&lock->crit) == 0;
373 #endif
374 }
375 
376 static void
377 native_mutex_initialize(rb_nativethread_lock_t *lock)
378 {
379 #if USE_WIN32_MUTEX
380  lock->mutex = w32_mutex_create();
381  /* thread_debug("initialize mutex: %p\n", lock->mutex); */
382 #else
383  InitializeCriticalSection(&lock->crit);
384 #endif
385 }
386 
387 static void
388 native_mutex_destroy(rb_nativethread_lock_t *lock)
389 {
390 #if USE_WIN32_MUTEX
391  w32_close_handle(lock->mutex);
392 #else
393  DeleteCriticalSection(&lock->crit);
394 #endif
395 }
396 
397 struct cond_event_entry {
398  struct cond_event_entry* next;
399  struct cond_event_entry* prev;
400  HANDLE event;
401 };
402 
403 static void
404 native_cond_signal(rb_nativethread_cond_t *cond)
405 {
406  /* cond is guarded by mutex */
407  struct cond_event_entry *e = cond->next;
408  struct cond_event_entry *head = (struct cond_event_entry*)cond;
409 
410  if (e != head) {
411  struct cond_event_entry *next = e->next;
412  struct cond_event_entry *prev = e->prev;
413 
414  prev->next = next;
415  next->prev = prev;
416  e->next = e->prev = e;
417 
418  SetEvent(e->event);
419  }
420 }
421 
422 static void
423 native_cond_broadcast(rb_nativethread_cond_t *cond)
424 {
425  /* cond is guarded by mutex */
426  struct cond_event_entry *e = cond->next;
427  struct cond_event_entry *head = (struct cond_event_entry*)cond;
428 
429  while (e != head) {
430  struct cond_event_entry *next = e->next;
431  struct cond_event_entry *prev = e->prev;
432 
433  SetEvent(e->event);
434 
435  prev->next = next;
436  next->prev = prev;
437  e->next = e->prev = e;
438 
439  e = next;
440  }
441 }
442 
443 
444 static int
445 native_cond_timedwait_ms(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec)
446 {
447  DWORD r;
448  struct cond_event_entry entry;
449  struct cond_event_entry *head = (struct cond_event_entry*)cond;
450 
451  entry.event = CreateEvent(0, FALSE, FALSE, 0);
452 
453  /* cond is guarded by mutex */
454  entry.next = head;
455  entry.prev = head->prev;
456  head->prev->next = &entry;
457  head->prev = &entry;
458 
459  native_mutex_unlock(mutex);
460  {
461  r = WaitForSingleObject(entry.event, msec);
462  if ((r != WAIT_OBJECT_0) && (r != WAIT_TIMEOUT)) {
463  rb_bug("native_cond_wait: WaitForSingleObject returns %lu", r);
464  }
465  }
466  native_mutex_lock(mutex);
467 
468  entry.prev->next = entry.next;
469  entry.next->prev = entry.prev;
470 
471  w32_close_handle(entry.event);
472  return (r == WAIT_OBJECT_0) ? 0 : ETIMEDOUT;
473 }
474 
475 static int
476 native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex)
477 {
478  return native_cond_timedwait_ms(cond, mutex, INFINITE);
479 }
480 
481 static unsigned long
482 abs_timespec_to_timeout_ms(struct timespec *ts)
483 {
484  struct timeval tv;
485  struct timeval now;
486 
487  gettimeofday(&now, NULL);
488  tv.tv_sec = ts->tv_sec;
489  tv.tv_usec = ts->tv_nsec / 1000;
490 
491  if (!rb_w32_time_subtract(&tv, &now))
492  return 0;
493 
494  return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
495 }
496 
497 static int
498 native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, struct timespec *ts)
499 {
500  unsigned long timeout_ms;
501 
502  timeout_ms = abs_timespec_to_timeout_ms(ts);
503  if (!timeout_ms)
504  return ETIMEDOUT;
505 
506  return native_cond_timedwait_ms(cond, mutex, timeout_ms);
507 }
508 
509 static struct timespec
510 native_cond_timeout(rb_nativethread_cond_t *cond, struct timespec timeout_rel)
511 {
512  int ret;
513  struct timeval tv;
514  struct timespec timeout;
515  struct timespec now;
516 
517  ret = gettimeofday(&tv, 0);
518  if (ret != 0)
519  rb_sys_fail(0);
520  now.tv_sec = tv.tv_sec;
521  now.tv_nsec = tv.tv_usec * 1000;
522 
523  timeout.tv_sec = now.tv_sec;
524  timeout.tv_nsec = now.tv_nsec;
525  timeout.tv_sec += timeout_rel.tv_sec;
526  timeout.tv_nsec += timeout_rel.tv_nsec;
527 
528  if (timeout.tv_nsec >= 1000*1000*1000) {
529  timeout.tv_sec++;
530  timeout.tv_nsec -= 1000*1000*1000;
531  }
532 
533  if (timeout.tv_sec < now.tv_sec)
534  timeout.tv_sec = TIMET_MAX;
535 
536  return timeout;
537 }
538 
539 static void
540 native_cond_initialize(rb_nativethread_cond_t *cond, int flags)
541 {
542  cond->next = (struct cond_event_entry *)cond;
543  cond->prev = (struct cond_event_entry *)cond;
544 }
545 
546 static void
547 native_cond_destroy(rb_nativethread_cond_t *cond)
548 {
549  /* */
550 }
551 
552 void
553 ruby_init_stack(volatile VALUE *addr)
554 {
555 }
556 
557 #define CHECK_ERR(expr) \
558  {if (!(expr)) {rb_bug("err: %lu - %s", GetLastError(), #expr);}}
559 
560 static void
561 native_thread_init_stack(rb_thread_t *th)
562 {
563  MEMORY_BASIC_INFORMATION mi;
564  char *base, *end;
565  DWORD size, space;
566 
567  CHECK_ERR(VirtualQuery(&mi, &mi, sizeof(mi)));
568  base = mi.AllocationBase;
569  end = mi.BaseAddress;
570  end += mi.RegionSize;
571  size = end - base;
572  space = size / 5;
573  if (space > 1024*1024) space = 1024*1024;
574  th->machine.stack_start = (VALUE *)end - 1;
575  th->machine.stack_maxsize = size - space;
576 }
577 
578 #ifndef InterlockedExchangePointer
579 #define InterlockedExchangePointer(t, v) \
580  (void *)InterlockedExchange((long *)(t), (long)(v))
581 #endif
582 static void
583 native_thread_destroy(rb_thread_t *th)
584 {
585  HANDLE intr = InterlockedExchangePointer(&th->native_thread_data.interrupt_event, 0);
586  thread_debug("close handle - intr: %p, thid: %p\n", intr, th->thread_id);
587  w32_close_handle(intr);
588 }
589 
590 static unsigned long __stdcall
591 thread_start_func_1(void *th_ptr)
592 {
593  rb_thread_t *th = th_ptr;
594  volatile HANDLE thread_id = th->thread_id;
595 
596  native_thread_init_stack(th);
597  th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
598 
599  /* run */
600  thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th,
602 
603  thread_start_func_2(th, th->machine.stack_start, rb_ia64_bsp());
604 
605  w32_close_handle(thread_id);
606  thread_debug("thread deleted (th: %p)\n", th);
607  return 0;
608 }
609 
610 static int
611 native_thread_create(rb_thread_t *th)
612 {
613  size_t stack_size = 4 * 1024; /* 4KB is the minimum commit size */
614  th->thread_id = w32_create_thread(stack_size, thread_start_func_1, th);
615 
616  if ((th->thread_id) == 0) {
617  return thread_errno;
618  }
619 
620  w32_resume_thread(th->thread_id);
621 
622  if (THREAD_DEBUG) {
623  Sleep(0);
624  thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %"PRIdSIZE"\n",
625  th, th->thread_id,
626  th->native_thread_data.interrupt_event, stack_size);
627  }
628  return 0;
629 }
630 
631 static void
632 native_thread_join(HANDLE th)
633 {
634  w32_wait_events(&th, 1, INFINITE, 0);
635 }
636 
637 #if USE_NATIVE_THREAD_PRIORITY
638 
639 static void
640 native_thread_apply_priority(rb_thread_t *th)
641 {
642  int priority = th->priority;
643  if (th->priority > 0) {
644  priority = THREAD_PRIORITY_ABOVE_NORMAL;
645  }
646  else if (th->priority < 0) {
647  priority = THREAD_PRIORITY_BELOW_NORMAL;
648  }
649  else {
650  priority = THREAD_PRIORITY_NORMAL;
651  }
652 
653  SetThreadPriority(th->thread_id, priority);
654 }
655 
656 #endif /* USE_NATIVE_THREAD_PRIORITY */
657 
658 int rb_w32_select_with_thread(int, fd_set *, fd_set *, fd_set *, struct timeval *, void *); /* @internal */
659 
660 static int
661 native_fd_select(int n, rb_fdset_t *readfds, rb_fdset_t *writefds, rb_fdset_t *exceptfds, struct timeval *timeout, rb_thread_t *th)
662 {
663  fd_set *r = NULL, *w = NULL, *e = NULL;
664  if (readfds) {
665  rb_fd_resize(n - 1, readfds);
666  r = rb_fd_ptr(readfds);
667  }
668  if (writefds) {
669  rb_fd_resize(n - 1, writefds);
670  w = rb_fd_ptr(writefds);
671  }
672  if (exceptfds) {
673  rb_fd_resize(n - 1, exceptfds);
674  e = rb_fd_ptr(exceptfds);
675  }
676  return rb_w32_select_with_thread(n, r, w, e, timeout, th);
677 }
678 
679 /* @internal */
680 int
682 {
683  return w32_wait_events(0, 0, 0, th);
684 }
685 
686 static void
687 ubf_handle(void *ptr)
688 {
689  rb_thread_t *th = (rb_thread_t *)ptr;
690  thread_debug("ubf_handle: %p\n", th);
691 
692  w32_set_event(th->native_thread_data.interrupt_event);
693 }
694 
695 static HANDLE timer_thread_id = 0;
696 static HANDLE timer_thread_lock;
697 
698 static unsigned long __stdcall
699 timer_thread_func(void *dummy)
700 {
701  thread_debug("timer_thread\n");
702  while (WaitForSingleObject(timer_thread_lock, TIME_QUANTUM_USEC/1000) ==
703  WAIT_TIMEOUT) {
704  timer_thread_function(dummy);
705  }
706  thread_debug("timer killed\n");
707  return 0;
708 }
709 
710 void
712 {
713  /* do nothing */
714 }
715 
716 static void
717 rb_thread_create_timer_thread(void)
718 {
719  if (timer_thread_id == 0) {
720  if (!timer_thread_lock) {
721  timer_thread_lock = CreateEvent(0, TRUE, FALSE, 0);
722  }
723  timer_thread_id = w32_create_thread(1024 + (THREAD_DEBUG ? BUFSIZ : 0),
724  timer_thread_func, 0);
725  w32_resume_thread(timer_thread_id);
726  }
727 }
728 
729 static int
730 native_stop_timer_thread(int close_anyway)
731 {
732  int stopped = --system_working <= 0;
733  if (stopped) {
734  SetEvent(timer_thread_lock);
735  native_thread_join(timer_thread_id);
736  CloseHandle(timer_thread_lock);
737  timer_thread_lock = 0;
738  }
739  return stopped;
740 }
741 
742 static void
743 native_reset_timer_thread(void)
744 {
745  if (timer_thread_id) {
746  CloseHandle(timer_thread_id);
747  timer_thread_id = 0;
748  }
749 }
750 
751 int
752 ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
753 {
755 }
756 
757 #if defined(__MINGW32__)
758 LONG WINAPI
759 rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *exception)
760 {
761  if (exception->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
763  raise(SIGSEGV);
764  }
765  return EXCEPTION_CONTINUE_SEARCH;
766 }
767 #endif
768 
769 #ifdef RUBY_ALLOCA_CHKSTK
770 void
771 ruby_alloca_chkstk(size_t len, void *sp)
772 {
773  if (ruby_stack_length(NULL) * sizeof(VALUE) >= len) {
774  rb_thread_t *th = GET_THREAD();
778  }
779  }
780 }
781 #endif
782 int
783 rb_reserved_fd_p(int fd)
784 {
785  return 0;
786 }
787 
790 {
791  return GetCurrentThread();
792 }
793 
794 #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
#define cond(node)
Definition: ripper.c:427
RUBY_SYMBOL_EXPORT_BEGIN rb_nativethread_id_t rb_nativethread_self()
rb_vm_t * vm
Definition: vm_core.h:526
void rb_bug(const char *fmt,...)
Definition: error.c:327
int gettimeofday(struct timeval *, struct timezone *)
Definition: win32.c:4313
#define FALSE
Definition: nkf.h:174
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
int count
Definition: encoding.c:48
size_t ruby_stack_length(VALUE **p)
Definition: gc.c:3253
rb_unblock_function_t * func
Definition: vm_core.h:500
#define THREAD_DEBUG
Definition: thread.c:74
long tv_sec
Definition: ossl_asn1.c:17
#define sysstack_error
Definition: vm_core.h:901
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
pthread_mutex_t rb_nativethread_lock_t
static volatile int system_working
Definition: thread.c:95
struct rb_thread_struct::@169 machine
#define head
Definition: st.c:107
time_t tv_sec
Definition: missing.h:51
WINBASEAPI BOOL WINAPI TryEnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection)
void rb_exc_raise(VALUE mesg)
Definition: eval.c:567
fd_set rb_fdset_t
Definition: intern.h:348
void rb_thread_wakeup_timer_thread(void)
#define val
long tv_usec
Definition: ossl_asn1.c:18
IUnknown DWORD
Definition: win32ole.c:149
#define rb_fd_ptr(f)
Definition: intern.h:356
int WINAPI rb_w32_Sleep(unsigned long msec)
long tv_nsec
Definition: missing.h:52
#define thread_debug
Definition: thread.c:210
int rb_w32_sleep(unsigned long msec)
#define ALLOCA_N(type, n)
Definition: ruby.h:1345
int rb_w32_select_with_thread(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout, void *th)
Definition: win32.c:2849
int err
Definition: win32.c:114
#define GVL_UNLOCK_BEGIN()
Definition: thread.c:136
int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait)
Definition: win32.c:2810
int errno
#define TRUE
Definition: nkf.h:175
pthread_t rb_nativethread_id_t
#define rb_thread_raised_set(th, f)
Definition: eval_intern.h:223
#define GVL_UNLOCK_END()
Definition: thread.c:141
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
void Init_native_thread(void)
void ruby_init_stack(volatile VALUE *)
static void timer_thread_function(void *)
Definition: thread.c:3829
void rb_sys_fail(const char *mesg)
Definition: error.c:1976
int rb_reserved_fd_p(int fd)
#define thread_start_func_2(th, st, rst)
Definition: thread.c:214
int size
Definition: encoding.c:49
VALUE * stack_start
Definition: vm_core.h:621
struct rb_unblock_callback unblock
Definition: vm_core.h:589
rb_nativethread_id_t thread_id
Definition: vm_core.h:561
#define ETIMEDOUT
Definition: win32.h:584
native_thread_data_t native_thread_data
Definition: vm_core.h:566
#define BLOCKING_REGION(func, arg)
Definition: rubysocket.h:258
#define rb_thread_raised_p(th, f)
Definition: eval_intern.h:225
#define rb_fd_resize(n, f)
Definition: intern.h:355
#define PRIdSIZE
Definition: ruby.h:176
rb_global_vm_lock_t gvl
Definition: vm_core.h:351
#define RUBY_VM_INTERRUPTED(th)
Definition: vm_core.h:965
rb_nativethread_lock_t interrupt_lock
Definition: vm_core.h:587
size_t stack_maxsize
Definition: vm_core.h:623
#define NULL
Definition: _sdbm.c:102
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:929
int rb_w32_check_interrupt(void *)