diff options
author | Edward Hervey <edward@centricular.com> | 2018-06-21 07:28:03 +0200 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2018-06-23 07:07:53 +0200 |
commit | 5653bdb707c18d1c9969eb78db0a936523df9fc6 (patch) | |
tree | d1c8e0b1bf8e3ecd1ebcec854a3f2d8bfd3b4a6a /libsoup/soup-message-body.c | |
parent | d6224cc932c52f829a591a408fccbde68573cbda (diff) | |
download | libsoup-5653bdb707c18d1c9969eb78db0a936523df9fc6.tar.gz |
soup: Use atomic integers for refcounting
For SoupBuffer, SoupMessageBody, SoupMessageHeaders and
SoupClientContext
https://bugzilla.gnome.org/show_bug.cgi?id=785110
Diffstat (limited to 'libsoup/soup-message-body.c')
-rw-r--r-- | libsoup/soup-message-body.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/libsoup/soup-message-body.c b/libsoup/soup-message-body.c index 50428eb4..0c45e18e 100644 --- a/libsoup/soup-message-body.c +++ b/libsoup/soup-message-body.c @@ -272,7 +272,7 @@ soup_buffer_copy (SoupBuffer *buffer) /* For non-TEMPORARY buffers, this is just a ref */ if (priv->use != SOUP_MEMORY_TEMPORARY) { - priv->refcount++; + g_atomic_int_inc (&priv->refcount); return buffer; } @@ -305,11 +305,12 @@ soup_buffer_free (SoupBuffer *buffer) { SoupBufferPrivate *priv = (SoupBufferPrivate *)buffer; - if (!--priv->refcount) { - if (priv->owner_dnotify) - priv->owner_dnotify (priv->owner); - g_slice_free (SoupBufferPrivate, priv); - } + if (!g_atomic_int_dec_and_test (&priv->refcount)) + return; + + if (priv->owner_dnotify) + priv->owner_dnotify (priv->owner); + g_slice_free (SoupBufferPrivate, priv); } /** @@ -725,7 +726,7 @@ soup_message_body_copy (SoupMessageBody *body) { SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body; - priv->ref_count++; + g_atomic_int_inc (&priv->ref_count); return body; } @@ -741,10 +742,11 @@ soup_message_body_free (SoupMessageBody *body) { SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body; - if (--priv->ref_count == 0) { - soup_message_body_truncate (body); - g_slice_free (SoupMessageBodyPrivate, priv); - } + if (!g_atomic_int_dec_and_test (&priv->ref_count)) + return; + + soup_message_body_truncate (body); + g_slice_free (SoupMessageBodyPrivate, priv); } G_DEFINE_BOXED_TYPE (SoupMessageBody, soup_message_body, soup_message_body_copy, soup_message_body_free) |