summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_ppp.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2004-07-16 00:07:44 +0000
committerglebius <glebius@FreeBSD.org>2004-07-16 00:07:44 +0000
commit2fbfee896e08736dbae2455199cd9c351520c337 (patch)
treee0474fa518baa20489347c401db836359e58dadc /sys/netgraph/ng_ppp.c
parent7597972ed77af33943e7cf02bffe395e692f99ba (diff)
downloadFreeBSD-src-2fbfee896e08736dbae2455199cd9c351520c337.zip
FreeBSD-src-2fbfee896e08736dbae2455199cd9c351520c337.tar.gz
Use qsort_r() instead of qsort() when sorting links by latency
This helps us to remove a global variable and a mutex protecting it. Reviewed by: rwatson Approved by: julian (mentor)
Diffstat (limited to 'sys/netgraph/ng_ppp.c')
-rw-r--r--sys/netgraph/ng_ppp.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/sys/netgraph/ng_ppp.c b/sys/netgraph/ng_ppp.c
index c923e57..d70bb94 100644
--- a/sys/netgraph/ng_ppp.c
+++ b/sys/netgraph/ng_ppp.c
@@ -234,7 +234,7 @@ static void ng_ppp_frag_checkstale(node_p node);
static void ng_ppp_frag_reset(node_p node);
static int ng_ppp_mp_output(node_p node, struct mbuf *m);
static void ng_ppp_mp_strategy(node_p node, int len, int *distrib);
-static int ng_ppp_intcmp(const void *v1, const void *v2);
+static int ng_ppp_intcmp(void *latency, const void *v1, const void *v2);
static struct mbuf *ng_ppp_addproto(struct mbuf *m, int proto, int compOK);
static struct mbuf *ng_ppp_prepend(struct mbuf *m, const void *buf, int len);
static int ng_ppp_config_valid(node_p node,
@@ -360,15 +360,6 @@ static struct ng_type ng_ppp_typestruct = {
};
NETGRAPH_INIT(ppp, &ng_ppp_typestruct);
-static int *compareLatencies; /* hack for ng_ppp_intcmp() */
-
-/*
- * XXXRW: An ugly synchronization hack to protect an ugly hack.
- */
-static struct mtx ng_ppp_latencies_mtx;
-MTX_SYSINIT(ng_ppp_latencies, &ng_ppp_latencies_mtx, "ng_ppp_latencies",
- MTX_DEF);
-
/* Address and control field header */
static const u_char ng_ppp_acf[2] = { 0xff, 0x03 };
@@ -1771,12 +1762,8 @@ ng_ppp_mp_strategy(node_p node, int len, int *distrib)
}
/* Sort active links by latency */
- mtx_lock(&ng_ppp_latencies_mtx);
- compareLatencies = latency;
- qsort(sortByLatency,
- priv->numActiveLinks, sizeof(*sortByLatency), ng_ppp_intcmp);
- compareLatencies = NULL;
- mtx_unlock(&ng_ppp_latencies_mtx);
+ qsort_r(sortByLatency,
+ priv->numActiveLinks, sizeof(*sortByLatency), latency, ng_ppp_intcmp);
/* Find the interval we need (add links in sortByLatency[] order) */
for (numFragments = 1;
@@ -1862,14 +1849,12 @@ ng_ppp_mp_strategy(node_p node, int len, int *distrib)
* Compare two integers
*/
static int
-ng_ppp_intcmp(const void *v1, const void *v2)
+ng_ppp_intcmp(void *latency, const void *v1, const void *v2)
{
const int index1 = *((const int *) v1);
const int index2 = *((const int *) v2);
- mtx_assert(&ng_ppp_latencies_mtx, MA_OWNED);
-
- return compareLatencies[index1] - compareLatencies[index2];
+ return ((int *)latency)[index1] - ((int *)latency)[index2];
}
/*
OpenPOWER on IntegriCloud