diff options
author | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-09 09:58:07 +0000 |
---|---|---|
committer | k0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-09 09:58:07 +0000 |
commit | 510cd06c78a7a2e24b30468d54d675577083c5ad (patch) | |
tree | 29f7ccc04cc36acd612f395800b09ba933514a82 /mjit.c | |
parent | 82de3b95c4c0bcd3f8ba0bac6f0dec81c787a067 (diff) | |
download | ruby-510cd06c78a7a2e24b30468d54d675577083c5ad.tar.gz |
mjit.c: add :wait option to RubyVM::MJIT.pause
and wait until JIT queue is flushed when wait option is not passed or
`wait: true` is passed.
vm.c: ditto
test/ruby/test_rubyvm_mjit.rb: added test for pause/resume
test/lib/jit_support.rb: allow retrying MJIT on JITSupport level
test/ruby/test_jit.rb: ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit.c')
-rw-r--r-- | mjit.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -1782,8 +1782,19 @@ stop_worker(void) /* Stop JIT-compiling methods but compiled code is kept available. */ VALUE -mjit_pause(void) +mjit_pause(int argc, VALUE *argv, VALUE recv) { + VALUE options = Qnil; + VALUE wait = Qtrue; + rb_scan_args(argc, argv, "0:", &options); + + if (!NIL_P(options)) { + static ID keyword_ids[1]; + if (!keyword_ids[0]) + keyword_ids[0] = rb_intern("wait"); + rb_get_kwargs(options, keyword_ids, 0, 1, &wait); + } + if (!mjit_enabled) { rb_raise(rb_eRuntimeError, "MJIT is not enabled"); } @@ -1791,6 +1802,20 @@ mjit_pause(void) return Qfalse; } + /* Flush all queued units with `wait: true` (default) */ + if (RTEST(wait)) { + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 1000; + + while (unit_queue.length > 0) { + CRITICAL_SECTION_START(3, "in mjit_pause for a worker wakeup"); + rb_native_cond_broadcast(&mjit_worker_wakeup); + CRITICAL_SECTION_FINISH(3, "in mjit_pause for a worker wakeup"); + rb_thread_wait_for(tv); + } + } + stop_worker(); return Qtrue; } |