remove probes

Original commit message from CVS:
remove probes
This commit is contained in:
Benjamin Otte 2005-05-16 02:30:13 +00:00
parent 68f8c5e090
commit b40a5f223c
12 changed files with 11 additions and 863 deletions

View file

@ -1,3 +1,14 @@
2005-05-16 Benjamin Otte <in7y118@public.uni-hamburg.de>
* gst/gstprobe.[ch]:
* gst/Makefile.am:
* gst/gst.c: (init_post):
* gst/gstpad.c: (gst_real_pad_init), (gst_pad_push),
(gst_pad_pull):
* gst/gstpad.h:
* testsuite/elements/struct_i386.h:
remove probes
2005-05-16 Benjamin Otte <in7y118@public.uni-hamburg.de>
* gst/gsttrashstack.[ch]:

View file

@ -103,7 +103,6 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \
gstpipeline.c \
gstplugin.c \
gstpluginfeature.c \
gstprobe.c \
gstqueue.c \
gstquery.c \
gstscheduler.c \
@ -176,7 +175,6 @@ gst_headers = \
gstpipeline.h \
gstplugin.h \
gstpluginfeature.h \
gstprobe.h \
gstqueue.h \
gstquery.h \
gstscheduler.h \

View file

@ -581,7 +581,6 @@ init_post (void)
_gst_format_initialize ();
_gst_query_type_initialize ();
gst_object_get_type ();
gst_probe_get_type ();
gst_pad_get_type ();
gst_real_pad_get_type ();
gst_ghost_pad_get_type ();

View file

@ -1,255 +0,0 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gst_private.h"
#include <string.h> /* memset */
#include "gstutils.h"
#include "gstmemchunk.h"
#include "gsttrashstack.h"
#ifdef HAVE_VALGRIND
#include <sys/mman.h>
#include <valgrind/valgrind.h>
#endif
#define GST_MEM_CHUNK_AREA(chunk) (((GstMemChunkElement*)(chunk))->area)
#define GST_MEM_CHUNK_DATA(chunk) ((gpointer)(((GstMemChunkElement*)(chunk)) + 1))
#define GST_MEM_CHUNK_LINK(mem) ((GstMemChunkElement*)((guint8*)(mem) - sizeof (GstMemChunkElement)))
typedef struct _GstMemChunkElement GstMemChunkElement;
struct _GstMemChunkElement
{
GstTrashStackElement elem; /* make sure we can safely push it on the trashstack */
gpointer area; /* pointer to data areas */
};
struct _GstMemChunk
{
GstTrashStack stack;
gchar *name;
gulong area_size;
gulong chunk_size;
gulong atom_size;
gboolean cleanup;
};
/*******************************************************
* area size
* +-------------------------------------------------------+
* chunk size
* +-----------------+
*
* !next!area|data... !next!area!data.... !next!area!data...
* ! ^ ! ^ !
* +------------------+ +-----------------+ +--------> NULL
*
*/
static gboolean
populate (GstMemChunk * mem_chunk)
{
guint8 *area;
gint i;
if (mem_chunk->cleanup)
return FALSE;
/* FIXME: if we don't do this here and use g_malloc, valgrind crashes */
#if HAVE_VALGRIND
if (__gst_in_valgrind ()) {
/* copied from valgrind example */
area =
(guint8 *) mmap (0, mem_chunk->area_size,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
} else
#endif
{
area = g_malloc0 (mem_chunk->area_size);
}
for (i = 0; i < mem_chunk->area_size; i += mem_chunk->chunk_size) {
GST_MEM_CHUNK_AREA (area + i) = area;
gst_trash_stack_push (&mem_chunk->stack, area + i);
}
return TRUE;
}
/**
* gst_mem_chunk_new:
* @name: the name of the chunk
* @atom_size: the size of the allocated atoms
* @area_size: the initial size of the memory area
* @type: the allocation strategy to use
*
* Creates a new memchunk that will allocate atom_sized memchunks.
* The initial area is set to area_size and will grow automatically
* when it is too small (with a small overhead when that happens)
*
* Returns: a new #GstMemChunk
*/
GstMemChunk *
gst_mem_chunk_new (gchar * name, gint atom_size, gulong area_size, gint type)
{
GstMemChunk *mem_chunk;
g_return_val_if_fail (atom_size > 0, NULL);
g_return_val_if_fail (area_size >= atom_size, NULL);
mem_chunk = g_malloc (sizeof (GstMemChunk));
mem_chunk->chunk_size = atom_size + sizeof (GstMemChunkElement);
area_size = (area_size / atom_size) * mem_chunk->chunk_size;
mem_chunk->name = g_strdup (name);
mem_chunk->atom_size = atom_size;
mem_chunk->area_size = area_size;
mem_chunk->cleanup = FALSE;
gst_trash_stack_init (&mem_chunk->stack);
populate (mem_chunk);
return mem_chunk;
}
static gboolean
free_area (gpointer key, gpointer value, gpointer user_data)
{
#if HAVE_VALGRIND
GstMemChunk *chunk = (GstMemChunk *) user_data;
if (__gst_in_valgrind ()) {
/* copied from valgrind example */
munmap (key, chunk->area_size);
} else
#endif
{
g_free (key);
}
return TRUE;
}
/**
* gst_mem_chunk_destroy:
* @mem_chunk: the GstMemChunk to destroy
*
* Free the memory allocated by the memchunk
*/
void
gst_mem_chunk_destroy (GstMemChunk * mem_chunk)
{
GHashTable *elements = g_hash_table_new (NULL, NULL);
gpointer data;
mem_chunk->cleanup = TRUE;
data = gst_mem_chunk_alloc (mem_chunk);
while (data) {
GstMemChunkElement *elem = GST_MEM_CHUNK_LINK (data);
g_hash_table_insert (elements, GST_MEM_CHUNK_AREA (elem), NULL);
data = gst_mem_chunk_alloc (mem_chunk);
}
g_hash_table_foreach_remove (elements, free_area, mem_chunk);
g_hash_table_destroy (elements);
g_free (mem_chunk->name);
g_free (mem_chunk);
}
/**
* gst_mem_chunk_alloc:
* @mem_chunk: the mem chunk to use
*
* Allocate a new memory region from the chunk. The size
* of the allocated memory was specified when the memchunk
* was created.
*
* Returns: a pointer to the allocated memory region.
*/
gpointer
gst_mem_chunk_alloc (GstMemChunk * mem_chunk)
{
GstMemChunkElement *chunk;
g_return_val_if_fail (mem_chunk != NULL, NULL);
again:
chunk = gst_trash_stack_pop (&mem_chunk->stack);
/* chunk is empty, try to refill */
if (!chunk) {
if (populate (mem_chunk))
goto again;
else
return NULL;
}
#ifdef HAVE_VALGRIND
VALGRIND_MALLOCLIKE_BLOCK (GST_MEM_CHUNK_DATA (chunk), mem_chunk->atom_size,
0, 0);
#endif
return GST_MEM_CHUNK_DATA (chunk);
}
/**
* gst_mem_chunk_alloc0:
* @mem_chunk: the mem chunk to use
*
* Allocate a new memory region from the chunk. The size
* of the allocated memory was specified when the memchunk
* was created. The memory will be set to all zeroes.
*
* Returns: a pointer to the allocated memory region.
*/
gpointer
gst_mem_chunk_alloc0 (GstMemChunk * mem_chunk)
{
gpointer mem = gst_mem_chunk_alloc (mem_chunk);
if (mem)
memset (mem, 0, mem_chunk->atom_size);
return mem;
}
/**
* gst_mem_chunk_free:
* @mem_chunk: the mem chunk to use
* @mem: the memory region to hand back to the chunk
*
* Free the memeory region allocated from the chunk.
*/
void
gst_mem_chunk_free (GstMemChunk * mem_chunk, gpointer mem)
{
GstMemChunkElement *chunk;
g_return_if_fail (mem_chunk != NULL);
g_return_if_fail (mem != NULL);
chunk = GST_MEM_CHUNK_LINK (mem);
#ifdef HAVE_VALGRIND
VALGRIND_FREELIKE_BLOCK (mem, 0);
#endif
gst_trash_stack_push (&mem_chunk->stack, chunk);
}

View file

@ -286,8 +286,6 @@ gst_real_pad_init (GstRealPad * pad)
GST_FLAG_SET (pad, GST_PAD_DISABLED);
GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
gst_probe_dispatcher_init (&pad->probedisp);
}
static void
@ -3285,13 +3283,6 @@ gst_pad_push (GstPad * pad, GstData * data)
DEBUG_DATA (pad, data, "gst_pad_push");
if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data)) {
GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
"not pushing data %p, blocked by probe", data);
gst_data_unref (data);
return;
}
if (!GST_PAD_IS_LINKED (pad)) {
GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
"not pushing data %p as pad is unconnected", data);
@ -3321,13 +3312,6 @@ gst_pad_push (GstPad * pad, GstData * data)
if (peer->chainhandler) {
if (data) {
if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data)) {
GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
"not pushing data %p, blocked by probe", data);
gst_data_unref (data);
return;
}
GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
"calling chainhandler &%s of peer pad %s:%s",
GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
@ -3376,7 +3360,6 @@ gst_pad_pull (GstPad * pad)
GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
} else {
restart:
if (peer->gethandler) {
GstPadLink *link = GST_RPAD_LINK (pad);
@ -3417,13 +3400,6 @@ gst_pad_pull (GstPad * pad)
GST_DEBUG_PAD_NAME (pad));
}
}
GST_DEBUG ("calling gst_probe_dispatcher_dispatch on data %p", data);
if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data)) {
GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
"not returning pulled data %p, blocked by probe", data);
gst_data_unref (data);
goto restart;
}
DEBUG_DATA (pad, data, "gst_pad_pull returned");
return data;
}

View file

@ -30,7 +30,6 @@
#include <gst/gstbuffer.h>
#include <gst/gstcaps.h>
#include <gst/gstevent.h>
#include <gst/gstprobe.h>
#include <gst/gstquery.h>
@ -205,8 +204,6 @@ struct _GstRealPad {
GstPadBufferAllocFunction bufferallocfunc;
GstProbeDispatcher probedisp;
GstPadLink *link;
GstCaps *explicit_caps;
@ -497,11 +494,6 @@ GList* gst_pad_get_internal_links_default (GstPad *pad);
gboolean gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
gpointer data);
#define gst_pad_add_probe(pad, probe) \
(gst_probe_dispatcher_add_probe (&(GST_PAD_REALIZE (pad)->probedisp), probe))
#define gst_pad_remove_probe(pad, probe) \
(gst_probe_dispatcher_remove_probe (&(GST_PAD_REALIZE (pad)->probedisp), probe))
#ifndef GST_DISABLE_LOADSAVE
void gst_pad_load_and_link (xmlNodePtr self, GstObject *parent);
#endif

View file

@ -1,263 +0,0 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wim.taymans@chello.be>
*
* gstprobe.h: Header for GstProbe object
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gst_private.h"
#include "gstprobe.h"
static GstProbe *
_gst_probe_copy (const GstProbe * src)
{
return gst_probe_new (src->single_shot, src->callback, src->user_data);
}
GType
gst_probe_get_type (void)
{
static GType gst_probe_type = 0;
if (!gst_probe_type) {
gst_probe_type = g_boxed_type_register_static ("GstProbe",
(GBoxedCopyFunc) _gst_probe_copy, (GBoxedFreeFunc) gst_probe_destroy);
}
return gst_probe_type;
}
/**
* gst_probe_new:
* @single_shot: TRUE if a single shot probe is required
* @callback: the function to call when the probe is triggered
* @user_data: data passed to the callback function
*
* Create a new probe with the specified parameters
*
* Returns: a new #GstProbe.
*/
GstProbe *
gst_probe_new (gboolean single_shot,
GstProbeCallback callback, gpointer user_data)
{
GstProbe *probe;
g_return_val_if_fail (callback, NULL);
probe = g_new0 (GstProbe, 1);
probe->single_shot = single_shot;
probe->callback = callback;
probe->user_data = user_data;
GST_CAT_DEBUG (GST_CAT_PROBE, "created probe %p", probe);
return probe;
}
/**
* gst_probe_destroy:
* @probe: The probe to destroy
*
* Free the memory associated with the probe.
*/
void
gst_probe_destroy (GstProbe * probe)
{
g_return_if_fail (probe);
#ifdef USE_POISONING
memset (probe, 0xff, sizeof (*probe));
#endif
g_free (probe);
}
/**
* gst_probe_perform:
* @probe: The probe to trigger
* @data: the GstData that triggered the probe.
*
* Perform the callback associated with the given probe.
*
* Returns: the result of the probe callback function.
*/
gboolean
gst_probe_perform (GstProbe * probe, GstData ** data)
{
gboolean res = TRUE;
g_return_val_if_fail (probe, res);
GST_CAT_DEBUG (GST_CAT_PROBE, "performing probe %p", probe);
if (probe->callback)
res = probe->callback (probe, data, probe->user_data);
return res;
}
/**
* gst_probe_dispatcher_new:
*
* Create a new probe dispatcher
*
* Returns: a new probe dispatcher.
*/
GstProbeDispatcher *
gst_probe_dispatcher_new (void)
{
GstProbeDispatcher *disp;
disp = g_new0 (GstProbeDispatcher, 1);
gst_probe_dispatcher_init (disp);
return disp;
}
/**
* gst_probe_dispatcher_destroy:
* @disp: the dispatcher to destroy
*
* Free the memory allocated by the probe dispatcher. All pending
* probes are removed first.
*/
void
gst_probe_dispatcher_destroy (GstProbeDispatcher * disp)
{
g_return_if_fail (disp);
#ifdef USE_POISONING
memset (disp, 0xff, sizeof (*disp));
#endif
/* FIXME, free pending probes */
g_free (disp);
}
/**
* gst_probe_dispatcher_init:
* @disp: the dispatcher to initialize
*
* Initialize the dispatcher. Useful for statically allocated probe
* dispatchers.
*/
void
gst_probe_dispatcher_init (GstProbeDispatcher * disp)
{
g_return_if_fail (disp);
disp->active = TRUE;
disp->probes = NULL;
}
/**
* gst_probe_dispatcher_set_active:
* @disp: the dispatcher to activate
* @active: boolean to indicate activation or deactivation
*
* Activate or deactivate the given dispatcher
* dispatchers.
*/
void
gst_probe_dispatcher_set_active (GstProbeDispatcher * disp, gboolean active)
{
g_return_if_fail (disp);
disp->active = active;
}
/**
* gst_probe_dispatcher_add_probe:
* @disp: the dispatcher to add the probe to
* @probe: the probe to add to the dispatcher
*
* Adds the given probe to the dispatcher.
*/
void
gst_probe_dispatcher_add_probe (GstProbeDispatcher * disp, GstProbe * probe)
{
g_return_if_fail (disp);
g_return_if_fail (probe);
GST_CAT_DEBUG (GST_CAT_PROBE, "adding probe %p to dispatcher %p", probe,
disp);
disp->probes = g_slist_prepend (disp->probes, probe);
}
/**
* gst_probe_dispatcher_remove_probe:
* @disp: the dispatcher to remove the probe from
* @probe: the probe to remove from the dispatcher
*
* Removes the given probe from the dispatcher.
*/
void
gst_probe_dispatcher_remove_probe (GstProbeDispatcher * disp, GstProbe * probe)
{
g_return_if_fail (disp);
g_return_if_fail (probe);
GST_CAT_DEBUG (GST_CAT_PROBE, "removing probe %p from dispatcher %p",
probe, disp);
disp->probes = g_slist_remove (disp->probes, probe);
}
/**
* gst_probe_dispatcher_dispatch:
* @disp: the dispatcher to dispatch
* @data: the data that triggered the dispatch
*
* Trigger all registered probes on the given dispatcher.
*
* Returns: TRUE if all callbacks returned TRUE.
*/
gboolean
gst_probe_dispatcher_dispatch (GstProbeDispatcher * disp, GstData ** data)
{
GSList *walk;
gboolean res = TRUE;
g_return_val_if_fail (disp, res);
GST_CAT_DEBUG (GST_CAT_PROBE, "dispatching data %p on dispatcher %p",
*data, disp);
walk = disp->probes;
while (walk) {
GstProbe *probe = (GstProbe *) walk->data;
walk = g_slist_next (walk);
res &= gst_probe_perform (probe, data);
/* it might have disappeared in the callback */
if (disp->active &&
g_slist_find (disp->probes, probe) && probe->single_shot) {
disp->probes = g_slist_remove (disp->probes, probe);
gst_probe_destroy (probe);
}
}
return res;
}

View file

@ -1,80 +0,0 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wim.taymans@chello.be>
*
* gstprobe.h: Header for GstProbe object
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_PROBE_H__
#define __GST_PROBE_H__
#include <glib.h>
#include <gst/gstdata.h>
G_BEGIN_DECLS
#define GST_TYPE_PROBE (gst_probe_get_type())
#define GST_PROBE(object) ((GstProbe *) object)
typedef struct _GstProbe GstProbe;
GType gst_probe_get_type (void) G_GNUC_CONST;
/* the callback should return FALSE if the data should be discarded */
typedef gboolean (*GstProbeCallback) (GstProbe *probe,
GstData **data,
gpointer user_data);
struct _GstProbe {
gboolean single_shot;
GstProbeCallback callback;
gpointer user_data;
};
GstProbe* gst_probe_new (gboolean single_shot,
GstProbeCallback callback,
gpointer user_data);
void gst_probe_destroy (GstProbe *probe);
gboolean gst_probe_perform (GstProbe *probe, GstData **data);
typedef struct _GstProbeDispatcher GstProbeDispatcher;
struct _GstProbeDispatcher {
gboolean active;
GSList *probes;
};
GstProbeDispatcher* gst_probe_dispatcher_new (void);
void gst_probe_dispatcher_destroy (GstProbeDispatcher *disp);
void gst_probe_dispatcher_init (GstProbeDispatcher *disp);
void gst_probe_dispatcher_set_active (GstProbeDispatcher *disp, gboolean active);
void gst_probe_dispatcher_add_probe (GstProbeDispatcher *disp, GstProbe *probe);
void gst_probe_dispatcher_remove_probe (GstProbeDispatcher *disp, GstProbe *probe);
gboolean gst_probe_dispatcher_dispatch (GstProbeDispatcher *disp, GstData **data);
G_END_DECLS
#endif /* __GST_PROBE_H__ */

View file

@ -1,24 +0,0 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#define GST_IMPLEMENT_INLINES 1
#define __GST_TRASH_STACK_C__
#include "gst_private.h"
#include "gsttrashstack.h"

View file

@ -1,198 +0,0 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_TRASH_STACK_H__
#define __GST_TRASH_STACK_H__
#include <glib.h>
#include "gstmacros.h"
G_BEGIN_DECLS
typedef struct _GstTrashStack GstTrashStack;
typedef struct _GstTrashStackElement GstTrashStackElement;
struct _GstTrashStackElement {
GstTrashStackElement *next;
};
typedef volatile gpointer gst_vgpointer;/* gtk-doc volatile workaround */
typedef volatile gulong gst_vgulong; /* gtk-doc volatile workaround */
struct _GstTrashStack {
gst_vgpointer head;
gst_vgulong count; /* for the ABA problem */
GMutex *lock; /* lock for C fallback */
};
GST_INLINE_FUNC GstTrashStack* gst_trash_stack_new (void);
GST_INLINE_FUNC void gst_trash_stack_init (GstTrashStack *stack);
GST_INLINE_FUNC void gst_trash_stack_destroy (GstTrashStack *stack);
GST_INLINE_FUNC void gst_trash_stack_free (GstTrashStack *stack);
GST_INLINE_FUNC void gst_trash_stack_push (GstTrashStack *stack, gpointer mem);
GST_INLINE_FUNC gpointer gst_trash_stack_pop (GstTrashStack *stack);
#if defined (GST_CAN_INLINE) || defined (__GST_TRASH_STACK_C__)
#if defined (USE_FAST_STACK_TRASH) && defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
#ifdef GST_CONFIG_NO_SMP
#define SMP_LOCK ""
#else
#define SMP_LOCK "lock ; "
#endif
/*
* intel ia32 optimized lockfree implementations
*/
GST_INLINE_FUNC void
gst_trash_stack_init (GstTrashStack *stack)
{
stack->head = NULL;
stack->count = 0;
}
GST_INLINE_FUNC void
gst_trash_stack_destroy (GstTrashStack *stack)
{
}
GST_INLINE_FUNC void
gst_trash_stack_push (GstTrashStack *stack, gpointer mem)
{
__asm__ __volatile__ (
"1: \n\t"
" movl %2, (%1); \n\t" /* mem->next == stack->head */
SMP_LOCK "cmpxchg %1, %0; \n\t" /* if head unchanged, move mem into it */
" jnz 1b; \n" /* head changed, retry */
:
: "m" (*stack),
"r" (mem),
"a" (stack->head)
);
}
GST_INLINE_FUNC gpointer
gst_trash_stack_pop (GstTrashStack *stack)
{
GstTrashStackElement *head;
/* pop is a little more complicated as we need to avoid the so called ABA
* problem that arises when a pop and push of the same element happens
* right between when we read head->next and try to swing the new pointer
* into place. This is usually solved using a counter which makes it highly
* inlikely that we manage to grab the wrong head->next value.
*/
__asm__ __volatile__ (
" pushl %%ebx; \n\t"
" testl %%eax, %%eax; \n\t" /* if (head == NULL) return */
" jz 20f; \n\t"
"10: \n\t"
" movl (%%eax), %%ebx; \n\t" /* take value pointed to by head (head->next) */
" movl %%edx, %%ecx; \n\t" /* take counter */
" incl %%ecx; \n\t" /* and increment */
SMP_LOCK "cmpxchg8b %1; \n\t" /* if eax:edx == *stack, move ebx:ecx to *stack,
* else *stack is moved into eax:edx again... */
" jz 20f; \n\t" /* success */
" testl %%eax, %%eax; \n\t" /* if (head == NULL) return */
" jnz 10b; \n\t" /* else we retry */
"20: \n\t"
" popl %%ebx \n"
: "=a" (head)
: "m" (*stack),
"a" (stack->head),
"d" (stack->count)
: "ecx"
);
return head;
}
#else
/*
* generic implementation
*/
GST_INLINE_FUNC void
gst_trash_stack_init (GstTrashStack *stack)
{
stack->head = NULL;
stack->lock = g_mutex_new();
}
GST_INLINE_FUNC void
gst_trash_stack_destroy (GstTrashStack *stack)
{
g_mutex_free (stack->lock);
}
GST_INLINE_FUNC void
gst_trash_stack_push (GstTrashStack *stack, gpointer mem)
{
GstTrashStackElement *elem = (GstTrashStackElement *) mem;
g_mutex_lock (stack->lock);
elem->next = stack->head;
stack->head = elem;
g_mutex_unlock (stack->lock);
}
GST_INLINE_FUNC gpointer
gst_trash_stack_pop (GstTrashStack *stack)
{
GstTrashStackElement *head;
g_mutex_lock (stack->lock);
head = (GstTrashStackElement *) stack->head;
if (head)
stack->head = head->next;
g_mutex_unlock (stack->lock);
return head;
}
#endif
/*
* common functions
*/
GST_INLINE_FUNC GstTrashStack*
gst_trash_stack_new (void)
{
GstTrashStack *stack;
stack = g_new (GstTrashStack, 1);
gst_trash_stack_init (stack);
return stack;
}
GST_INLINE_FUNC void
gst_trash_stack_free (GstTrashStack *stack)
{
gst_trash_stack_destroy (stack);
g_free (stack);
}
#endif /* defined (GST_CAN_INLINE) || defined (__GST_TRASH_STACK_C__)*/
G_END_DECLS
#endif /* __GST_TRASH_STACK_H__ */

View file

@ -64,10 +64,6 @@ Struct list[] = {
,
{"GstPluginFeatureClass", sizeof (GstPluginFeatureClass), 88}
,
{"GstProbe", sizeof (GstProbe), 12}
,
{"GstProbeDispatcher", sizeof (GstProbeDispatcher), 8}
,
{"GstQueryTypeDefinition", sizeof (GstQueryTypeDefinition), 12}
,
{"GstQueue", sizeof (GstQueue), 252}

View file

@ -64,10 +64,6 @@ Struct list[] = {
,
{"GstPluginFeatureClass", sizeof (GstPluginFeatureClass), 88}
,
{"GstProbe", sizeof (GstProbe), 12}
,
{"GstProbeDispatcher", sizeof (GstProbeDispatcher), 8}
,
{"GstQueryTypeDefinition", sizeof (GstQueryTypeDefinition), 12}
,
{"GstQueue", sizeof (GstQueue), 252}