aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorRobert Watson <rwatson@FreeBSD.org>2004-07-14 20:27:33 +0000
committerRobert Watson <rwatson@FreeBSD.org>2004-07-14 20:27:33 +0000
commit544fc3d5624c0802754c9e142cc8448df514c173 (patch)
treedde7514b4aa2e376477f9c412ed2ae92f08d20b9 /sys
parentdffa5be1a4748e975d31cbef825af8f7e6b18296 (diff)
Notes
Diffstat (limited to 'sys')
-rw-r--r--sys/netgraph/ng_fec.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/netgraph/ng_fec.c b/sys/netgraph/ng_fec.c
index 3e451f76f17dc..1e126f2283be5 100644
--- a/sys/netgraph/ng_fec.c
+++ b/sys/netgraph/ng_fec.c
@@ -257,6 +257,9 @@ static int ng_units_in_use = 0;
#define UNITS_BITSPERWORD (sizeof(*ng_fec_units) * NBBY)
+static struct mtx ng_fec_mtx;
+MTX_SYSINIT(ng_fec, &ng_fec_mtx, "ng_fec", MTX_DEF);
+
/*
* Find the first free unit number for a new interface.
* Increase the size of the unit bitmap as necessary.
@@ -266,6 +269,7 @@ ng_fec_get_unit(int *unit)
{
int index, bit;
+ mtx_lock(&ng_fec_mtx);
for (index = 0; index < ng_fec_units_len
&& ng_fec_units[index] == 0; index++);
if (index == ng_fec_units_len) { /* extend array */
@@ -274,8 +278,10 @@ ng_fec_get_unit(int *unit)
newlen = (2 * ng_fec_units_len) + 4;
MALLOC(newarray, int *, newlen * sizeof(*ng_fec_units),
M_NETGRAPH, M_NOWAIT);
- if (newarray == NULL)
+ if (newarray == NULL) {
+ mtx_unlock(&ng_fec_mtx);
return (ENOMEM);
+ }
bcopy(ng_fec_units, newarray,
ng_fec_units_len * sizeof(*ng_fec_units));
for (i = ng_fec_units_len; i < newlen; i++)
@@ -291,6 +297,7 @@ ng_fec_get_unit(int *unit)
ng_fec_units[index] &= ~(1 << bit);
*unit = (index * UNITS_BITSPERWORD) + bit;
ng_units_in_use++;
+ mtx_unlock(&ng_fec_mtx);
return (0);
}
@@ -304,6 +311,7 @@ ng_fec_free_unit(int unit)
index = unit / UNITS_BITSPERWORD;
bit = unit % UNITS_BITSPERWORD;
+ mtx_lock(&ng_fec_mtx);
KASSERT(index < ng_fec_units_len,
("%s: unit=%d len=%d", __FUNCTION__, unit, ng_fec_units_len));
KASSERT((ng_fec_units[index] & (1 << bit)) == 0,
@@ -321,6 +329,7 @@ ng_fec_free_unit(int unit)
ng_fec_units_len = 0;
ng_fec_units = NULL;
}
+ mtx_unlock(&ng_fec_mtx);
}
/************************************************************************