1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Revert "Enclose crtitical sections in thread_exclusive block"

19cc24b34b and fixups.
This commit is contained in:
Nobuyoshi Nakada 2021-02-24 03:12:19 +09:00
parent 7563d542d6
commit a12e950816
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 75 additions and 73 deletions

View file

@ -263,7 +263,6 @@ ruby_set_debug_option(const char *str)
} }
#if RUBY_DEVEL #if RUBY_DEVEL
#undef getenv
// RUBY_DEBUG_LOG features // RUBY_DEBUG_LOG features
// See vm_debug.h comments for details. // See vm_debug.h comments for details.

View file

@ -704,11 +704,6 @@ static CRITICAL_SECTION conlist_mutex;
static st_table *conlist = NULL; static st_table *conlist = NULL;
#define conlist_disabled ((st_table *)-1) #define conlist_disabled ((st_table *)-1)
#define thread_exclusive(obj) \
for (bool first = (EnterCriticalSection(&obj##_mutex), true); \
first; first = (LeaveCriticalSection(&obj##_mutex), false))
static CRITICAL_SECTION uenvarea_mutex;
static char *uenvarea; static char *uenvarea;
/* License: Ruby's */ /* License: Ruby's */
@ -733,13 +728,13 @@ free_conlist(st_data_t key, st_data_t val, st_data_t arg)
static void static void
constat_delete(HANDLE h) constat_delete(HANDLE h)
{ {
thread_exclusive(conlist) { EnterCriticalSection(&conlist_mutex);
if (conlist && conlist != conlist_disabled) { if (conlist && conlist != conlist_disabled) {
st_data_t key = (st_data_t)h, val; st_data_t key = (st_data_t)h, val;
st_delete(conlist, &key, &val); st_delete(conlist, &key, &val);
xfree((struct constat *)val); xfree((struct constat *)val);
} }
} LeaveCriticalSection(&conlist_mutex);
} }
/* License: Ruby's */ /* License: Ruby's */
@ -750,13 +745,10 @@ exit_handler(void)
DeleteCriticalSection(&select_mutex); DeleteCriticalSection(&select_mutex);
DeleteCriticalSection(&socklist_mutex); DeleteCriticalSection(&socklist_mutex);
DeleteCriticalSection(&conlist_mutex); DeleteCriticalSection(&conlist_mutex);
thread_exclusive(uenvarea) {
if (uenvarea) { if (uenvarea) {
free(uenvarea); free(uenvarea);
uenvarea = NULL; uenvarea = NULL;
} }
}
DeleteCriticalSection(&uenvarea_mutex);
} }
/* License: Ruby's */ /* License: Ruby's */
@ -825,13 +817,13 @@ socklist_insert(SOCKET sock, int flag)
{ {
int ret; int ret;
thread_exclusive(socklist) { EnterCriticalSection(&socklist_mutex);
if (!socklist) { if (!socklist) {
socklist = st_init_numtable(); socklist = st_init_numtable();
install_vm_exit_handler(); install_vm_exit_handler();
} }
ret = st_insert(socklist, (st_data_t)sock, (st_data_t)flag); ret = st_insert(socklist, (st_data_t)sock, (st_data_t)flag);
} LeaveCriticalSection(&socklist_mutex);
return ret; return ret;
} }
@ -841,14 +833,18 @@ static inline int
socklist_lookup(SOCKET sock, int *flagp) socklist_lookup(SOCKET sock, int *flagp)
{ {
st_data_t data; st_data_t data;
int ret = 0; int ret;
thread_exclusive(socklist) { EnterCriticalSection(&socklist_mutex);
if (!socklist) continue; if (socklist) {
ret = st_lookup(socklist, (st_data_t)sock, (st_data_t *)&data); ret = st_lookup(socklist, (st_data_t)sock, (st_data_t *)&data);
if (ret && flagp) if (ret && flagp)
*flagp = (int)data; *flagp = (int)data;
} }
else {
ret = 0;
}
LeaveCriticalSection(&socklist_mutex);
return ret; return ret;
} }
@ -859,10 +855,10 @@ socklist_delete(SOCKET *sockp, int *flagp)
{ {
st_data_t key; st_data_t key;
st_data_t data; st_data_t data;
int ret = 0; int ret;
thread_exclusive(socklist) { EnterCriticalSection(&socklist_mutex);
if (!socklist) continue; if (socklist) {
key = (st_data_t)*sockp; key = (st_data_t)*sockp;
if (flagp) if (flagp)
data = (st_data_t)*flagp; data = (st_data_t)*flagp;
@ -873,6 +869,10 @@ socklist_delete(SOCKET *sockp, int *flagp)
*flagp = (int)data; *flagp = (int)data;
} }
} }
else {
ret = 0;
}
LeaveCriticalSection(&socklist_mutex);
return ret; return ret;
} }
@ -895,7 +895,6 @@ rb_w32_sysinit(int *argc, char ***argv)
#endif #endif
SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX); SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX);
InitializeCriticalSection(&uenvarea_mutex);
get_version(); get_version();
// //
@ -2915,7 +2914,7 @@ rb_w32_fdisset(int fd, fd_set *set)
SOCKET s = TO_SOCKET(fd); SOCKET s = TO_SOCKET(fd);
if (s == (SOCKET)INVALID_HANDLE_VALUE) if (s == (SOCKET)INVALID_HANDLE_VALUE)
return 0; return 0;
RUBY_CRITICAL {ret = __WSAFDIsSet(s, set);} RUBY_CRITICAL(ret = __WSAFDIsSet(s, set));
return ret; return ret;
} }
@ -3119,9 +3118,9 @@ do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
} }
else { else {
RUBY_CRITICAL { RUBY_CRITICAL {
thread_exclusive(select) { EnterCriticalSection(&select_mutex);
r = select(nfds, rd, wr, ex, timeout); r = select(nfds, rd, wr, ex, timeout);
} LeaveCriticalSection(&select_mutex);
if (r == SOCKET_ERROR) { if (r == SOCKET_ERROR) {
errno = map_errno(WSAGetLastError()); errno = map_errno(WSAGetLastError());
r = -1; r = -1;
@ -5265,12 +5264,11 @@ w32_getenv(const char *name, UINT cp)
{ {
WCHAR *wenvarea, *wenv; WCHAR *wenvarea, *wenv;
int len = strlen(name); int len = strlen(name);
char *env = NULL; char *env;
int wlen; int wlen;
if (len == 0) return NULL; if (len == 0) return NULL;
thread_exclusive(uenvarea) {
if (uenvarea) { if (uenvarea) {
free(uenvarea); free(uenvarea);
uenvarea = NULL; uenvarea = NULL;
@ -5278,24 +5276,20 @@ w32_getenv(const char *name, UINT cp)
wenvarea = GetEnvironmentStringsW(); wenvarea = GetEnvironmentStringsW();
if (!wenvarea) { if (!wenvarea) {
map_errno(GetLastError()); map_errno(GetLastError());
continue; return NULL;
} }
for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1) for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
wlen += lstrlenW(wenv) + 1; wlen += lstrlenW(wenv) + 1;
uenvarea = wstr_to_mbstr(cp, wenvarea, wlen, NULL); uenvarea = wstr_to_mbstr(cp, wenvarea, wlen, NULL);
FreeEnvironmentStringsW(wenvarea); FreeEnvironmentStringsW(wenvarea);
if (!uenvarea) if (!uenvarea)
continue; return NULL;
for (env = uenvarea; *env; env += strlen(env) + 1) { for (env = uenvarea; *env; env += strlen(env) + 1)
if (strncasecmp(env, name, len) == 0 && *(env + len) == '=') { if (strncasecmp(env, name, len) == 0 && *(env + len) == '=')
env += len + 1; return env + len + 1;
break;
}
}
}
return env; return NULL;
} }
/* License: Ruby's */ /* License: Ruby's */
@ -6599,19 +6593,19 @@ static struct constat *
constat_handle(HANDLE h) constat_handle(HANDLE h)
{ {
st_data_t data; st_data_t data;
struct constat *p = NULL; struct constat *p;
thread_exclusive(conlist) {
EnterCriticalSection(&conlist_mutex);
if (!conlist) { if (!conlist) {
if (console_emulator_p()) { if (console_emulator_p()) {
conlist = conlist_disabled; conlist = conlist_disabled;
continue;
} }
else {
conlist = st_init_numtable(); conlist = st_init_numtable();
install_vm_exit_handler(); install_vm_exit_handler();
} }
else if (conlist == conlist_disabled) {
continue;
} }
if (conlist != conlist_disabled) {
if (st_lookup(conlist, (st_data_t)h, &data)) { if (st_lookup(conlist, (st_data_t)h, &data)) {
p = (struct constat *)data; p = (struct constat *)data;
} }
@ -6628,6 +6622,11 @@ constat_handle(HANDLE h)
st_insert(conlist, (st_data_t)h, (st_data_t)p); st_insert(conlist, (st_data_t)h, (st_data_t)p);
} }
} }
else {
p = NULL;
}
LeaveCriticalSection(&conlist_mutex);
return p; return p;
} }
@ -6637,12 +6636,16 @@ constat_reset(HANDLE h)
{ {
st_data_t data; st_data_t data;
struct constat *p; struct constat *p;
thread_exclusive(conlist) {
if (!conlist || conlist == conlist_disabled) continue; EnterCriticalSection(&conlist_mutex);
if (!st_lookup(conlist, (st_data_t)h, &data)) continue; if (
conlist && conlist != conlist_disabled &&
st_lookup(conlist, (st_data_t)h, &data)
) {
p = (struct constat *)data; p = (struct constat *)data;
p->vt100.state = constat_init; p->vt100.state = constat_init;
} }
LeaveCriticalSection(&conlist_mutex);
} }
#define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY) #define FOREGROUND_MASK (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)