diff options
author | luigi <luigi@FreeBSD.org> | 2009-12-28 10:19:53 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2009-12-28 10:19:53 +0000 |
commit | ffe8fa8dada6df26645bc5af9810d8e7e565187b (patch) | |
tree | 1a299899c272c48e95a08ef97f02f4c7a8de9a9c | |
parent | 5596409e3474a387a5822069e2094d9551e250a8 (diff) | |
download | FreeBSD-src-ffe8fa8dada6df26645bc5af9810d8e7e565187b.zip FreeBSD-src-ffe8fa8dada6df26645bc5af9810d8e7e565187b.tar.gz |
readability fixes -- add braces on large blocks, remove unnecessary
initializations
-rw-r--r-- | sys/netinet/ipfw/ip_dummynet.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/sys/netinet/ipfw/ip_dummynet.c b/sys/netinet/ipfw/ip_dummynet.c index a4f9668..2b9b928 100644 --- a/sys/netinet/ipfw/ip_dummynet.c +++ b/sys/netinet/ipfw/ip_dummynet.c @@ -566,13 +566,6 @@ set_ticks(struct mbuf *m, struct dn_flow_queue *q, struct dn_pipe *p) ret = div64( (m->m_pkthdr.len * 8 + q->extra_bits) * hz - q->numbytes + p->bandwidth - 1 , p->bandwidth); -#if 0 - printf("%s %d extra_bits %d numb %d ret %d\n", - __FUNCTION__, __LINE__, - (int)(q->extra_bits & 0xffffffff), - (int)(q->numbytes & 0xffffffff), - (int)(ret & 0xffffffff)); -#endif if (ret < 0) ret = 0; return ret; @@ -945,8 +938,8 @@ dummynet_task(void *context, int pending) } /* Sweep pipes trying to expire idle flow_queues. */ - for (i = 0; i < HASHSIZE; i++) - SLIST_FOREACH(pipe, &pipehash[i], next) + for (i = 0; i < HASHSIZE; i++) { + SLIST_FOREACH(pipe, &pipehash[i], next) { if (pipe->idle_heap.elements > 0 && DN_KEY_LT(pipe->idle_heap.p[0].key, pipe->V)) { struct dn_flow_queue *q = @@ -957,6 +950,8 @@ dummynet_task(void *context, int pending) q->S = q->F + 1; pipe->sum -= q->fs->weight; } + } + } DUMMYNET_UNLOCK(); @@ -1055,8 +1050,8 @@ expire_queues(struct dn_flow_set *fs) if (fs->last_expired == time_uptime) return 0 ; fs->last_expired = time_uptime ; - for (i = 0 ; i <= fs->rq_size ; i++) /* last one is overflow */ - for (prev=NULL, q = fs->rq[i] ; q != NULL ; ) + for (i = 0 ; i <= fs->rq_size ; i++) { /* last one is overflow */ + for (prev=NULL, q = fs->rq[i] ; q != NULL ; ) { if (!QUEUE_IS_IDLE(q)) { prev = q ; q = q->next ; @@ -1070,6 +1065,8 @@ expire_queues(struct dn_flow_set *fs) fs->rq_elements-- ; free(old_q, M_DUMMYNET); } + } + } return initial_elements - fs->rq_elements ; } @@ -1929,14 +1926,16 @@ config_pipe(struct dn_pipe *p) static void fs_remove_from_heap(struct dn_heap *h, struct dn_flow_set *fs) { - int i = 0, found = 0 ; - for (; i < h->elements ;) + int i, found; + + for (i = found = 0 ; i < h->elements ;) { if ( ((struct dn_flow_queue *)h->p[i].object)->fs == fs) { h->elements-- ; h->p[i] = h->p[h->elements] ; found++ ; } else i++ ; + } if (found) heapify(h); } @@ -1947,17 +1946,16 @@ fs_remove_from_heap(struct dn_heap *h, struct dn_flow_set *fs) static void pipe_remove_from_heap(struct dn_heap *h, struct dn_pipe *p) { - if (h->elements > 0) { - int i = 0 ; + int i; + for (i=0; i < h->elements ; i++ ) { - if (h->p[i].object == p) { /* found it */ - h->elements-- ; - h->p[i] = h->p[h->elements] ; - heapify(h); - break ; - } + if (h->p[i].object == p) { /* found it */ + h->elements-- ; + h->p[i] = h->p[h->elements] ; + heapify(h); + break ; + } } - } } /* @@ -2017,14 +2015,16 @@ delete_pipe(struct dn_pipe *p) SLIST_REMOVE(&pipehash[HASH(pipe->pipe_nr)], pipe, dn_pipe, next); /* Remove all references to this pipe from flow_sets. */ - for (i = 0; i < HASHSIZE; i++) - SLIST_FOREACH(fs, &flowsethash[i], next) + for (i = 0; i < HASHSIZE; i++) { + SLIST_FOREACH(fs, &flowsethash[i], next) { if (fs->pipe == pipe) { printf("dummynet: ++ ref to pipe %d from fs %d\n", p->pipe_nr, fs->fs_nr); fs->pipe = NULL ; purge_flow_set(fs, 0); } + } + } fs_remove_from_heap(&ready_heap, &(pipe->fs)); purge_pipe(pipe); /* remove all data associated to this pipe */ /* remove reference to here from extract_heap and wfq_ready_heap */ @@ -2073,7 +2073,7 @@ dn_copy_set(struct dn_flow_set *set, char *bp) DUMMYNET_LOCK_ASSERT(); - for (i = 0 ; i <= set->rq_size ; i++) + for (i = 0 ; i <= set->rq_size ; i++) { for (q = set->rq[i] ; q ; q = q->next, qp++ ) { if (q->hash_slot != i) printf("dummynet: ++ at %d: wrong slot (have %d, " @@ -2088,6 +2088,7 @@ dn_copy_set(struct dn_flow_set *set, char *bp) qp->head = qp->tail = NULL ; qp->fs = NULL ; } + } if (copied != set->rq_elements) printf("dummynet: ++ wrong count, have %d should be %d\n", copied, set->rq_elements); @@ -2137,7 +2138,7 @@ dummynet_get(struct sockopt *sopt) DUMMYNET_UNLOCK(); buf = malloc(size, M_TEMP, M_WAITOK); DUMMYNET_LOCK(); - if (size == dn_calc_size()) + if (size >= dn_calc_size()) break; free(buf, M_TEMP); buf = NULL; @@ -2147,7 +2148,7 @@ dummynet_get(struct sockopt *sopt) return ENOBUFS ; } bp = buf; - for (i = 0; i < HASHSIZE; i++) + for (i = 0; i < HASHSIZE; i++) { SLIST_FOREACH(pipe, &pipehash[i], next) { struct dn_pipe *pipe_bp = (struct dn_pipe *)bp; @@ -2176,8 +2177,9 @@ dummynet_get(struct sockopt *sopt) bp += sizeof(*pipe) ; bp = dn_copy_set(&(pipe->fs), bp); } + } - for (i = 0; i < HASHSIZE; i++) + for (i = 0; i < HASHSIZE; i++) { SLIST_FOREACH(fs, &flowsethash[i], next) { struct dn_flow_set *fs_bp = (struct dn_flow_set *)bp; @@ -2189,6 +2191,7 @@ dummynet_get(struct sockopt *sopt) bp += sizeof(*fs); bp = dn_copy_set(fs, bp); } + } DUMMYNET_UNLOCK(); |