Skip to content

Commit dac6757

Browse files
committed
Bugfix: bthread_interrupt was scheduled to the wrong tag group
1 parent 11c8ea9 commit dac6757

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/bthread/bthread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ void bthread_flush() {
368368
}
369369
}
370370

371-
int bthread_interrupt(bthread_t tid, bthread_tag_t tag) {
372-
return bthread::TaskGroup::interrupt(tid, bthread::get_task_control(), tag);
371+
int bthread_interrupt(bthread_t tid, bthread_tag_t /*tag*/) {
372+
return bthread::TaskGroup::interrupt(tid, bthread::get_task_control());
373373
}
374374

375375
int bthread_stop(bthread_t tid) {

src/bthread/butex.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ struct ButexBthreadWaiter : public ButexWaiter {
9797
Butex* initial_butex;
9898
TaskControl* control;
9999
const timespec* abstime;
100-
bthread_tag_t tag;
101100
};
102101

103102
// pthread_task or main_task allocates this structure on stack and queue it
@@ -320,7 +319,7 @@ int butex_wake(void* arg, bool nosignal) {
320319
}
321320
ButexBthreadWaiter* bbw = static_cast<ButexBthreadWaiter*>(front);
322321
unsleep_if_necessary(bbw, get_global_timer_thread());
323-
TaskGroup* g = get_task_group(bbw->control, bbw->tag);
322+
TaskGroup* g = get_task_group(bbw->control, bbw->task_meta->attr.tag);
324323
if (g == tls_task_group) {
325324
run_in_local_task_group(g, bbw->task_meta, nosignal);
326325
} else {
@@ -373,7 +372,7 @@ int butex_wake_n(void* arg, size_t n, bool nosignal) {
373372
bthread_waiters.tail()->value());
374373
w->RemoveFromList();
375374
unsleep_if_necessary(w, get_global_timer_thread());
376-
auto g = get_task_group(w->control, w->tag);
375+
auto g = get_task_group(w->control, w->task_meta->attr.tag);
377376
g->ready_to_run_general(w->task_meta, true);
378377
nwakeups[g->tag()] = g;
379378
++nwakeup;
@@ -384,7 +383,7 @@ int butex_wake_n(void* arg, size_t n, bool nosignal) {
384383
g->flush_nosignal_tasks_general();
385384
}
386385
}
387-
auto g = get_task_group(next->control, next->tag);
386+
auto g = get_task_group(next->control, next->task_meta->attr.tag);
388387
if (g == tls_task_group) {
389388
run_in_local_task_group(g, next->task_meta, nosignal);
390389
} else {
@@ -446,7 +445,7 @@ int butex_wake_except(void* arg, bthread_t excluded_bthread) {
446445
ButexBthreadWaiter* w = static_cast<ButexBthreadWaiter*>(bthread_waiters.tail()->value());
447446
w->RemoveFromList();
448447
unsleep_if_necessary(w, get_global_timer_thread());
449-
auto g = get_task_group(w->control, w->tag);
448+
auto g = get_task_group(w->control, w->task_meta->attr.tag);
450449
g->ready_to_run_general(w->task_meta, true);
451450
nwakeups[g->tag()] = g;
452451
++nwakeup;
@@ -489,11 +488,12 @@ int butex_requeue(void* arg, void* arg2) {
489488
}
490489
ButexBthreadWaiter* bbw = static_cast<ButexBthreadWaiter*>(front);
491490
unsleep_if_necessary(bbw, get_global_timer_thread());
492-
auto g = is_same_tag(bbw->tag) ? tls_task_group : NULL;
491+
auto g = is_same_tag(bbw->task_meta->attr.tag) ? tls_task_group : NULL;
493492
if (g) {
494493
TaskGroup::exchange(&g, bbw->task_meta);
495494
} else {
496-
bbw->control->choose_one_group(bbw->tag)->ready_to_run_remote(bbw->task_meta);
495+
g = bbw->control->choose_one_group(bbw->task_meta->attr.tag);
496+
g->ready_to_run_remote(bbw->task_meta);
497497
}
498498
return 1;
499499
}
@@ -531,7 +531,8 @@ inline bool erase_from_butex(ButexWaiter* bw, bool wakeup, WaiterState state) {
531531
if (erased && wakeup) {
532532
if (bw->tid) {
533533
ButexBthreadWaiter* bbw = static_cast<ButexBthreadWaiter*>(bw);
534-
get_task_group(bbw->control, bbw->tag)->ready_to_run_general(bbw->task_meta);
534+
auto g = get_task_group(bbw->control, bbw->task_meta->attr.tag);
535+
g->ready_to_run_general(bbw->task_meta);
535536
} else {
536537
ButexPthreadWaiter* pw = static_cast<ButexPthreadWaiter*>(bw);
537538
wakeup_pthread(pw);
@@ -691,7 +692,6 @@ int butex_wait(void* arg, int expected_value, const timespec* abstime, bool prep
691692
bbw.initial_butex = b;
692693
bbw.control = g->control();
693694
bbw.abstime = abstime;
694-
bbw.tag = g->tag();
695695

696696
if (abstime != NULL) {
697697
// Schedule timer before queueing. If the timer is triggered before

src/bthread/task_group.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ static int set_butex_waiter(bthread_t tid, ButexWaiter* w) {
10891089
// by race conditions.
10901090
// TODO: bthreads created by BTHREAD_ATTR_PTHREAD blocking on bthread_usleep()
10911091
// can't be interrupted.
1092-
int TaskGroup::interrupt(bthread_t tid, TaskControl* c, bthread_tag_t tag) {
1092+
int TaskGroup::interrupt(bthread_t tid, TaskControl* c) {
10931093
// Consume current_waiter in the TaskMeta, wake it up then set it back.
10941094
ButexWaiter* w = NULL;
10951095
uint64_t sleep_id = 0;
@@ -1118,7 +1118,7 @@ int TaskGroup::interrupt(bthread_t tid, TaskControl* c, bthread_tag_t tag) {
11181118
if (!c) {
11191119
return EINVAL;
11201120
}
1121-
c->choose_one_group(tag)->ready_to_run_remote(m);
1121+
c->choose_one_group(m->attr.tag)->ready_to_run_remote(m);
11221122
}
11231123
}
11241124
}

src/bthread/task_group.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class TaskGroup {
203203

204204
// Wake up blocking ops in the thread.
205205
// Returns 0 on success, errno otherwise.
206-
static int interrupt(bthread_t tid, TaskControl* c, bthread_tag_t tag);
206+
static int interrupt(bthread_t tid, TaskControl* c);
207207

208208
// Get the meta associate with the task.
209209
static TaskMeta* address_meta(bthread_t tid);

0 commit comments

Comments
 (0)