mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread_sync.c: common wakeup_{one,all} implementation
This let us avoid looping in rb_szqueue_max_set, saves us some lines of code and reduces binary size slightly (numbers from 32-bit x86): text data bss dec hex filename before: 91272 392 156 91820 166ac thread.o after: 91200 392 156 91748 16664 thread.o Inspiration from this taken from the FUTEX_WAKE op of the Linux futex(2) syscall. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
84859fd2d2
commit
70d6c1a102
1 changed files with 11 additions and 16 deletions
|
@ -12,8 +12,8 @@ struct sync_waiter {
|
||||||
|
|
||||||
#define MUTEX_ALLOW_TRAP FL_USER1
|
#define MUTEX_ALLOW_TRAP FL_USER1
|
||||||
|
|
||||||
static int
|
static void
|
||||||
wakeup_one(struct list_head *head)
|
sync_wakeup(struct list_head *head, long max)
|
||||||
{
|
{
|
||||||
struct sync_waiter *cur = 0, *next;
|
struct sync_waiter *cur = 0, *next;
|
||||||
|
|
||||||
|
@ -22,24 +22,21 @@ wakeup_one(struct list_head *head)
|
||||||
if (cur->th->status != THREAD_KILLED) {
|
if (cur->th->status != THREAD_KILLED) {
|
||||||
rb_threadptr_interrupt(cur->th);
|
rb_threadptr_interrupt(cur->th);
|
||||||
cur->th->status = THREAD_RUNNABLE;
|
cur->th->status = THREAD_RUNNABLE;
|
||||||
return TRUE;
|
if (--max == 0) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wakeup_one(struct list_head *head)
|
||||||
|
{
|
||||||
|
sync_wakeup(head, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wakeup_all(struct list_head *head)
|
wakeup_all(struct list_head *head)
|
||||||
{
|
{
|
||||||
struct sync_waiter *cur = 0, *next;
|
sync_wakeup(head, LONG_MAX);
|
||||||
|
|
||||||
list_for_each_safe(head, cur, next, node) {
|
|
||||||
list_del_init(&cur->node);
|
|
||||||
if (cur->th->status != THREAD_KILLED) {
|
|
||||||
rb_threadptr_interrupt(cur->th);
|
|
||||||
cur->th->status = THREAD_RUNNABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mutex */
|
/* Mutex */
|
||||||
|
@ -1112,9 +1109,7 @@ rb_szqueue_max_set(VALUE self, VALUE vmax)
|
||||||
diff = max - sq->max;
|
diff = max - sq->max;
|
||||||
}
|
}
|
||||||
sq->max = max;
|
sq->max = max;
|
||||||
while (diff-- > 0 && wakeup_one(szqueue_pushq(sq))) {
|
sync_wakeup(szqueue_pushq(sq), diff);
|
||||||
/* keep waking more up */
|
|
||||||
}
|
|
||||||
return vmax;
|
return vmax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue