Project

General

Profile

Bug #13941 ยป 0001-Release-gvl-while-doing-f-stat.patch

Patch to the `file.c` - graywolf (Gray Wolf), 09/26/2017 12:10 AM

View differences:

file.c
27 27
#include "internal.h"
28 28
#include "ruby/io.h"
29 29
#include "ruby/util.h"
30
#include "ruby/thread.h"
30 31
#include "dln.h"
31 32
#include "encindex.h"
32 33

  
......
1022 1023
    return str;
1023 1024
}
1024 1025

  
1026
typedef struct no_gvl_fstat_data {
1027
    int fd;
1028
    struct stat * st;
1029
    int result;
1030
} no_gvl_fstat_data;
1031

  
1032
static void * no_gvl_fstat(void * data)
1033
{
1034
    ((no_gvl_fstat_data *) data)->result = fstat(
1035
	((no_gvl_fstat_data *) data)->fd,
1036
	((no_gvl_fstat_data *) data)->st
1037
    );
1038
    return NULL;
1039
}
1040

  
1041
typedef struct no_gvl_stat_data {
1042
    const char * path;
1043
    struct stat * st;
1044
    int result;
1045
} no_gvl_stat_data;
1046

  
1047
static void * no_gvl_stat(void * data)
1048
{
1049
    ((no_gvl_stat_data *) data)->result = STAT(
1050
	((no_gvl_stat_data *) data)->path,
1051
	((no_gvl_stat_data *) data)->st
1052
    );
1053
    return NULL;
1054
}
1055

  
1056

  
1025 1057
static int
1026 1058
rb_stat(VALUE file, struct stat *st)
1027 1059
{
1028 1060
    VALUE tmp;
1061
    no_gvl_fstat_data fstat_data;
1062
    no_gvl_stat_data stat_data;
1029 1063

  
1030 1064
    tmp = rb_check_convert_type_with_id(file, T_FILE, "IO", idTo_io);
1031 1065
    if (!NIL_P(tmp)) {
1032 1066
	rb_io_t *fptr;
1033 1067

  
1034 1068
	GetOpenFile(tmp, fptr);
1035
	return fstat(fptr->fd, st);
1069
	fstat_data.fd = fptr->fd;
1070
	fstat_data.st = st;
1071
	rb_thread_call_without_gvl(
1072
	    no_gvl_fstat,
1073
	    (void *) &fstat_data,
1074
	    RUBY_UBF_IO,
1075
	    NULL
1076
	);
1077
	return fstat_data.result;
1036 1078
    }
1037 1079
    FilePathValue(file);
1038 1080
    file = rb_str_encode_ospath(file);
1039
    return STAT(StringValueCStr(file), st);
1081
    stat_data.path = StringValueCStr(file);
1082
    stat_data.st = st;
1083
    rb_thread_call_without_gvl(
1084
	no_gvl_stat,
1085
	(void *) &stat_data,
1086
	RUBY_UBF_IO,
1087
	NULL
1088
    );
1089
    return stat_data.result;
1040 1090
}
1041 1091

  
1042 1092
#ifdef _WIN32
......
6263 6313
    rb_define_method(rb_cStat, "setgid?",  rb_stat_sgid, 0);
6264 6314
    rb_define_method(rb_cStat, "sticky?",  rb_stat_sticky, 0);
6265 6315
}
6316

  
6317
/* vim: set ts=8 sw=4 noexpandtab: */
6266
-