mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
fa326994ae
commit
e33b1690d0
3 changed files with 35 additions and 24 deletions
|
@ -844,7 +844,8 @@ compile.$(OBJEXT): {$(VPATH)}opt_sc.inc {$(VPATH)}optunifs.inc
|
||||||
|
|
||||||
win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}win32/file.h \
|
win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}win32/file.h \
|
||||||
{$(VPATH)}dln.h {$(VPATH)}dln_find.c {$(VPATH)}encindex.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 \
|
win32/file.$(OBJEXT): {$(VPATH)}win32/file.c {$(VPATH)}win32/file.h \
|
||||||
$(RUBY_H_INCLUDES) $(PLATFORM_D)
|
$(RUBY_H_INCLUDES) $(PLATFORM_D)
|
||||||
|
|
||||||
|
|
9
gc.c
9
gc.c
|
@ -719,16 +719,7 @@ struct heap_page {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_VM_OBJSPACE
|
#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
|
# define ENABLE_VM_OBJSPACE 1
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Aliases */
|
/* Aliases */
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include <mswsock.h>
|
#include <mswsock.h>
|
||||||
#endif
|
#endif
|
||||||
#include "ruby/win32.h"
|
#include "ruby/win32.h"
|
||||||
|
#include "ruby/vm.h"
|
||||||
#include "win32/dir.h"
|
#include "win32/dir.h"
|
||||||
#include "win32/file.h"
|
#include "win32/file.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
@ -689,7 +690,7 @@ rtc_error_handler(int e, const char *src, int line, const char *exe, const char
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static CRITICAL_SECTION select_mutex;
|
static CRITICAL_SECTION select_mutex;
|
||||||
static int NtSocketsInitialized = 0;
|
#define NtSocketsInitialized 1
|
||||||
static st_table *socklist = NULL;
|
static st_table *socklist = NULL;
|
||||||
static st_table *conlist = NULL;
|
static st_table *conlist = NULL;
|
||||||
#define conlist_disabled ((st_table *)-1)
|
#define conlist_disabled ((st_table *)-1)
|
||||||
|
@ -730,21 +731,38 @@ exit_handler(void)
|
||||||
{
|
{
|
||||||
if (NtSocketsInitialized) {
|
if (NtSocketsInitialized) {
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
DeleteCriticalSection(&select_mutex);
|
||||||
|
}
|
||||||
|
if (uenvarea) {
|
||||||
|
free(uenvarea);
|
||||||
|
uenvarea = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* License: Ruby's */
|
||||||
|
static void
|
||||||
|
vm_exit_handler(ruby_vm_t *vm)
|
||||||
|
{
|
||||||
if (socklist) {
|
if (socklist) {
|
||||||
st_free_table(socklist);
|
st_free_table(socklist);
|
||||||
socklist = NULL;
|
socklist = NULL;
|
||||||
}
|
}
|
||||||
DeleteCriticalSection(&select_mutex);
|
|
||||||
NtSocketsInitialized = 0;
|
|
||||||
}
|
|
||||||
if (conlist && conlist != conlist_disabled) {
|
if (conlist && conlist != conlist_disabled) {
|
||||||
st_foreach(conlist, free_conlist, 0);
|
st_foreach(conlist, free_conlist, 0);
|
||||||
st_free_table(conlist);
|
st_free_table(conlist);
|
||||||
conlist = NULL;
|
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);
|
InitializeCriticalSection(&select_mutex);
|
||||||
|
|
||||||
NtSocketsInitialized = 1;
|
atexit(exit_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAKE_SOCKDATA(af, fl) ((int)((((int)af)<<4)|((fl)&0xFFFF)))
|
#define MAKE_SOCKDATA(af, fl) ((int)((((int)af)<<4)|((fl)&0xFFFF)))
|
||||||
|
@ -778,8 +796,10 @@ StartSockets(void)
|
||||||
static inline int
|
static inline int
|
||||||
socklist_insert(SOCKET sock, int flag)
|
socklist_insert(SOCKET sock, int flag)
|
||||||
{
|
{
|
||||||
if (!socklist)
|
if (!socklist) {
|
||||||
socklist = st_init_numtable();
|
socklist = st_init_numtable();
|
||||||
|
install_vm_exit_handler();
|
||||||
|
}
|
||||||
return st_insert(socklist, (st_data_t)sock, (st_data_t)flag);
|
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();
|
init_stdhandle();
|
||||||
|
|
||||||
atexit(exit_handler);
|
|
||||||
|
|
||||||
// Initialize Winsock
|
// Initialize Winsock
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
|
@ -6560,6 +6578,7 @@ constat_handle(HANDLE h)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
conlist = st_init_numtable();
|
conlist = st_init_numtable();
|
||||||
|
install_vm_exit_handler();
|
||||||
}
|
}
|
||||||
else if (conlist == conlist_disabled) {
|
else if (conlist == conlist_disabled) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in a new issue