]> granicus.if.org Git - libevent/commitdiff
add pin/unpin functions, and a deref-and-free pair.
authorNick Mathewson <nickm@torproject.org>
Mon, 13 Apr 2009 03:06:47 +0000 (03:06 +0000)
committerNick Mathewson <nickm@torproject.org>
Mon, 13 Apr 2009 03:06:47 +0000 (03:06 +0000)
svn:r1165

buffer.c
evbuffer-internal.h

index 3c2c7db1eebf880b5c275c9ddc7af2a370ff9eb1..d08a0709797ce24f1a7c46551f8260d945d688d3 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -231,23 +231,21 @@ evbuffer_chain_insert(struct evbuffer *buf, struct evbuffer_chain *chain)
        buf->total_len += chain->off;
 }
 
-#ifdef NOT_USED_YET
-static void
-evbuffer_chain_pin(struct evbuffer_chain *chain, unsigned flag)
+void
+_evbuffer_chain_pin(struct evbuffer_chain *chain, unsigned flag)
 {
        assert((chain->flags & flag) == 0);
        chain->flags |= flag;
 }
 
-static void
-evbuffer_chain_unpin(struct evbuffer_chain *chain, unsigned flag)
+void
+_evbuffer_chain_unpin(struct evbuffer_chain *chain, unsigned flag)
 {
        assert((chain->flags & flag) != 0);
        chain->flags &= ~flag;
        if (chain->flags & EVBUFFER_DANGLING)
                evbuffer_chain_free(chain);
 }
-#endif
 
 struct evbuffer *
 evbuffer_new(void)
@@ -370,8 +368,7 @@ evbuffer_deferred_callback(struct deferred_cb *cb, void *arg)
 
        EVBUFFER_LOCK(buffer, EVTHREAD_WRITE);
        evbuffer_run_callbacks(buffer);
-       evbuffer_free(buffer); /* release the reference */
-       EVBUFFER_UNLOCK(buffer, EVTHREAD_WRITE);
+       _evbuffer_decref_and_unlock(buffer);
 }
 
 static void
@@ -386,11 +383,11 @@ evbuffer_remove_all_callbacks(struct evbuffer *buffer)
 }
 
 void
-evbuffer_free(struct evbuffer *buffer)
+_evbuffer_decref_and_unlock(struct evbuffer *buffer)
 {
        struct evbuffer_chain *chain, *next;
+       ASSERT_EVBUFFER_LOCKED(buffer);
 
-       EVBUFFER_LOCK(buffer, EVTHREAD_WRITE);
        if (--buffer->refcnt > 0) {
                EVBUFFER_UNLOCK(buffer, EVTHREAD_WRITE);
                return;
@@ -410,6 +407,13 @@ evbuffer_free(struct evbuffer *buffer)
        mm_free(buffer);
 }
 
+void
+evbuffer_free(struct evbuffer *buffer)
+{
+       EVBUFFER_LOCK(buffer, EVTHREAD_WRITE);
+       _evbuffer_decref_and_unlock(buffer);
+}
+
 void
 evbuffer_lock(struct evbuffer *buf)
 {
index 31e51154334a90e131694fcb53b6ebd2a629aa09..d6d9b1c05b815713fe6c3c55168ed2467e681c26 100644 (file)
@@ -194,6 +194,9 @@ struct evbuffer_chain_reference {
        } while(0)
 
 void _evbuffer_incref(struct evbuffer *buf);
+void _evbuffer_chain_pin(struct evbuffer_chain *chain, unsigned flag);
+void _evbuffer_chain_unpin(struct evbuffer_chain *chain, unsigned flag);
+void _evbuffer_decref_and_unlock(struct evbuffer *buffer);
 
 #ifdef _EVENT_HAVE_SYS_UIO_H
 int _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch,