Граф коммитов

146 Коммитов

Автор SHA1 Сообщение Дата
nobu 665333e314 thread_win32.c: disable currently unused functions
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-13 01:16:36 +00:00
nobu 97819765a6 thread_win32.c: fix index
* thread_win32.c (w32_wait_events): fix wait object index in the
  case of interrupt_event is not usable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-17 13:23:42 +00:00
nobu 7206ac5492 thread_win32.c: no GVL for interrupt_event
* thread_win32.c (w32_wait_events): do not acquire GVL, to fix
  deadlock at read/close race condition.  instead, just ignore
  interrupt_event if it is closed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-16 14:27:21 +00:00
rhe 2f551849c4 Use PRIuSIZE format specifier for size_t values
Use PRIuSIZE instead of PRIdSIZE. This fixes the exception message shown
on too large xmalloc2. This commit also fixes other incorrect use of
PRIdSIZE in other functions; though most of them are debug print.

* gc.c (heap_extend_pages, get_envparam_size, ruby_malloc_size_overflow,
  gc_profile_dump_on): Use PRIuSIZE instead of PRIdSIZE as the passed
  value is size_t, not ssize_t.

* iseq.c (get_line_info, rb_iseq_disasm_insn): Ditto.

* sprintf.c (rb_str_format): Ditto.

* thread_win32.c (native_thread_create): Ditto.

* vm.c (get_param): Ditto.

* ext/objspace/objspace_dump.c (dump_append_string_content,
  dump_object): Ditto.

* ext/socket/raddrinfo.c (host_str, port_str): Ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-13 12:33:13 +00:00
nobu a46df859cc thread.c: clear atfork functions
* thread.c (rb_thread_atfork, rb_thread_atfork_before_exec): do
  nothing unless working fork is available.
* thread_sync.c (rb_mutex_abandon_all): define only if working
  fork is available.
* thread_sync.c (rb_mutex_abandon_keeping_mutexes): ditto.
* thread_sync.c (rb_mutex_abandon_locking_mutex): ditto.
* thread_win32.c (gvl_init): never used.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-09 01:46:37 +00:00
kosaki 487748fac8 * thread_pthread.c (register_ubf_list): renamed from
add_signal_thread_list.
* thread_pthread.c (unregister_ubf_list): renamed
  from remove_signal_thread_list.
* thread_pthread.c (ubf_wakeup_all_threads): renamed from
  ping_signal_thread_list.
* thread_pthread.c (ubf_wakeup_thread): renamed from
  ubf_select_each.
* thread_pthread.c (ubf_threads_empty): renamed from
  check_signal_thread_list().
* thread_pthread.c (ubf_list_lock): renamed from
  signal_thread_list_lock.

* thread_pthread.c (register_ubf_list): large simplification
  by using ccan/list.h.
  bonus: removed malloc() and exit(EXIT_FAILURE).
* thread_pthread.c (unregister_ubf_list): ditto.
* thread_pthread.c (ubf_threads_empty): ditto.
* thread_pthread.c (ubf_wakeup_all_threads): ditto.

* thread_pthread.c (print_signal_list): removed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 20:33:20 +00:00
normal f224fecc0f improve handling of timer thread shutdown
Shutting down the timer thread now always closes pipes to free FDs.
In fact, we close the write ends of the pipes is done in the main
RubyVM to signal the timer thread shutdown.

To effectively close pipes, we implement userspace locks via
atomics to force the pipe closing thread to wait on any signal
handlers which may be waking up.

While we're at it, improve robustness during resource exhaustion and
allow it to limp along non-fatally if restarting a timer thread
fails.

This reverts r51268

Note: this change is tested with VM_CHECK_MODE 1 in vm_core.h

* process.c (close_unless_reserved): add extra check
  (dup2_with_divert): remove
  (redirect_dup2): use dup2 without divert
  (before_exec_non_async_signal_safe): adjust call + comment
  (rb_f_exec): stop timer thread for all OSes
  (rb_exec_without_timer_thread): remove
* eval.c (ruby_cleanup): adjust call
* thread.c (rb_thread_stop_timer_thread): always close pipes
* thread_pthread.c (struct timer_thread_pipe): add writing field,
    mark owner_process volatile for signal handlers
  (rb_thread_wakeup_timer_thread_fd): check valid FD
  (rb_thread_wakeup_timer_thread): set writing flag to prevent close
  (rb_thread_wakeup_timer_thread_low): ditto
  (CLOSE_INVALIDATE): new macro
  (close_invalidate): new function
  (close_communication_pipe): removed
  (setup_communication_pipe_internal): make errors non-fatal
  (setup_communication_pipe): ditto
  (thread_timer): close reading ends inside timer thread
  (rb_thread_create_timer_thread): make errors non-fatal
  (native_stop_timer_thread): close write ends only, always,
   wait for signal handlers to finish
  (rb_divert_reserved_fd): remove
* thread_win32.c (native_stop_timer_thread): adjust (untested)
  (rb_divert_reserved_fd): remove
* vm_core.h: adjust prototype

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-14 09:44:10 +00:00
ngoto f242e17f9b * process.c (redirect_dup2): when the new FD of dup2() coflicts
with one of the timer thread FDs, the internal FD is diverted.
  [Bug #11336] [ruby-core:69886] [Bug #11350] [ruby-core:69961]
    
* process.c (dup2_with_divert): new function for the above purpose.
   
* thread_pthread.c (rb_divert_reserved_fd): new function for
  diverting reserved FD. If the given FD is the same as one of the
  reserved FDs, the reserved FD number is internally changed.
  It returns -1 when error. Otherwise, returns 0. It also returns
  0 if there is no need to change reserved FD number.

* thread_win32.c (rb_divert_reserved_fd): always returns 0 because
  of no reserved FDs.

* internal.h (rb_divert_reserved_fd): prototype declaration.
  It is Ruby internal use only.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-16 13:06:13 +00:00
akr 1ea4976041 * thread_pthread.c (native_set_thread_name): New function to
set thread name visible with ps command on GNU/Linux.
  Ex. ps -o %c -L

* thread.c (thread_start_func_2): Call native_set_thread_name at
  beginning.
  (rb_thread_inspect_msg): Extract from rb_thread_inspect.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-21 05:14:47 +00:00
nobu e2b10b6d13 thread_pthread.c: timer thread flag
* thread_pthread.c (timer_thread): add a flag to tell timer thread
  is created, since 0 may be a valid value as pthread_t.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-11 08:37:44 +00:00
nobu 3343feeebf Handle machine stack overflow on mingw
* thread_win32.c (rb_w32_stack_overflow_handler): use Structured
  Exception Handling by Addvectoredexceptionhandler() for machine
  stack overflow on mingw.
  This would be equivalent to the handling using __try and __exept
  on mswin introduced by r43748.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-15 08:32:55 +00:00
nobu ed37579c6a thread_*.c: constify
* thread_{pthread,win32}.c (native_cond_timedwait): constify.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-09 14:31:34 +00:00
nobu 628f75b752 vm_core.h: rb_thread_struct::machine
* vm_core.h (rb_thread_struct): aggregate cpu stuff into a struct,
  so that a debugger can show its content at once.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-28 06:09:58 +00:00
usa 1df5ebf450 * eval_intern.h (SAVE_ROOT_JMPBUF): workaround for the failure of
test/ruby/test_exception.rb on Windows.
  wrap by __try and __exception statements on mswin to raise SIGSEGV
  when EXCEPTION_STACK_OVERFLOW is occurred, because MSVCRT doesn't
  handle the exception.
  however, (1) mingw-gcc doesn't support __try and __exception
  statements, and (2) we cannot retry SystemStackError after this
  change yet (maybe crashed) because SEH and longjmp() are too
  uncongenial.

* signal.c (check_stack_overflow, CHECK_STACK_OVERFLOW): now defined on
  Windows, too.

* thread_win32.c (ruby_stack_overflowed_p): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21 06:33:41 +00:00
ko1 4d3feac974 * thread_(pthread|win32).h: rename rb_thread_cond_t to
rb_nativethread_cond_t.
* thread.c, thread_pthread.c, thread_win32.c, vm_core.h: catch up
  renaming.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 10:50:32 +00:00
ko1 b2bcef7294 * thread_native.h: add rb_nativethread_self() which returns
current running native thread identifier.
* thread_[pthread|win32].c: implement rb_nativethread_self().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 10:46:37 +00:00
ko1 bd058912da * thread_native.h: added.
Move native thread related lines from vm_core.h.
  And declare several functions "rb_nativethread_lock_*",
  manipulate locking.
* common.mk: add thread_native.h.
* thread.c: add functions "rb_nativethread_lock_*".
* thraed.c, thread_[pthread,win32].[ch]: rename rb_thread_lock_t
  to rb_nativethread_lock_t to make it clear that this lock is for
  native thraeds, not for ruby threads.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 09:53:14 +00:00
nobu 444f08f661 win32: for strict ANSI
* thread_win32.c (w32_thread_start_func, thread_start_func_1),
  (timer_thread_func): use __stdcall instead of _stdcall which is
  unavailable in strict ANSI mode.  [ruby-core:55312] [Bug #8495]
* win32/win32.c (gettimeofday): use __cdecl instead of _cdecl.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 14:12:26 +00:00
nobu 77ff241fa0 timev.h: move time_t stuffs
* timev.h (TYPEOF_TIMEVAL_TV_SEC, unsigned_time_t): move from time.c.

* thread.c: use definitions in timev.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-30 21:08:36 +00:00
akr bfb0edbad2 * internal.h: Define TIMET_MAX and TIMET_MIN here.
* time.c: Remove TIMET_MAX and TIMET_MIN definitions.

* thread.c: Ditto.

* thread_pthread.c: Remove TIMET_MAX definition.

* thread_win32.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-26 14:45:55 +00:00
nobu ccde88c1f1 * thread_win32.c (native_sleep): suppress warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-03-21 14:17:46 +00:00
nobu e881056fd6 thread_win32.c: suppress warning
* thread_win32.c (native_sleep): constify local variable to suppress a
  false positive might-be-clobbered warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-27 04:47:10 +00:00
ko1 bf442ed2b3 * thread_win32.c: catch up latest change of BLOCKING_REGION.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 13:57:52 +00:00
nobu cdeff42cc1 thread_win32.h: rb_thread_lock_t for USE_WIN32_MUTEX
* thread_win32.h (rb_thread_lock_t): make a union for USE_WIN32_MUTEX.
  this internal is used only in thread_win32.c, but has to be complete
  to define rb_thread_t.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-17 07:21:03 +00:00
nobu 3c56645634 thread_win32.c: USE_WIN32_MUTEX
* thread_win32.c (native_mutex_lock, native_mutex_destroy): fix for
  USE_WIN32_MUTEX.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-17 07:20:58 +00:00
nobu 34b6d06629 thread_win32.c: reserved pattern name
* thread_win32.c (native_cond_timedwait_ms): rename reserved pattern
  name.  user defined symbols should not start with __.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-17 07:20:53 +00:00
usa dbcda636a6 * thread_win32.c (native_thread_create): add a comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-08 01:40:08 +00:00
usa 8e601a20f4 * thread_win32.c (TIME_QUANTUM_USEC): 10ms(= old setting) [experimental]
cf. [Bug #6098]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-29 01:17:39 +00:00
shirosaki 494fd237f0 * thread_win32.c (rb_w32_wait_events_blocking): use
ruby_thread_from_native() instead of GET_THREAD() because
  GET_THREAD() doesn't always return the current thread and
  WaitForMultipleObjects() at rb_w32_read() doesn't return by
  Thread#kill. This fixes TestQueue#test_thr_kill failure on
  Windows.

* thread_win32.c (rb_w32_wait_events): use ruby_thread_from_native()
  instead of GET_THREAD() for consistency with the above change.

* thread_win32.c (rb_w32_sleep): ditto.

* thread_win32.c (rb_w32_Sleep): ditto.
  [ruby-dev:45149] [Bug #5812]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-28 00:51:36 +00:00
ko1 eb35bb0b35 * include/ruby/intern.h, thread_pthread.c (rb_reserved_fd_p,
RB_RESERVED_FD_P): added.  This C API is to limit to access
  fds which are used by RubyVM internal.  In this version of
  CRuby, return 1 if fd is communication pipe.
  If your application needs to close all file descriptors to
  preent resource leak, skip internal fds using this C API.
  We also define a macro RB_RESERVED_FD_P(fd).  So you can write
  #ifndef RB_RESERVED_FD_P
  #define RB_RESERVED_FD_P(fd) 0
  #endif
  for Ruby 1.9.2 or previous version to write compatible extensions.
  See [ruby-core:37727]
* thread_win32.c (rb_reserved_fd_p): added (return 0 for any fds).
* io.c (rb_io_initialize): raise ArgumentError if given fd is reserved by Ruby.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-03 21:56:59 +00:00
usa 565336acca * thread_win32.c (native_stop_timer_thread): fixed commit miss of
r32244.  grep sources before changing the signature of a function.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-28 04:45:05 +00:00
ko1 d1d5d5e798 * thread_pthread.c: Stop polling in the timer thread when there are
no waiting thread.  If there are 2 or more runnable threads,
  the timer thread does polling.  Avoid polling makes power save
  for several computers (0.2W per a Ruby process, when I measured).
  If outside-event such as signal or Thread#kill was occuerred
  when the timer thread does not do polling, then wake-up
  the timer thread using communication-pipe (the timer thread
  waits this communication-pipe with select(2)).
  The discussion about this modification can be found from the post
  [ruby-core:33456] and other related posts.
  Note that Eric Wong and KOSAKI Motohiro give us the huge
  contributions for this modification.  Thanks.
* thread_pthread.c (rb_thread_wakeup_timer_thread): add a function.
  This function wakes up the timer thread using communication-pipe.
* thread.c (rb_thread_stop_timer_thread): add a parameter which
  specify closing communication-pipe or not.
* thread.c (rb_thread_terminate_all): do not stop timer thread here
  (ruby_cleanup() terminate timer thread).
* signal.c: wake up timer thread using
  rb_thread_wakeup_timer_thread() from signal handler.
* eval.c (ruby_cleanup): use rb_thread_stop_timer_thread(1).
* process.c: use rb_thread_stop_timer_thread(0)
  (reuse communication-pipe).
* thread_win32.c (rb_thread_wakeup_timer_thread): add a dummy
  function.
* vm_core.h: add and fix decl. of functions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-27 00:30:41 +00:00
usa a8bdd28d10 * thread.c (do_select): Windows: no need to poll if select(2) is
cancelable.

* thread_win32.c (native_fd_select): new function to make select(2)
  cancelable.

* thread_win32.c (rb_w32_check_interrupt): new function for checking
  interrupt.

* win32/win32.c (rb_w32_select_with_thread): new function. cancelable
  select(2).

* win32/win32.c (rb_w32_select): use above function internally.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-15 18:04:13 +00:00
kosaki afd1a64cd6 * thread.c (rb_thread_schedule_rec): call gvl_yield() unconditionally.
* thread_pthread.c: remove HAVE_GVL_YIELD macro.
* thread_win32.c (gvl_yield): new. this fallback logic was moved from
  rb_thread_schedule_rec().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13 15:06:30 +00:00
kosaki bcfc22b10e * thread_pthread.c: rewrite GVL completely.
* thread_win32.c: ditto.
* thread_pthread.h: ditto.
* vm_core.h: ditto.
* thread.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13 14:14:53 +00:00
kosaki e3672626bf * thread_win32.c (native_cond_signal): remove unnecessary rb_bug().
It's addional fix for r32021. [Bug #4696]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13 12:49:53 +00:00
nobu df3e3768e9 * atomic.h (ATOMIC_OR): _InterlockedOr is not available on migw.
* gc.c (rb_gc_set_params): VM_OBJSPACE is disabled on mignw.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-12 00:32:32 +00:00
kosaki 562a1a7929 remove debugging code
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 06:22:39 +00:00
kosaki 94e4d61bda fix win32 native_cond_timedwait() makes SIGSEGV.
* thread_win32.h (rb_thread_cond_struct): add prev field instead of last.
  (ie cond_event_entry is now using double linked list instead of single)
* thread_win32.c (cond_event_entry): add prev field.

* thread_win32.c (__cond_timedwait): remove entry properly if timeout
  was happen.

* thread_win32.c (native_cond_signal): change for double linked list.
* thread_win32.c (native_cond_broadcast): ditto.
* thread_win32.c (native_cond_initialize): ditto.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 06:17:59 +00:00
kosaki 471fb33b1a fix mutex deadlock test hang-up.
* thread_win32.c (abs_timespec_to_timeout_ms): fix 1000x calculation
  mistake. (ie fix hang-up native_cond_timedwait())



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 03:43:27 +00:00
kosaki 7ac6b706b4 sleep_cond use monotonic time if possible.
* thread_pthread.c (native_thread_init): change sleep_cond
  attribute to monotonic.
* thread_pthread.c (native_sleep): use native_cond_timeout().

* thread_pthread.c (native_cond_timeout): add overflow care.
* thread_win32.c (native_cond_timeout): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06 18:17:14 +00:00
kosaki 604a1e2e22 fix win32 compile error.
* thread_win32.c (RB_CONDATTR_CLOCK_MONOTONIC): define
  RB_CONDATTR_CLOCK_MONOTONIC always.
* thread_pthread.c (RB_CONDATTR_CLOCK_MONOTONIC): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06 17:50:23 +00:00
kosaki b2ea836ae7 mutex: deadlock check timeout use monotonic time.
* thread_pthread.c (native_cond_timeout): new internal api.
  it calculate a proper time for argument of native_cond_timedwait().
* thread_win32.c (native_cond_timeout): ditto.

* thread_pthread.c (thread_timer): use native_cond_timeout()
  instead of get_ts.
* thread.c (lock_func): ditto.

* thread_pthread.c (get_ts): removed. use native_cond_timeout().
* thread.c (init_lock_timeout): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06 17:39:32 +00:00
kosaki a1cfaf4b1f * thread_pthread.h (rb_thread_cond_t): add clockid field. it's
no longer an alias of pthread_cond_t.
* thread_pthread.c: adapt new rb_thread_cond_t type.
* thread.c (mutex_alloc): ditto.
* thread_win32.c (native_cond_initialize): ditto.
* configure.in: add check for pthread_cond_attr_setclock() and
  clockid_t type.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06 16:47:38 +00:00
kosaki b5d612e0df * thread_pthread.c (native_mutex_reinitialize_atfork): removed
unused macro.
* thread_win32.c (native_mutex_reinitialize_atfork): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-05 13:26:18 +00:00
nobu 5f131b648d * thread_win32.c, include/ruby/win32.h: add prototypes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-29 12:12:52 +00:00
kosaki b4c5fad4b1 * thread_win32.c (native_cond_timedwait): New. r31373 caused
win32 build failure.

* thread_win32.c (__cond_timedwait, abs_timespec_to_timeout_ms):
  New helper functions.

* win32/win32.c (rb_w32_time_subtract): rename from subtract and
  remove static.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-29 04:18:29 +00:00
kosaki 1ff6a1953c * thread.c (thread_cleanup_func): Moved interrupted_lock
destroying code from native_thread_destroy() to
          thread_cleanup_func() because it's platform independent logic.

        * thread_win32.c (native_thread_destroy): ditto.
        * thread_pthread.c (native_thread_destroy): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-12-20 15:20:17 +00:00
nobu f0445d156c * thread_win32.c (gvl_release, gvl_init): suppress warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-28 05:55:49 +00:00
ko1 450463d5fb * thread.c, vm_core.h: make gvl_acquire/release/init/destruct
APIs to modularize GVL implementation.
* thread_pthread.c, thread_pthread.h: Two GVL implementations.
  (1) Simple locking GVL which is same as existing GVL.
  (2) Wake-up queued threads.  The wake-up order is simple FIFO.
  (We can make several queues to support exact priorities, however
  this causes some issues such as priority inversion and so on.)
  This impl. prevents spin-loop (*1) caused on SMP environemnts.
  *1: Only one Ruby thread acqures GVL again and again.
  Bug #2359 [ruby-core:26694]
* thread_win32.c, thread_win32.h: Using simple lock
  not by CRITICAL_SECTION but by Mutex.
  Bug #3890 [ruby-dev:42315]
* vm.c (ruby_vm_destruct): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-27 20:15:59 +00:00
usa f30e1877b2 * thread_win32.c (w32_error): should get error no only once, because
the result of the second getting will indicate the error of the
  first FormatMessage() call.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-27 06:08:37 +00:00
nobu 767d70841a * Makefile.in (ASFLAGS): needs INCFLAGS.
* configure.in (rb_cv_dynamic_alloca): check if extra source for
  dynamic size alloca.

* missing/x86_64-chkstk.s (___chkstk): necessary for alloca of
  amd64-mingw32msvc-gcc on Ubutu.

* thread_win32.c (ruby_alloca_chkstk): check stack overflow

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-26 09:09:45 +00:00
usa c94c6a1a16 * thread_win32.c (w32_error): get English message first, instead
of system default. see [ruby-core:32765].
  [experimental]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-13 03:10:49 +00:00
nobu cea3919ae6 * configure.in (RUBY_CHECK_PRINTF_PREFIX): check for printf format
specifier if possible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-12 15:03:51 +00:00
wanabe 060f18c0d9 * thread_win32.c (w32_wait_events, w32_close_handle): suppress warnings.
see [ruby-core:31932].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-09-23 10:29:27 +00:00
usa 6198f539bb * thread_win32.c (native_thread_join): need to wait thread, of course.
[ruby-dev:41911]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-02 07:35:35 +00:00
akr f40d2c9670 * vm.c (Init_BareVM): call Init_native_thread here.
* thread.c (Init_Thread): don't call Init_native_thread.

* thread_pthread.c (Init_native_thread): exported.

* thread_win32.c (Init_native_thread): ditto.

[ruby-dev:41536]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-06-05 23:26:43 +00:00
wanabe bd21118627 * thread_win32.c (w32_wait_events): get GVL before handle interrupt
event.   [ruby-core:27199], [ruby-core:29698]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-05 11:53:03 +00:00
usa f9e536235b * thread_win32.c (ubf_handle): remove unused typedef.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-04-22 16:28:27 +00:00
usa dfc07e8aa7 * thread_win32.c (InterlockedExchangePointer): old SDK support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-01-04 00:30:52 +00:00
usa 9f90682c4b * thread_win32.c (native_thread_destroy): decreased the probability of
using the interrupt event in the thread termination.
  see [ruby-core:27199].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-30 18:30:36 +00:00
usa 5bc85d6264 * thread_win32.c (w32_error): should report the function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-12-30 17:36:20 +00:00
nobu a000201fee * thread.c (rb_thread_atfork_internal): reinitialize global lock
at fork to get rid of deadlock.  based on the patch from Hongli
  Lai in [ruby-core:26783].  [ruby-core:26361]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-18 09:25:46 +00:00
nobu 9e0f3e0db9 * thread_win32.c (thread_errno): CreateThread does not set errno.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-12 05:33:23 +00:00
nobu 1d4183030d * thread.c (thread_create_core): moved failure handling from
native_thread_core().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-12 04:57:39 +00:00
usa 9ee5e613b5 * thread_{pthread,win32}.c (native_stop_timer_thread): join the thread
here.

* thread_{pthread,win32}.c (native_reset_timer_thread): new function.

* thread.c (rb_thread_stop_timer_thread, rb_thread_reset_timer_thread):
  call above function instead of simply seting 0.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-11-02 03:58:25 +00:00
nobu c7853b4344 * eval.c (ruby_cleanup): the order of local variables on stack is
undefined.  should use outermost VALUE for ruby_init_stack.

* gc.c (ruby_get_stack_grow_direction, Init_stack): allows volatile
  pointer.

* thread_*.c (ruby_init_stack): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-04-19 05:43:20 +00:00
usa b451955bbb * thread_win32.c (Init_native_thread): need to call
ruby_thread_set_native() here.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-12-22 10:12:02 +00:00
nobu 641f43de97 * thread_pthread.c (thread_timer): checks working flags again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-11-08 15:31:05 +00:00
nobu df6ea23faf * thread_win32.c (thread_start_func_1): use already gotten stack info.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-11-07 12:23:15 +00:00
nobu 5732566f4d * thread.c (rb_thread_stop_timer_thread): terminates timer thread
immediately.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-11-06 13:21:26 +00:00
usa 3c8dca55c4 * win32/win32.c, include/ruby/win32.h (rb_w32_open): overlapped file
I/O support.

	* win32/win32.c, include/ruby/win32.h (rb_w32_pipe): overlapped pipe
	  I/O support.

	* wn32/win32.c (rb_w32_read, rb_w32_write): overlapped I/O support to
	  enable canceling I/O.

	* thread_win32.c (ubf_handle): remove workaround.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-28 12:46:58 +00:00
ko1 16612b360b * thread.c, vm_core.h: add manual priority support
using time slice.  if you enable USE_NATIVE_THREAD_PRIORITY
  macro, this mechanism is ignored.  [ruby-dev:33124]
* thread_pthread.c, thread_win32.c: ditto.
* test/ruby/test_thread.rb: fix test parameter.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 07:53:35 +00:00
usa a73ba1def7 * thread_win32.[ch] (cond_every_entry, rb_thread_cond_struct): reverted
r18239 because r18245 made the changes unnecessary.

	* thread.c (rb_mutex_struct): define after including thread_{pthread,
	  win32}.c.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-28 12:27:43 +00:00
usa 9b3aade1b6 * thread_win32.[ch]: moved definitions of cond_every_entry and
rb_thread_cond_struct from .c to .h because rb_thread_cond_struct
	  is used in vm_core.h.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-28 07:02:07 +00:00
usa f92478c0fb * win32/win32.c (overlapped_socket_io): avoid warnings.
* thread_win32.c (ubf_handle): refactoring.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-24 07:05:49 +00:00
nobu 47e3f4e1ae * thread.c (thread_start_func_2): wake up joining threads.
* thread.c (sleep_forever, sleep_timeval): return when interrupted.
  [ruby-dev:35542]

* thread.c (timer_thread_function): restore main thread status.
  [ruby-core:17270]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-16 19:19:36 +00:00
usa 25498d24c8 * thread_win32.c (ubf_handle): cancel blocking IO if it can (only
Vista). see [ruby-dev:35446]

	* win32/win32.c (errmap): add ERROR_OPERATION_ABORTED as EINTR.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-15 09:14:09 +00:00
nobu a14682906f * thread.c (sleep_forever): wait until timed out. [ruby-core:17270]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-09 13:41:19 +00:00
nobu 7df7982b47 * thread_{pthread,win32}.c (native_sleep): wait until timed out.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-09 11:35:06 +00:00
nobu a534e39a87 * thread_{pthread,win32}.c (rb_thread_create_timer_thread): needs more
stack for debug.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-09 09:17:09 +00:00
nobu 6bbbf9889d * thread.c (thread_initialize): NUM2INT() returns int.
* thread.c (timer_thread_function), thread_pthread.c (thread_timer),
  thread_win32.c (timer_thread_func), thread_{pthread,win32}.c
  (rb_thread_create_timer_thread): passing VM.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-07-05 13:22:29 +00:00
usa 8724448ed5 * thread_win32.c (native_sleep): must block reentrance when accessing
th->unblock.
	  fixed [ruby-core:17341], reported by Bill Kelly <billk at cts.com>



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-21 07:48:29 +00:00
ko1 af94c81302 * thread_win32.c (native_sleep): fix to decrement sleeper count.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-19 15:19:38 +00:00
mame 4b645dc8f3 * thread.c, thread_win32.c, vm_core.h: try to remove false positive of
deadlock detection.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-19 14:18:46 +00:00
nobu fc3c60f608 * gc.h (STACK_UPPER): moved from gc.c
* thread.c, thread_{pthread,win32}.c (ruby_init_stack,
  ruby_thread_init_stack): moved stack initialization from gc.c.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-14 02:59:19 +00:00
usa 4b022866ee * thread_win32.c (native_sleep): fixed previous commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-12 13:20:55 +00:00
mame 6f5aaff73b * thread.c, vm_core.h, vm.c, thread_pthread.c, thread_win32.c: add
deadlock detection.  [ruby-dev:35044]

* bootstraptest/test_thread.rb: add tests for above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-12 13:01:38 +00:00
nobu 1b63d7bc92 * vm_core.h (struct rb_unblock_callback), thread.c
(set_unblock_function), thread_{pthread,win32}.c (native_sleep):
  extracted from struct rb_thread_struct.

* thread.c (reset_unblock_function): not check interrupts at leaving
  blocking region.  [ruby-dev:34874]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-30 01:52:38 +00:00
nobu 87e4ad0a23 * io.c, signal.c, thread.c, thread_win32.c, include/ruby/intern.h:
suppress warnings.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-26 09:36:35 +00:00
usa caa539f2a3 * thread_win32.c (w32_wait_events): shouldn't invoke interrupt handle
by timer_thread.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-18 15:15:40 +00:00
nobu 3a4bfbad09 * thread.c (thread_cleanup_func): ignore errors from destroying mutex
of dead thread.  [ruby-core:15069]

* thread_pthread.c, thread_win32.c (native_thread_destroy): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-18 06:57:08 +00:00
akr 6cdef2dc7e * $Date$ keyword removed to avoid inclusion of locale dependent
string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-06 15:49:38 +00:00
ko1 42f0b52f77 * thread_pthread.c, thread_pthread.h, thread_win32.c,
thread_win32.c: make some functions static functions.
  a patch from Tadashi Saito <shiba AT mail2.accsnet.ne.jp>
  in [ruby-core:14407]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-25 04:35:17 +00:00
ko1 5f0b8afb97 * vm_core.h, thread.c, cont.c: add RUBY_VM_SET_INTERRUPT(),
RUBY_VM_SET_TIMER_INTERRUPT(), RUBY_VM_INTERRUPTED().
* thread.c, thread_pthread.c, thread_win32.c: fix to ignore time slice
  event until sleep.
* bootstraptest/test_thread.rb: add a test for time limited join test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-25 04:16:06 +00:00
ko1 c334a09f7a * common.mk, *.ci: renamed to *.c.
* eval_laod.c: renamed to load.c.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-20 09:29:46 +00:00