summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2011-02-16 17:59:04 +0100
committerWim Taymans <wim.taymans@collabora.co.uk>2011-02-16 17:59:21 +0100
commit84efb8e67dce4429ce0909fbe8bc61452486edf0 (patch)
tree3418fef1c06161cade5bdf4a2deaf4dd66707ff6
parent14d7db1b527b05f029819057aef5c123ac7e013d (diff)
buffer: recycle buffers using the atomic queuebuffer-recycle
Recycle buffers instead of alloc/free them. Improves pathological fakesrc num-buffers=5000000 silent=1 ! fakesink silent=1 with 6%
-rw-r--r--gst/gstbuffer.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c
index 5a126639d..a86c127b7 100644
--- a/gst/gstbuffer.c
+++ b/gst/gstbuffer.c
@@ -122,6 +122,7 @@
#include <stdlib.h>
#endif
+#include "gstatomicqueue.h"
#include "gstbuffer.h"
#include "gstinfo.h"
#include "gstutils.h"
@@ -133,6 +134,8 @@ static GstBuffer *_gst_buffer_copy (GstBuffer * buffer);
static GType _gst_buffer_type = 0;
+static GstAtomicQueue *queue;
+
/* buffer alignment in bytes
* an alignment of 8 would be the same as malloc() guarantees
*/
@@ -161,6 +164,7 @@ aligned_malloc (gpointer * memptr, guint size)
void
_gst_buffer_initialize (void)
{
+ queue = gst_atomic_queue_new (16);
/* the GstMiniObject types need to be class_ref'd once before it can be
* done from multiple threads;
* see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
@@ -203,6 +207,10 @@ gst_buffer_finalize (GstBuffer * buffer)
if (buffer->parent)
gst_buffer_unref (buffer->parent);
+ /* revive */
+ gst_buffer_ref (buffer);
+ gst_atomic_queue_push (queue, buffer);
+
/* ((GstMiniObjectClass *) */
/* gst_buffer_parent_class)->finalize (GST_MINI_OBJECT_CAST (buffer)); */
}
@@ -331,7 +339,16 @@ gst_buffer_new (void)
{
GstBuffer *newbuf;
- newbuf = (GstBuffer *) gst_mini_object_new (_gst_buffer_type);
+ if ((newbuf = gst_atomic_queue_pop (queue))) {
+ GST_MINI_OBJECT_CAST (newbuf)->flags = 0;
+ gst_buffer_init (newbuf);
+ newbuf->data = NULL;
+ newbuf->size = 0;
+ newbuf->malloc_data = NULL;
+ newbuf->parent = NULL;
+ } else {
+ newbuf = (GstBuffer *) gst_mini_object_new (_gst_buffer_type);
+ }
GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);