curproc access isn't necessarily as cheap as a local variable access,
authorderaadt <deraadt@openbsd.org>
Tue, 19 Dec 2017 16:41:43 +0000 (16:41 +0000)
committerderaadt <deraadt@openbsd.org>
Tue, 19 Dec 2017 16:41:43 +0000 (16:41 +0000)
so only get it once
ok guenther

sys/kern/sys_futex.c

index 7c46441..9d00d0f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_futex.c,v 1.4 2017/08/13 20:26:33 guenther Exp $ */
+/*     $OpenBSD: sys_futex.c,v 1.5 2017/12/19 16:41:43 deraadt Exp $ */
 
 /*
  * Copyright (c) 2016-2017 Martin Pieuchot
@@ -129,12 +129,13 @@ sys_futex(struct proc *p, void *v, register_t *retval)
 struct futex *
 futex_get(uint32_t *uaddr, int flag)
 {
+       struct proc *p = curproc;
        struct futex *f;
 
        rw_assert_wrlock(&ftlock);
 
        LIST_FOREACH(f, &ftlist, ft_list) {
-               if (f->ft_uaddr == uaddr && f->ft_pid == curproc->p_p->ps_pid) {
+               if (f->ft_uaddr == uaddr && f->ft_pid == p->p_p->ps_pid) {
                        f->ft_refcnt++;
                        break;
                }
@@ -148,7 +149,7 @@ futex_get(uint32_t *uaddr, int flag)
                f = pool_get(&ftpool, PR_WAITOK);
                TAILQ_INIT(&f->ft_threads);
                f->ft_uaddr = uaddr;
-               f->ft_pid = curproc->p_p->ps_pid;
+               f->ft_pid = p->p_p->ps_pid;
                f->ft_refcnt = 1;
                LIST_INSERT_HEAD(&ftlist, f, ft_list);
        }