diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2009-10-26 12:20:52 +1100 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2009-10-26 12:20:52 +1100 |
commit | 8aacfa348dc02b5f2d634dd763cc5fce39bdc888 (patch) | |
tree | 149a4e851ac175c135c82af9aa8c5cb8c9db8e24 /ctdb/common/ctdb_io.c | |
parent | c36fa583f3e97e2059c2d6abf27f71d987958eb9 (diff) | |
download | samba-8aacfa348dc02b5f2d634dd763cc5fce39bdc888.tar.gz |
Suggestion from Volker,
make ctdb_queue_length() cheaper by using a counter variable instead of counting the number of packets each time.
(This used to be ctdb commit 331c6e3afd96d8b5e191153a631efdbdabb6ea33)
Diffstat (limited to 'ctdb/common/ctdb_io.c')
-rw-r--r-- | ctdb/common/ctdb_io.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/ctdb/common/ctdb_io.c b/ctdb/common/ctdb_io.c index ea7c17d0198..99180ce926f 100644 --- a/ctdb/common/ctdb_io.c +++ b/ctdb/common/ctdb_io.c @@ -46,6 +46,7 @@ struct ctdb_queue { struct ctdb_context *ctdb; struct ctdb_partial partial; /* partial input packet */ struct ctdb_queue_pkt *out_queue; + uint32_t out_queue_length; struct fd_event *fde; int fd; size_t alignment; @@ -57,12 +58,7 @@ struct ctdb_queue { int ctdb_queue_length(struct ctdb_queue *queue) { - int i; - struct ctdb_queue_pkt *pkt; - - for(i=0, pkt=queue->out_queue;pkt;i++,pkt=pkt->next); - - return i; + return queue->out_queue_length; } /* @@ -188,6 +184,7 @@ static void queue_io_write(struct ctdb_queue *queue) if (pkt->length != pkt->full_length) { /* partial packet sent - we have to drop it */ DLIST_REMOVE(queue->out_queue, pkt); + queue->out_queue_length--; talloc_free(pkt); } talloc_free(queue->fde); @@ -206,6 +203,7 @@ static void queue_io_write(struct ctdb_queue *queue) } DLIST_REMOVE(queue->out_queue, pkt); + queue->out_queue_length--; talloc_free(pkt); } @@ -286,6 +284,7 @@ int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length) } DLIST_ADD_END(queue->out_queue, pkt, struct ctdb_queue_pkt *); + queue->out_queue_length++; if (queue->ctdb->tunable.verbose_memory_names != 0) { struct ctdb_req_header *hdr = (struct ctdb_req_header *)pkt->data; |