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)
This commit is contained in:
parent
b1e34c44ef
commit
8250de8330
@ -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];
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user