From: Ben Pfaff Date: Thu, 3 Jun 2010 17:17:51 +0000 (-0700) Subject: port-array: Add port_array_delete() function. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3648418c4bf028e6bca38bcbfc5a5ed493447fb;p=openvswitch port-array: Add port_array_delete() function. port_array_delete(pa, idx) is equivalent to port_array_set(pa, idx, NULL), but it never allocates memory and avoids conditionals. --- diff --git a/lib/port-array.c b/lib/port-array.c index e8f35be9..be4c0dcc 100644 --- a/lib/port-array.c +++ b/lib/port-array.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Nicira Networks. + * Copyright (c) 2008, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,6 +95,17 @@ port_array_set(struct port_array *pa, uint16_t idx, void *p) l3->l3[PORT_ARRAY_L3(idx)] = p; } +/* Sets 'pa' element numbered 'idx' to NULL. */ +void +port_array_delete(struct port_array *pa, uint16_t idx) +{ + unsigned int l1_idx = PORT_ARRAY_L1(idx); + unsigned int l2_idx = PORT_ARRAY_L2(idx); + unsigned int l3_idx = PORT_ARRAY_L3(idx); + + pa->l1[l1_idx]->l2[l2_idx]->l3[l3_idx] = NULL; +} + static void * next(const struct port_array *pa, unsigned int *idxp) { diff --git a/lib/port-array.h b/lib/port-array.h index 36410bfe..15fa41d1 100644 --- a/lib/port-array.h +++ b/lib/port-array.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,6 +84,7 @@ void port_array_init(struct port_array *); void port_array_destroy(struct port_array *); void port_array_clear(struct port_array *); void port_array_set(struct port_array *, uint16_t idx, void *); +void port_array_delete(struct port_array *, uint16_t idx); void *port_array_first(const struct port_array *, unsigned int *); void *port_array_next(const struct port_array *, unsigned int *); unsigned int port_array_count(const struct port_array *); diff --git a/ofproto/ofproto-sflow.c b/ofproto/ofproto-sflow.c index a96d8b49..cc6a6935 100644 --- a/ofproto/ofproto-sflow.c +++ b/ofproto/ofproto-sflow.c @@ -354,7 +354,7 @@ ofproto_sflow_del_port(struct ofproto_sflow *os, uint16_t odp_port) } netdev_close(osp->netdev); free(osp); - port_array_set(&os->ports, odp_port, NULL); + port_array_delete(&os->ports, odp_port); } } diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 031531c7..d877d36a 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1478,7 +1478,7 @@ ofport_remove(struct ofproto *p, struct ofport *ofport) uint16_t odp_port = ofp_port_to_odp_port(ofport->opp.port_no); netdev_monitor_remove(p->netdev_monitor, ofport->netdev); - port_array_set(&p->ports, odp_port, NULL); + port_array_delete(&p->ports, odp_port); shash_delete(&p->port_by_name, shash_find(&p->port_by_name, (char *) ofport->opp.name)); if (p->sflow) { diff --git a/ofproto/pinsched.c b/ofproto/pinsched.c index 6af2bb67..d749ee4e 100644 --- a/ofproto/pinsched.c +++ b/ofproto/pinsched.c @@ -70,7 +70,7 @@ dequeue_packet(struct pinsched *ps, struct ovs_queue *q, struct ofpbuf *packet = queue_pop_head(q); if (!q->n) { free(q); - port_array_set(&ps->queues, port_no, NULL); + port_array_delete(&ps->queues, port_no); } ps->n_queued--; return packet;