зеркало из https://github.com/github/ruby.git
win32.c: vm_exit_handler
* win32/win32.c (vm_exit_handler): separate exit handler for resources which must be released at exit of Ruby VM. * win32/win32.c (socklist_insert, constat_handle): install the VM exit handler. * gc.c (ENABLE_VM_OBJSPACE): no longer needs process global object space on Windows too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
fa326994ae
Коммит
e33b1690d0
|
@ -844,7 +844,8 @@ compile.$(OBJEXT): {$(VPATH)}opt_sc.inc {$(VPATH)}optunifs.inc
|
|||
|
||||
win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}win32/file.h \
|
||||
{$(VPATH)}dln.h {$(VPATH)}dln_find.c {$(VPATH)}encindex.h \
|
||||
{$(VPATH)}internal.h {$(VPATH)}util.h $(RUBY_H_INCLUDES) $(PLATFORM_D)
|
||||
{$(VPATH)}internal.h {$(VPATH)}util.h $(RUBY_H_INCLUDES) \
|
||||
{$(VPATH)}vm.h $(PLATFORM_D)
|
||||
win32/file.$(OBJEXT): {$(VPATH)}win32/file.c {$(VPATH)}win32/file.h \
|
||||
$(RUBY_H_INCLUDES) $(PLATFORM_D)
|
||||
|
||||
|
|
11
gc.c
11
gc.c
|
@ -719,16 +719,7 @@ struct heap_page {
|
|||
#endif
|
||||
|
||||
#ifndef ENABLE_VM_OBJSPACE
|
||||
# ifdef _WIN32
|
||||
/*
|
||||
* TODO: object space independent st_table.
|
||||
* socklist and conlist will be freed exit_handler(), after object
|
||||
* space destruction.
|
||||
*/
|
||||
# define ENABLE_VM_OBJSPACE 0
|
||||
# else
|
||||
# define ENABLE_VM_OBJSPACE 1
|
||||
# endif
|
||||
# define ENABLE_VM_OBJSPACE 1
|
||||
#endif
|
||||
|
||||
/* Aliases */
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <mswsock.h>
|
||||
#endif
|
||||
#include "ruby/win32.h"
|
||||
#include "ruby/vm.h"
|
||||
#include "win32/dir.h"
|
||||
#include "win32/file.h"
|
||||
#include "internal.h"
|
||||
|
@ -689,7 +690,7 @@ rtc_error_handler(int e, const char *src, int line, const char *exe, const char
|
|||
#endif
|
||||
|
||||
static CRITICAL_SECTION select_mutex;
|
||||
static int NtSocketsInitialized = 0;
|
||||
#define NtSocketsInitialized 1
|
||||
static st_table *socklist = NULL;
|
||||
static st_table *conlist = NULL;
|
||||
#define conlist_disabled ((st_table *)-1)
|
||||
|
@ -730,21 +731,38 @@ exit_handler(void)
|
|||
{
|
||||
if (NtSocketsInitialized) {
|
||||
WSACleanup();
|
||||
if (socklist) {
|
||||
st_free_table(socklist);
|
||||
socklist = NULL;
|
||||
}
|
||||
DeleteCriticalSection(&select_mutex);
|
||||
NtSocketsInitialized = 0;
|
||||
}
|
||||
if (uenvarea) {
|
||||
free(uenvarea);
|
||||
uenvarea = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
static void
|
||||
vm_exit_handler(ruby_vm_t *vm)
|
||||
{
|
||||
if (socklist) {
|
||||
st_free_table(socklist);
|
||||
socklist = NULL;
|
||||
}
|
||||
if (conlist && conlist != conlist_disabled) {
|
||||
st_foreach(conlist, free_conlist, 0);
|
||||
st_free_table(conlist);
|
||||
conlist = NULL;
|
||||
}
|
||||
if (uenvarea) {
|
||||
free(uenvarea);
|
||||
uenvarea = NULL;
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
static void
|
||||
install_vm_exit_handler(void)
|
||||
{
|
||||
static bool installed = 0;
|
||||
|
||||
if (!installed) {
|
||||
ruby_vm_at_exit(vm_exit_handler);
|
||||
installed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -767,7 +785,7 @@ StartSockets(void)
|
|||
|
||||
InitializeCriticalSection(&select_mutex);
|
||||
|
||||
NtSocketsInitialized = 1;
|
||||
atexit(exit_handler);
|
||||
}
|
||||
|
||||
#define MAKE_SOCKDATA(af, fl) ((int)((((int)af)<<4)|((fl)&0xFFFF)))
|
||||
|
@ -778,8 +796,10 @@ StartSockets(void)
|
|||
static inline int
|
||||
socklist_insert(SOCKET sock, int flag)
|
||||
{
|
||||
if (!socklist)
|
||||
if (!socklist) {
|
||||
socklist = st_init_numtable();
|
||||
install_vm_exit_handler();
|
||||
}
|
||||
return st_insert(socklist, (st_data_t)sock, (st_data_t)flag);
|
||||
}
|
||||
|
||||
|
@ -857,8 +877,6 @@ rb_w32_sysinit(int *argc, char ***argv)
|
|||
|
||||
init_stdhandle();
|
||||
|
||||
atexit(exit_handler);
|
||||
|
||||
// Initialize Winsock
|
||||
StartSockets();
|
||||
}
|
||||
|
@ -6560,6 +6578,7 @@ constat_handle(HANDLE h)
|
|||
return NULL;
|
||||
}
|
||||
conlist = st_init_numtable();
|
||||
install_vm_exit_handler();
|
||||
}
|
||||
else if (conlist == conlist_disabled) {
|
||||
return NULL;
|
||||
|
|
Загрузка…
Ссылка в новой задаче