Enclose crtitical sections in thread_exclusive
block
This commit is contained in:
parent
d10b535806
commit
1a00402987
@ -704,6 +704,10 @@ 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 char *uenvarea;
|
static char *uenvarea;
|
||||||
|
|
||||||
/* License: Ruby's */
|
/* License: Ruby's */
|
||||||
@ -728,13 +732,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)
|
||||||
{
|
{
|
||||||
EnterCriticalSection(&conlist_mutex);
|
thread_exclusive(conlist) {
|
||||||
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 */
|
||||||
@ -817,13 +821,13 @@ socklist_insert(SOCKET sock, int flag)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
EnterCriticalSection(&socklist_mutex);
|
thread_exclusive(socklist) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -833,18 +837,14 @@ 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;
|
int ret = 0;
|
||||||
|
|
||||||
EnterCriticalSection(&socklist_mutex);
|
thread_exclusive(socklist) {
|
||||||
if (socklist) {
|
if (!socklist) continue;
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -855,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;
|
int ret = 0;
|
||||||
|
|
||||||
EnterCriticalSection(&socklist_mutex);
|
thread_exclusive(socklist) {
|
||||||
if (socklist) {
|
if (!socklist) continue;
|
||||||
key = (st_data_t)*sockp;
|
key = (st_data_t)*sockp;
|
||||||
if (flagp)
|
if (flagp)
|
||||||
data = (st_data_t)*flagp;
|
data = (st_data_t)*flagp;
|
||||||
@ -869,10 +869,6 @@ socklist_delete(SOCKET *sockp, int *flagp)
|
|||||||
*flagp = (int)data;
|
*flagp = (int)data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
LeaveCriticalSection(&socklist_mutex);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -2914,7 +2910,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3118,9 +3114,9 @@ do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
RUBY_CRITICAL {
|
RUBY_CRITICAL {
|
||||||
EnterCriticalSection(&select_mutex);
|
thread_exclusive(select) {
|
||||||
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;
|
||||||
@ -6593,19 +6589,19 @@ static struct constat *
|
|||||||
constat_handle(HANDLE h)
|
constat_handle(HANDLE h)
|
||||||
{
|
{
|
||||||
st_data_t data;
|
st_data_t data;
|
||||||
struct constat *p;
|
struct constat *p = NULL;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@ -6622,11 +6618,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6636,16 +6627,12 @@ constat_reset(HANDLE h)
|
|||||||
{
|
{
|
||||||
st_data_t data;
|
st_data_t data;
|
||||||
struct constat *p;
|
struct constat *p;
|
||||||
|
thread_exclusive(conlist) {
|
||||||
EnterCriticalSection(&conlist_mutex);
|
if (!conlist || conlist == conlist_disabled) continue;
|
||||||
if (
|
if (!st_lookup(conlist, (st_data_t)h, &data)) continue;
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user