thread_pthread.c: rename rb_timer_* to ubf_timer_*
These functions will not be exported outside of thread_pthread.c and we need to clarify the timer here is used for ubf and not timeslice. [ruby-core:88475] [Misc #14937] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e4fd71d64d
commit
3dcf85e08e
@ -103,7 +103,7 @@ static int native_cond_timedwait(rb_nativethread_cond_t *, pthread_mutex_t *,
|
|||||||
static const struct timespec *sigwait_timeout(rb_thread_t *, int sigwait_fd,
|
static const struct timespec *sigwait_timeout(rb_thread_t *, int sigwait_fd,
|
||||||
const struct timespec *,
|
const struct timespec *,
|
||||||
int *drained_p);
|
int *drained_p);
|
||||||
static void rb_timer_disarm(void);
|
static void ubf_timer_disarm(void);
|
||||||
|
|
||||||
#define TIMER_THREAD_CREATED_P() (signal_self_pipe.owner_process == getpid())
|
#define TIMER_THREAD_CREATED_P() (signal_self_pipe.owner_process == getpid())
|
||||||
|
|
||||||
@ -168,8 +168,8 @@ gvl_acquire_common(rb_vm_t *vm, rb_thread_t *th)
|
|||||||
static struct timespec ts;
|
static struct timespec ts;
|
||||||
static int err = ETIMEDOUT;
|
static int err = ETIMEDOUT;
|
||||||
|
|
||||||
/* take over timing from timer */
|
/* take over wakeups from UBF_TIMER */
|
||||||
rb_timer_disarm();
|
ubf_timer_disarm();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* become designated timer thread to kick vm->gvl.acquired
|
* become designated timer thread to kick vm->gvl.acquired
|
||||||
@ -186,9 +186,8 @@ gvl_acquire_common(rb_vm_t *vm, rb_thread_t *th)
|
|||||||
ubf_wakeup_all_threads();
|
ubf_wakeup_all_threads();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Timeslice. We can't touch thread_destruct_lock here,
|
* Timeslice. Warning: the process may fork while this
|
||||||
* as the process may fork while this thread is contending
|
* thread is contending for GVL:
|
||||||
* for GVL:
|
|
||||||
*/
|
*/
|
||||||
if (vm->gvl.acquired) timer_thread_function();
|
if (vm->gvl.acquired) timer_thread_function();
|
||||||
}
|
}
|
||||||
@ -244,6 +243,10 @@ gvl_yield(rb_vm_t *vm, rb_thread_t *th)
|
|||||||
{
|
{
|
||||||
native_thread_data_t *next;
|
native_thread_data_t *next;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perhaps other threads are stuck in blocking region w/o GVL, too,
|
||||||
|
* (perhaps looping in io_close_fptr) so we kick them:
|
||||||
|
*/
|
||||||
ubf_wakeup_all_threads();
|
ubf_wakeup_all_threads();
|
||||||
rb_native_mutex_lock(&vm->gvl.lock);
|
rb_native_mutex_lock(&vm->gvl.lock);
|
||||||
next = gvl_release_common(vm);
|
next = gvl_release_common(vm);
|
||||||
@ -1248,7 +1251,7 @@ unregister_ubf_list(rb_thread_t *th)
|
|||||||
rb_native_mutex_lock(&ubf_list_lock);
|
rb_native_mutex_lock(&ubf_list_lock);
|
||||||
list_del_init(node);
|
list_del_init(node);
|
||||||
if (list_empty(&ubf_list_head) && !rb_signal_buff_size()) {
|
if (list_empty(&ubf_list_head) && !rb_signal_buff_size()) {
|
||||||
rb_timer_disarm();
|
ubf_timer_disarm();
|
||||||
}
|
}
|
||||||
rb_native_mutex_unlock(&ubf_list_lock);
|
rb_native_mutex_unlock(&ubf_list_lock);
|
||||||
}
|
}
|
||||||
@ -1365,7 +1368,7 @@ rb_thread_wakeup_timer_thread_fd(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_timer_arm(rb_pid_t current) /* async signal safe */
|
ubf_timer_arm(rb_pid_t current) /* async signal safe */
|
||||||
{
|
{
|
||||||
#if UBF_TIMER == UBF_TIMER_POSIX
|
#if UBF_TIMER == UBF_TIMER_POSIX
|
||||||
if (timer_posix.owner == current && !ATOMIC_CAS(timer_posix.armed, 0, 1)) {
|
if (timer_posix.owner == current && !ATOMIC_CAS(timer_posix.armed, 0, 1)) {
|
||||||
@ -1435,11 +1438,11 @@ rb_thread_wakeup_timer_thread(int sig)
|
|||||||
|
|
||||||
if (ec) {
|
if (ec) {
|
||||||
RUBY_VM_SET_TRAP_INTERRUPT(ec);
|
RUBY_VM_SET_TRAP_INTERRUPT(ec);
|
||||||
rb_timer_arm(current);
|
ubf_timer_arm(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sig == 0 && system_working > 0) {
|
else if (sig == 0 && system_working > 0) {
|
||||||
rb_timer_arm(current);
|
ubf_timer_arm(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1548,7 +1551,7 @@ native_set_another_thread_name(rb_nativethread_id_t thread_id, VALUE name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_timer_invalidate(void)
|
ubf_timer_invalidate(void)
|
||||||
{
|
{
|
||||||
#if UBF_TIMER == UBF_TIMER_PTHREAD
|
#if UBF_TIMER == UBF_TIMER_PTHREAD
|
||||||
CLOSE_INVALIDATE(timer_pthread.low[0]);
|
CLOSE_INVALIDATE(timer_pthread.low[0]);
|
||||||
@ -1557,7 +1560,7 @@ rb_timer_invalidate(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_timer_pthread_create(rb_pid_t current)
|
ubf_timer_pthread_create(rb_pid_t current)
|
||||||
{
|
{
|
||||||
#if UBF_TIMER == UBF_TIMER_PTHREAD
|
#if UBF_TIMER == UBF_TIMER_PTHREAD
|
||||||
int err;
|
int err;
|
||||||
@ -1577,7 +1580,7 @@ rb_timer_pthread_create(rb_pid_t current)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_timer_create(rb_pid_t current)
|
ubf_timer_create(rb_pid_t current)
|
||||||
{
|
{
|
||||||
#if UBF_TIMER == UBF_TIMER_POSIX
|
#if UBF_TIMER == UBF_TIMER_POSIX
|
||||||
# if defined(__sun)
|
# if defined(__sun)
|
||||||
@ -1610,25 +1613,25 @@ rb_thread_create_timer_thread(void)
|
|||||||
if (owner && owner != current) {
|
if (owner && owner != current) {
|
||||||
CLOSE_INVALIDATE(signal_self_pipe.normal[0]);
|
CLOSE_INVALIDATE(signal_self_pipe.normal[0]);
|
||||||
CLOSE_INVALIDATE(signal_self_pipe.normal[1]);
|
CLOSE_INVALIDATE(signal_self_pipe.normal[1]);
|
||||||
rb_timer_invalidate();
|
ubf_timer_invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setup_communication_pipe_internal(signal_self_pipe.normal) < 0) return;
|
if (setup_communication_pipe_internal(signal_self_pipe.normal) < 0) return;
|
||||||
|
|
||||||
if (owner != current) {
|
if (owner != current) {
|
||||||
/* validate pipe on this process */
|
/* validate pipe on this process */
|
||||||
rb_timer_create(current);
|
ubf_timer_create(current);
|
||||||
sigwait_th = THREAD_INVALID;
|
sigwait_th = THREAD_INVALID;
|
||||||
signal_self_pipe.owner_process = current;
|
signal_self_pipe.owner_process = current;
|
||||||
}
|
}
|
||||||
else if (UBF_TIMER == UBF_TIMER_PTHREAD) {
|
else if (UBF_TIMER == UBF_TIMER_PTHREAD) {
|
||||||
/* UBF_TIMER_PTHREAD needs to recreate after fork */
|
/* UBF_TIMER_PTHREAD needs to recreate after fork */
|
||||||
rb_timer_pthread_create(current);
|
ubf_timer_pthread_create(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_timer_disarm(void)
|
ubf_timer_disarm(void)
|
||||||
{
|
{
|
||||||
#if UBF_TIMER == UBF_TIMER_POSIX
|
#if UBF_TIMER == UBF_TIMER_POSIX
|
||||||
static const struct itimerspec zero;
|
static const struct itimerspec zero;
|
||||||
@ -1636,7 +1639,7 @@ rb_timer_disarm(void)
|
|||||||
|
|
||||||
if (LIKELY(armed) == 0) return;
|
if (LIKELY(armed) == 0) return;
|
||||||
switch (armed) {
|
switch (armed) {
|
||||||
case 1: return; /* rb_timer_arm was arming and will disarm itself */
|
case 1: return; /* ubf_timer_arm was arming and will disarm itself */
|
||||||
case 2:
|
case 2:
|
||||||
if (timer_settime(timer_posix.timerid, 0, &zero, 0))
|
if (timer_settime(timer_posix.timerid, 0, &zero, 0))
|
||||||
rb_bug_errno("timer_settime (disarm)", errno);
|
rb_bug_errno("timer_settime (disarm)", errno);
|
||||||
@ -1650,7 +1653,7 @@ rb_timer_disarm(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_timer_destroy(void)
|
ubf_timer_destroy(void)
|
||||||
{
|
{
|
||||||
#if UBF_TIMER == UBF_TIMER_PTHREAD
|
#if UBF_TIMER == UBF_TIMER_PTHREAD
|
||||||
rb_pid_t current = getpid();
|
rb_pid_t current = getpid();
|
||||||
@ -1658,7 +1661,7 @@ rb_timer_destroy(void)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
timer_pthread.owner = 0;
|
timer_pthread.owner = 0;
|
||||||
rb_timer_disarm();
|
ubf_timer_disarm();
|
||||||
rb_thread_wakeup_timer_thread_fd(timer_pthread.low[1]);
|
rb_thread_wakeup_timer_thread_fd(timer_pthread.low[1]);
|
||||||
err = pthread_join(timer_pthread.thid, 0);
|
err = pthread_join(timer_pthread.thid, 0);
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -1675,7 +1678,7 @@ native_stop_timer_thread(void)
|
|||||||
int stopped;
|
int stopped;
|
||||||
stopped = --system_working <= 0;
|
stopped = --system_working <= 0;
|
||||||
if (stopped)
|
if (stopped)
|
||||||
rb_timer_destroy();
|
ubf_timer_destroy();
|
||||||
|
|
||||||
if (TT_DEBUG) fprintf(stderr, "stop timer thread\n");
|
if (TT_DEBUG) fprintf(stderr, "stop timer thread\n");
|
||||||
return stopped;
|
return stopped;
|
||||||
@ -1818,7 +1821,7 @@ rb_sigwait_fd_get(const rb_thread_t *th)
|
|||||||
* no need to keep firing the timer if any thread is sleeping
|
* no need to keep firing the timer if any thread is sleeping
|
||||||
* on the signal self-pipe
|
* on the signal self-pipe
|
||||||
*/
|
*/
|
||||||
rb_timer_disarm();
|
ubf_timer_disarm();
|
||||||
|
|
||||||
if (ATOMIC_PTR_CAS(sigwait_th, THREAD_INVALID, th) == THREAD_INVALID) {
|
if (ATOMIC_PTR_CAS(sigwait_th, THREAD_INVALID, th) == THREAD_INVALID) {
|
||||||
return signal_self_pipe.normal[0];
|
return signal_self_pipe.normal[0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user