diff options
author | 2018-06-24 05:58:05 +0000 | |
---|---|---|
committer | 2018-06-24 05:58:05 +0000 | |
commit | 47f9075b1fbb00608a2d7270ed229aec981539a0 (patch) | |
tree | 73b1ee1f04c592181fa30cbd70597e4ed2064a0c | |
parent | Move signal generation from fputrap() to where it's called in trap() (diff) | |
download | wireguard-openbsd-47f9075b1fbb00608a2d7270ed229aec981539a0.tar.xz wireguard-openbsd-47f9075b1fbb00608a2d7270ed229aec981539a0.zip |
Use atomic operations for updating `numfiles'. This makes the file count
tracking work without locks.
OK kettenis@, deraadt@
-rw-r--r-- | sys/kern/kern_descrip.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index f6c17c8a67e..b0815c2111a 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.167 2018/06/20 10:52:49 mpi Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.168 2018/06/24 05:58:05 visa Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -957,7 +957,7 @@ int falloc(struct proc *p, struct file **resultfp, int *resultfd) { struct file *fp; - int error, i; + int error, i, nfiles; KASSERT(resultfp != NULL); KASSERT(resultfd != NULL); @@ -971,7 +971,9 @@ restart: } return (error); } - if (numfiles >= maxfiles) { + nfiles = atomic_inc_int_nv(&numfiles); + if (nfiles > maxfiles) { + atomic_dec_int(&numfiles); fd_unused(p->p_fd, i); tablefull("file"); return (ENFILE); @@ -982,7 +984,6 @@ restart: * of open files at that point, otherwise put it at the front of * the list of open files. */ - numfiles++; fp = pool_get(&file_pool, PR_WAITOK|PR_ZERO); /* * We need to block interrupts as long as `f_mtx' is being taken @@ -1222,7 +1223,7 @@ fdrop(struct file *fp, struct proc *p) error = 0; crfree(fp->f_cred); - numfiles--; + atomic_dec_int(&numfiles); pool_put(&file_pool, fp); return (error); |