Skip to content

Commit

Permalink
Yield thread group leader *Task in TaskSet.ForEachThreadGroup.
Browse files Browse the repository at this point in the history
This makes this function usable from outside of the `kernel` package
without needing to call `tg.Leader()` (which requires a lock that
`TaskSet.ForEachThreadGroup` already acquires).

PiperOrigin-RevId: 720734630
  • Loading branch information
EtiennePerot authored and gvisor-bot committed Jan 30, 2025
1 parent 8bdf76c commit fe9da19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/sentry/kernel/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (pg *ProcessGroup) handleOrphan() {

// See if there are any stopped jobs.
hasStopped := false
pg.originator.pidns.owner.forEachThreadGroupLocked(func(tg *ThreadGroup) {
pg.originator.pidns.owner.forEachThreadGroupLocked(func(tg *ThreadGroup, _ *Task) {
if tg.processGroup != pg {
return
}
Expand All @@ -213,13 +213,13 @@ func (pg *ProcessGroup) handleOrphan() {
}

// Deliver appropriate signals to all thread groups.
pg.originator.pidns.owner.forEachThreadGroupLocked(func(tg *ThreadGroup) {
pg.originator.pidns.owner.forEachThreadGroupLocked(func(tg *ThreadGroup, tgLeader *Task) {
if tg.processGroup != pg {
return
}
tg.signalHandlers.mu.NestedLock(signalHandlersLockTg)
tg.leader.sendSignalLocked(SignalInfoPriv(linux.SIGHUP), true /* group */)
tg.leader.sendSignalLocked(SignalInfoPriv(linux.SIGCONT), true /* group */)
tgLeader.sendSignalLocked(SignalInfoPriv(linux.SIGHUP), true /* group */)
tgLeader.sendSignalLocked(SignalInfoPriv(linux.SIGCONT), true /* group */)
tg.signalHandlers.mu.NestedUnlock(signalHandlersLockTg)
})

Expand Down
6 changes: 3 additions & 3 deletions pkg/sentry/kernel/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func newTaskSet(pidns *PIDNamespace) *TaskSet {
}

// ForEachThreadGroup applies f to each thread group in ts.
func (ts *TaskSet) ForEachThreadGroup(f func(tg *ThreadGroup)) {
func (ts *TaskSet) ForEachThreadGroup(f func(tg *ThreadGroup, tgLeader *Task)) {
ts.mu.RLock()
defer ts.mu.RUnlock()
ts.forEachThreadGroupLocked(f)
Expand All @@ -122,9 +122,9 @@ func (ts *TaskSet) ForEachThreadGroup(f func(tg *ThreadGroup)) {
// forEachThreadGroupLocked applies f to each thread group in ts.
//
// Preconditions: ts.mu must be locked (for reading or writing).
func (ts *TaskSet) forEachThreadGroupLocked(f func(tg *ThreadGroup)) {
func (ts *TaskSet) forEachThreadGroupLocked(f func(tg *ThreadGroup, tgLeader *Task)) {
for tg := range ts.Root.tgids {
f(tg)
f(tg, tg.leader)
}
}

Expand Down

0 comments on commit fe9da19

Please sign in to comment.