Project

General

Profile

Feature #13951 ยป 0001-File-rename-releases-GVL.patch

normalperson (Eric Wong), 09/29/2017 08:54 AM

View differences:

benchmark/bm_file_rename.rb
# rename file
require 'tempfile'
max = 100_000
tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ]
a, b = tmp.map { |x| x.path }
max.times do
File.rename(a, b)
File.rename(b, a)
end
tmp.each { |t| t.close! }
file.c
return apply2files(unlink_internal, argc, argv, 0);
}
struct rename_args {
const char *src;
const char *dst;
};
static void *
no_gvl_rename(void *ptr)
{
struct rename_args *ra = ptr;
return (void *)rename(ra->src, ra->dst);
}
/*
* call-seq:
* File.rename(old_name, new_name) -> 0
......
static VALUE
rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
{
const char *src, *dst;
struct rename_args ra;
VALUE f, t;
FilePathValue(from);
FilePathValue(to);
f = rb_str_encode_ospath(from);
t = rb_str_encode_ospath(to);
src = StringValueCStr(f);
dst = StringValueCStr(t);
ra.src = StringValueCStr(f);
ra.dst = StringValueCStr(t);
#if defined __CYGWIN__
errno = 0;
#endif
if (rename(src, dst) < 0) {
if ((int)rb_thread_call_without_gvl(no_gvl_rename, &ra,
RUBY_UBF_IO, 0) < 0) {
int e = errno;
#if defined DOSISH
switch (e) {
-
    (1-1/1)