Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/config use a reference count to avoid deleting psref...
details: https://anonhg.NetBSD.org/src/rev/2f537f9b3fd2
branches: trunk
changeset: 357776:2f537f9b3fd2
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 27 00:25:46 2017 +0000
description:
use a reference count to avoid deleting psrefs still in use.
diffstat:
usr.bin/config/defs.h | 4 ++--
usr.bin/config/main.c | 11 +++++++----
usr.bin/config/sem.c | 25 +++++++++++++++----------
3 files changed, 24 insertions(+), 16 deletions(-)
diffs (127 lines):
diff -r 71aef210e3a6 -r 2f537f9b3fd2 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h Sun Nov 26 21:02:37 2017 +0000
+++ b/usr.bin/config/defs.h Mon Nov 27 00:25:46 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.101 2017/11/18 18:44:20 christos Exp $ */
+/* $NetBSD: defs.h,v 1.102 2017/11/27 00:25:46 christos Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -234,9 +234,9 @@
struct devbase *p_atdev; /* optional parent device base */
int p_atunit; /* optional parent device unit */
struct nvlist *p_devs; /* children using it */
- struct deva *p_deva; /* attribute */
int p_inst; /* parent spec instance */
int p_active; /* parent spec is actively used */
+ int p_ref; /* refcount */
};
/*
diff -r 71aef210e3a6 -r 2f537f9b3fd2 usr.bin/config/main.c
--- a/usr.bin/config/main.c Sun Nov 26 21:02:37 2017 +0000
+++ b/usr.bin/config/main.c Mon Nov 27 00:25:46 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.95 2017/11/24 23:42:36 christos Exp $ */
+/* $NetBSD: main.c,v 1.96 2017/11/27 00:25:46 christos Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.95 2017/11/24 23:42:36 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.96 2017/11/27 00:25:46 christos Exp $");
#ifndef MAKE_BOOTSTRAP
#include <sys/cdefs.h>
@@ -1959,8 +1959,11 @@
continue;
}
j->i_active = active = state;
- if (p != NULL)
- p->p_active = state;
+ if (p != NULL) {
+ if (state == DEVI_ACTIVE ||
+ --p->p_ref == 0)
+ p->p_active = state;
+ }
if (state == DEVI_IGNORED) {
CFGDBG(5,
"`%s' at '%s' ignored",
diff -r 71aef210e3a6 -r 2f537f9b3fd2 usr.bin/config/sem.c
--- a/usr.bin/config/sem.c Sun Nov 26 21:02:37 2017 +0000
+++ b/usr.bin/config/sem.c Mon Nov 27 00:25:46 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.c,v 1.81 2017/11/24 18:45:59 christos Exp $ */
+/* $NetBSD: sem.c,v 1.82 2017/11/27 00:25:46 christos Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: sem.c,v 1.81 2017/11/24 18:45:59 christos Exp $");
+__RCSID("$NetBSD: sem.c,v 1.82 2017/11/27 00:25:46 christos Exp $");
#include <sys/param.h>
#include <ctype.h>
@@ -79,8 +79,7 @@
static struct nvlist *addtoattr(struct nvlist *, struct devbase *);
static int resolve(struct nvlist **, const char *, const char *,
struct nvlist *, int);
-static struct pspec *getpspec(struct attr *, struct devbase *, int,
- struct deva *);
+static struct pspec *getpspec(struct attr *, struct devbase *, int, int);
static struct devi *newdevi(const char *, int, struct devbase *d);
static struct devi *getdevi(const char *);
static void remove_devi(struct devi *);
@@ -1296,7 +1295,7 @@
* XXX: This creates multiple pspecs that look the
* same in the config file and could be merged.
*/
- p = getpspec(attr, ab, atunit, iba);
+ p = getpspec(attr, ab, atunit, first);
p->p_devs = newnv(NULL, NULL, i, 0, p->p_devs);
} else
p = NULL;
@@ -1907,17 +1906,23 @@
* Look up a parent spec, creating a new one if it does not exist.
*/
static struct pspec *
-getpspec(struct attr *attr, struct devbase *ab, int atunit, struct deva *da)
+getpspec(struct attr *attr, struct devbase *ab, int atunit, int first)
{
struct pspec *p;
int inst = npspecs;
+ int ref = 1;
TAILQ_FOREACH(p, &allpspecs, p_list) {
if (p->p_iattr == attr && p->p_atdev == ab &&
p->p_atunit == atunit) {
- if (p->p_deva == da)
- return (p);
- inst = p->p_inst;
+ p->p_ref++;
+ if (first)
+ return p;
+ else {
+ inst = p->p_inst;
+ ref = p->p_ref;
+ }
+
}
}
@@ -1929,8 +1934,8 @@
p->p_inst = inst;
if (inst == npspecs)
npspecs++;
- p->p_deva = da;
p->p_active = 0;
+ p->p_ref = ref;
TAILQ_INSERT_TAIL(&allpspecs, p, p_list);
Home |
Main Index |
Thread Index |
Old Index