1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-19 10:53:58 +00:00

filedesc: microoptimize fget_unlocked by retrying obtaining reference count

without restarting whole lookup

Restart is only needed when fp was closed by current process, which is a much
rarer event than ref/deref by some other thread.
This commit is contained in:
Mateusz Guzik 2014-10-30 05:21:12 +00:00
parent aa77d52800
commit 29c85772bb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=273843

View File

@ -2359,6 +2359,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
}
}
#endif
retry:
count = fp->f_count;
if (count == 0) {
fdt = fdp->fd_files;
@ -2368,10 +2369,8 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
* Use an acquire barrier to force re-reading of fdt so it is
* refreshed for verification.
*/
if (atomic_cmpset_acq_int(&fp->f_count, count, count + 1) == 0) {
fdt = fdp->fd_files;
continue;
}
if (atomic_cmpset_acq_int(&fp->f_count, count, count + 1) == 0)
goto retry;
fdt = fdp->fd_files;
#ifdef CAPABILITIES
if (seq_consistent_nomb(fd_seq(fdt, fd), seq))