Date: Thu, 13 Nov 2014 14:14:29 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 194985] getdtablecount new syscall from openbsd Message-ID: <bug-194985-8-ncyvm4on5A@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-194985-8@https.bugs.freebsd.org/bugzilla/> References: <bug-194985-8@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194985 --- Comment #4 from Mateusz Guzik <mjg@FreeBSD.org> --- + p = td->td_proc; + PROC_LOCK(p); + fdp = p->p_fd; + FILEDESC_SLOCK(fdp); + td->td_retval[0] = fdp->fd_openfd; + FILEDESC_SUNLOCK(fdp); + PROC_UNLOCK(p); proc lock has no useful purpose here. p_fd can change in some cases during fork, but then the process is singlethreaded. proc lock is a mutex with bound sleep, while filedesc lock has unbound sleep. As such, they cannot be taken in this order anyway. As a side note, they happen to be taken in the opposide order, so this code gives 2 different opportunities for deadlocks. The kernel would tell you that if you enabled WITNESS and INVARIANTS. Lastly, I'm not a fan of counting fds if it can be avoided. As mentioned in my previous comment, the kernel maintains a bitmap of open descriptors. I would suspect counting set bits (= open descriptors) would be fast enough for real life cases. -- You are receiving this mail because: You are the assignee for the bug.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-194985-8-ncyvm4on5A>