summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/kernel
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2019-04-04 17:13:31 -0700
committerShentubot <shentubot@google.com>2019-04-04 17:14:27 -0700
commit75a5ccf5d98876c26305da0feff20e4a148027ec (patch)
treedf7ae64d05c7537108d3d8c278a61da8f394da41 /pkg/sentry/kernel
parent75c8ac38e0f6cc4eb3726c89aee41357cd592c4b (diff)
Remove defer from trivial ThreadID methods
In particular, ns.IDOfTask and tg.ID are used for gettid and getpid, respectively, where removing defer saves ~100ns. This may be a small improvement to application logging, which may call gettid/getpid frequently. PiperOrigin-RevId: 242039616 Change-Id: I860beb62db3fe077519835e6bafa7c74cba6ca80
Diffstat (limited to 'pkg/sentry/kernel')
-rw-r--r--pkg/sentry/kernel/threads.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/pkg/sentry/kernel/threads.go b/pkg/sentry/kernel/threads.go
index 4af1b7dfa..4fd6cf4e2 100644
--- a/pkg/sentry/kernel/threads.go
+++ b/pkg/sentry/kernel/threads.go
@@ -196,8 +196,9 @@ func (ns *PIDNamespace) NewChild(userns *auth.UserNamespace) *PIDNamespace {
// task has that TID, TaskWithID returns nil.
func (ns *PIDNamespace) TaskWithID(tid ThreadID) *Task {
ns.owner.mu.RLock()
- defer ns.owner.mu.RUnlock()
- return ns.tasks[tid]
+ t := ns.tasks[tid]
+ ns.owner.mu.RUnlock()
+ return t
}
// ThreadGroupWithID returns the thread group lead by the task with thread ID
@@ -224,16 +225,18 @@ func (ns *PIDNamespace) ThreadGroupWithID(tid ThreadID) *ThreadGroup {
// 0.
func (ns *PIDNamespace) IDOfTask(t *Task) ThreadID {
ns.owner.mu.RLock()
- defer ns.owner.mu.RUnlock()
- return ns.tids[t]
+ id := ns.tids[t]
+ ns.owner.mu.RUnlock()
+ return id
}
// IDOfThreadGroup returns the TID assigned to tg's leader in PID namespace ns.
// If the task is not visible in that namespace, IDOfThreadGroup returns 0.
func (ns *PIDNamespace) IDOfThreadGroup(tg *ThreadGroup) ThreadID {
ns.owner.mu.RLock()
- defer ns.owner.mu.RUnlock()
- return ns.tgids[tg]
+ id := ns.tgids[tg]
+ ns.owner.mu.RUnlock()
+ return id
}
// Tasks returns a snapshot of the tasks in ns.
@@ -390,8 +393,9 @@ func (tg *ThreadGroup) MemberIDs(pidns *PIDNamespace) []ThreadID {
// is dead, ID returns 0.
func (tg *ThreadGroup) ID() ThreadID {
tg.pidns.owner.mu.RLock()
- defer tg.pidns.owner.mu.RUnlock()
- return tg.pidns.tgids[tg]
+ id := tg.pidns.tgids[tg]
+ tg.pidns.owner.mu.RUnlock()
+ return id
}
// A taskNode defines the relationship between a task and the rest of the