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
This commit is contained in:
normal 2018-04-20 21:38:27 +00:00
parent e72a86fc93
commit 475b4aa40b
7 changed files with 20 additions and 38 deletions

View file

@ -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;