]> granicus.if.org Git - libevent/commitdiff
expose bufferevent_incref/decref (with fewer modifications)
authorMark Ellzey <socket@gmail.com>
Wed, 6 May 2015 21:56:31 +0000 (14:56 -0700)
committerMark Ellzey <socket@gmail.com>
Wed, 6 May 2015 21:56:31 +0000 (14:56 -0700)
bufferevent-internal.h
bufferevent.c
include/event2/bufferevent.h

index 134bb337521c128a7d2aa08561736e49cc5a7ac6..ad3dcfc9ebd465fe658ec8bc63696cad55f855c4 100644 (file)
@@ -327,14 +327,17 @@ int bufferevent_disable_hard_(struct bufferevent *bufev, short event);
 /** Internal: Set up locking on a bufferevent.  If lock is set, use it.
  * Otherwise, use a new lock. */
 int bufferevent_enable_locking_(struct bufferevent *bufev, void *lock);
-/** Internal: Increment the reference count on bufev. */
-void bufferevent_incref_(struct bufferevent *bufev);
+/** Internal: backwards compat macro for the now public function
+ * Increment the reference count on bufev. */
+#define bufferevent_incref_(bufev) bufferevent_incref(bufev)
 /** Internal: Lock bufev and increase its reference count.
  * unlocking it otherwise. */
 void bufferevent_incref_and_lock_(struct bufferevent *bufev);
-/** Internal: Decrement the reference count on bufev.  Returns 1 if it freed
+/** Internal: backwards compat macro for the now public function
+ * Decrement the reference count on bufev.  Returns 1 if it freed
  * the bufferevent.*/
-int bufferevent_decref_(struct bufferevent *bufev);
+#define bufferevent_decref_(bufev) bufferevent_decref(bufev)
+
 /** Internal: Drop the reference count on bufev, freeing as necessary, and
  * unlocking it otherwise.  Returns 1 if it freed the bufferevent. */
 int bufferevent_decref_and_unlock_(struct bufferevent *bufev);
index d298d0b3f01387aae7a453ecff9b9193e2b94d76..7d3d69352dda47c6987378dd1aface2364293263 100644 (file)
@@ -777,7 +777,7 @@ bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_)
 }
 
 int
-bufferevent_decref_(struct bufferevent *bufev)
+bufferevent_decref(struct bufferevent *bufev)
 {
        BEV_LOCK(bufev);
        return bufferevent_decref_and_unlock_(bufev);
@@ -793,11 +793,15 @@ bufferevent_free(struct bufferevent *bufev)
 }
 
 void
-bufferevent_incref_(struct bufferevent *bufev)
+bufferevent_incref(struct bufferevent *bufev)
 {
        struct bufferevent_private *bufev_private =
            EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
 
+       /* XXX: now that this function is public, we might want to
+        * - return the count from this function
+        * - create a new function to atomically grab the current refcount
+        */
        BEV_LOCK(bufev);
        ++bufev_private->refcnt;
        BEV_UNLOCK(bufev);
index fe8a74d348c635f04faed31032d4d9903b809f0e..f041fa85f551d93fefb119160738d7bc9ebcec55 100644 (file)
@@ -562,6 +562,32 @@ void bufferevent_lock(struct bufferevent *bufev);
 EVENT2_EXPORT_SYMBOL
 void bufferevent_unlock(struct bufferevent *bufev);
 
+
+/**
+ * Public interface to manually increase the reference count of a bufferevent
+ * this is useful in situations where a user may reference the bufferevent
+ * somewhere eles (unknown to libevent)
+ *
+ * @param bufev the bufferevent to increase the refcount on
+ *
+ */
+EVENT2_EXPORT_SYMBOL
+void bufferevent_incref(struct bufferevent *bufev);
+
+/**
+ * Public interface to manually decrement the reference count of a bufferevent
+ *
+ * Warning: make sure you know what you're doing. This is mainly used in
+ * conjunction with bufferevent_incref(). This will free up all data associated
+ * with a bufferevent if the reference count hits 0.
+ *
+ * @param bufev the bufferevent to decrement the refcount on
+ *
+ * @return 1 if the bufferevent was freed, otherwise 0 (still referenced)
+ */
+EVENT2_EXPORT_SYMBOL
+int bufferevent_decref(struct bufferevent *bufev);
+
 /**
    Flags that can be passed into filters to let them know how to
    deal with the incoming data.