summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2022-03-18 14:45:40 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2022-03-18 14:45:40 +0000
commit1e1a38c2f14dd8cd06836a7402d96f0c1dd74983 (patch)
tree5016586ec871ef488b1cd836a995d1d7544b75a1 /sys
parent8734b3d36aa08e8392852adc260d99e37ad7d048 (diff)
Use the refcnt API with struct plimit.
OK bluhm@ dlg@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_resource.c14
-rw-r--r--sys/sys/resourcevar.h5
2 files changed, 10 insertions, 9 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index 3133d2b7edc..f8d418ac526 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_resource.c,v 1.71 2021/02/08 10:51:01 mpi Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.72 2022/03/18 14:45:39 visa Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
@@ -582,7 +582,7 @@ lim_startup(struct plimit *limit0)
limit0->pl_rlimit[RLIMIT_RSS].rlim_max = lim;
limit0->pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
limit0->pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
- limit0->pl_refcnt = 1;
+ refcnt_init(&limit0->pl_refcnt);
}
/*
@@ -598,14 +598,14 @@ lim_copy(struct plimit *lim)
newlim = pool_get(&plimit_pool, PR_WAITOK);
memcpy(newlim->pl_rlimit, lim->pl_rlimit,
sizeof(struct rlimit) * RLIM_NLIMITS);
- newlim->pl_refcnt = 1;
+ refcnt_init(&newlim->pl_refcnt);
return (newlim);
}
void
lim_free(struct plimit *lim)
{
- if (atomic_dec_int_nv(&lim->pl_refcnt) > 0)
+ if (refcnt_rele(&lim->pl_refcnt) == 0)
return;
pool_put(&plimit_pool, lim);
}
@@ -617,7 +617,7 @@ lim_fork(struct process *parent, struct process *child)
mtx_enter(&parent->ps_mtx);
limit = parent->ps_limit;
- atomic_inc_int(&limit->pl_refcnt);
+ refcnt_take(&limit->pl_refcnt);
mtx_leave(&parent->ps_mtx);
child->ps_limit = limit;
@@ -650,7 +650,7 @@ lim_write_begin(void)
*/
limit = p->p_p->ps_limit;
- if (P_HASSIBLING(p) || limit->pl_refcnt > 1)
+ if (P_HASSIBLING(p) || refcnt_shared(&limit->pl_refcnt))
limit = lim_copy(limit);
return (limit);
@@ -703,7 +703,7 @@ lim_read_enter(void)
if (limit != pr->ps_limit) {
mtx_enter(&pr->ps_mtx);
limit = pr->ps_limit;
- atomic_inc_int(&limit->pl_refcnt);
+ refcnt_take(&limit->pl_refcnt);
mtx_leave(&pr->ps_mtx);
if (p->p_limit != NULL)
lim_free(p->p_limit);
diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h
index 4200758bd04..74b994e4db3 100644
--- a/sys/sys/resourcevar.h
+++ b/sys/sys/resourcevar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: resourcevar.h,v 1.24 2019/06/21 09:39:48 visa Exp $ */
+/* $OpenBSD: resourcevar.h,v 1.25 2022/03/18 14:45:39 visa Exp $ */
/* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */
/*
@@ -35,6 +35,7 @@
#ifndef _SYS_RESOURCEVAR_H_
#define _SYS_RESOURCEVAR_H_
+#include <sys/refcnt.h>
#include <sys/timeout.h>
/*
@@ -44,7 +45,7 @@
*/
struct plimit {
struct rlimit pl_rlimit[RLIM_NLIMITS];
- u_int pl_refcnt; /* number of references */
+ struct refcnt pl_refcnt;
};
/* add user profiling from AST */