From 475b4aa40b6cf83e57176a063d368d55bf779e7c Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 20 Apr 2018 21:38:27 +0000 Subject: simplify altstack and enable reuse with thread cache Instead of allocating and registering the altstack in different places, do it together to reduce code and improve readability. When thread cache is enabled, storing altstack in rb_thread_t is wasteful and we may reuse altstack in the same pthread. This also lets us clearly allow use of xmalloc to allow GC to recover from ENOMEM. [ruby-core:85621] [Feature #14487] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_core.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'vm_core.h') diff --git a/vm_core.h b/vm_core.h index 5fa11487f7..a5ba1900c1 100644 --- a/vm_core.h +++ b/vm_core.h @@ -101,7 +101,13 @@ #endif #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__) -#define USE_SIGALTSTACK +# define USE_SIGALTSTACK +void *rb_register_sigaltstack(void); +# define RB_ALTSTACK_INIT(var) var = rb_register_sigaltstack() +# define RB_ALTSTACK_FREE(var) xfree(var) +#else /* noop */ +# define RB_ALTSTACK_INIT(var) +# define RB_ALTSTACK_FREE(var) #endif /*****************/ @@ -538,6 +544,9 @@ typedef struct rb_vm_struct { struct rb_thread_struct *main_thread; struct rb_thread_struct *running_thread; +#ifdef USE_SIGALTSTACK + void *main_altstack; +#endif rb_serial_t fork_gen; struct list_head waiting_fds; /* <=> struct waiting_fd */ @@ -883,9 +892,6 @@ typedef struct rb_thread_struct { /* misc */ unsigned int abort_on_exception: 1; unsigned int report_on_exception: 1; -#ifdef USE_SIGALTSTACK - void *altstack; -#endif uint32_t running_time_us; /* 12500..800000 */ VALUE name; } rb_thread_t; -- cgit v1.2.3