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
1
# rename file
2
require 'tempfile'
3

  
4
max = 100_000
5
tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ]
6
a, b = tmp.map { |x| x.path }
7
max.times do
8
  File.rename(a, b)
9
  File.rename(b, a)
10
end
11
tmp.each { |t| t.close! }
file.c
2873 2873
    return apply2files(unlink_internal, argc, argv, 0);
2874 2874
}
2875 2875

  
2876
struct rename_args {
2877
    const char *src;
2878
    const char *dst;
2879
};
2880

  
2881
static void *
2882
no_gvl_rename(void *ptr)
2883
{
2884
    struct rename_args *ra = ptr;
2885

  
2886
    return (void *)rename(ra->src, ra->dst);
2887
}
2888

  
2876 2889
/*
2877 2890
 *  call-seq:
2878 2891
 *     File.rename(old_name, new_name)   -> 0
......
2886 2899
static VALUE
2887 2900
rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
2888 2901
{
2889
    const char *src, *dst;
2902
    struct rename_args ra;
2890 2903
    VALUE f, t;
2891 2904

  
2892 2905
    FilePathValue(from);
2893 2906
    FilePathValue(to);
2894 2907
    f = rb_str_encode_ospath(from);
2895 2908
    t = rb_str_encode_ospath(to);
2896
    src = StringValueCStr(f);
2897
    dst = StringValueCStr(t);
2909
    ra.src = StringValueCStr(f);
2910
    ra.dst = StringValueCStr(t);
2898 2911
#if defined __CYGWIN__
2899 2912
    errno = 0;
2900 2913
#endif
2901
    if (rename(src, dst) < 0) {
2914
    if ((int)rb_thread_call_without_gvl(no_gvl_rename, &ra,
2915
					 RUBY_UBF_IO, 0) < 0) {
2902 2916
	int e = errno;
2903 2917
#if defined DOSISH
2904 2918
	switch (e) {
2905
-