thread_pthread.c: eliminate timer thread by restructuring GVL

This reverts commit 194a6a2c68 (r64203).

Race conditions which caused the original reversion will be fixed
in the subsequent commit.

[ruby-core:88360] [Misc #14937]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2018-08-13 21:34:20 +00:00
parent 4d2e0fffb0
commit 48b6bd74e2
11 changed files with 738 additions and 576 deletions

View file

@ -22,7 +22,19 @@ typedef pthread_cond_t rb_nativethread_cond_t;
typedef struct native_thread_data_struct {
struct list_node ubf_list;
rb_nativethread_cond_t sleep_cond;
#if defined(__GLIBC__) || defined(__FreeBSD__)
union
#else
/*
* assume the platform condvars are badly implemented and have a
* "memory" of which mutex they're associated with
*/
struct
#endif
{
rb_nativethread_cond_t intr; /* th->interrupt_lock */
rb_nativethread_cond_t gvlq; /* vm->gvl.lock */
} cond;
} native_thread_data_t;
#undef except
@ -32,12 +44,12 @@ typedef struct native_thread_data_struct {
typedef struct rb_global_vm_lock_struct {
/* fast path */
unsigned long acquired;
const struct rb_thread_struct *acquired;
rb_nativethread_lock_t lock;
/* slow path */
volatile unsigned long waiting;
rb_nativethread_cond_t cond;
struct list_head waitq;
const struct rb_thread_struct *timer;
/* yield */
rb_nativethread_cond_t switch_cond;