ruby-changes:48729
From: normal <ko1@a...>
Date: Sun, 19 Nov 2017 14:03:23 +0900 (JST)
Subject: [ruby-changes:48729] normal:r60845 (trunk): File.readlink and rb_readlink releases GVL
normal 2017-11-19 14:03:17 +0900 (Sun, 19 Nov 2017) New Revision: 60845 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60845 Log: File.readlink and rb_readlink releases GVL The `readlink' can stall on slow filesystems like `open' and `read' syscalls. Release the GVL and let the rest of the VM function while `readlink' runs. * file.c (nogvl_readlink): new function (readlink_without_gvl): ditto (rb_readlink): use readlink_without_gvl Modified files: trunk/file.c Index: file.c =================================================================== --- file.c (revision 60844) +++ file.c (revision 60845) @@ -2873,6 +2873,33 @@ rb_file_s_readlink(VALUE klass, VALUE pa https://github.com/ruby/ruby/blob/trunk/file.c#L2873 } #ifndef _WIN32 +struct readlink_arg { + const char *path; + char *buf; + size_t size; +}; + +static void * +nogvl_readlink(void *ptr) +{ + struct readlink_arg *ra = ptr; + + return (void *)(VALUE)readlink(ra->path, ra->buf, ra->size); +} + +static ssize_t +readlink_without_gvl(VALUE path, VALUE buf, size_t size) +{ + struct readlink_arg ra; + + ra.path = RSTRING_PTR(path); + ra.buf = RSTRING_PTR(buf); + ra.size = size; + + return (ssize_t)rb_thread_call_without_gvl(nogvl_readlink, &ra, + RUBY_UBF_IO, 0); +} + VALUE rb_readlink(VALUE path, rb_encoding *enc) { @@ -2883,7 +2910,7 @@ rb_readlink(VALUE path, rb_encoding *enc https://github.com/ruby/ruby/blob/trunk/file.c#L2910 FilePathValue(path); path = rb_str_encode_ospath(path); v = rb_enc_str_new(0, size, enc); - while ((rv = readlink(RSTRING_PTR(path), RSTRING_PTR(v), size)) == size + while ((rv = readlink_without_gvl(path, v, size)) == size #ifdef _AIX || (rv < 0 && errno == ERANGE) /* quirky behavior of GPFS */ #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/