[Swfdec] Branch 'as' - 4 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_context.h libswfdec/swfdec_player.c
Benjamin Otte
company at kemper.freedesktop.org
Sun Jun 17 12:48:10 PDT 2007
libswfdec/swfdec_as_context.c | 25 ++++++++++++++++++++++---
libswfdec/swfdec_as_context.h | 7 ++++++-
libswfdec/swfdec_player.c | 1 +
3 files changed, 29 insertions(+), 4 deletions(-)
New commits:
diff-tree d766f996e21c12d9fbca23b8e315cc1e79b4e784 (from c9fbb629a9fafe3cb05322ef3c7653085cd1ace9)
Author: Benjamin Otte <otte at gnome.org>
Date: Sun Jun 17 21:49:08 2007 +0200
remove leftover g_print
diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index b848ba3..4ea8f7b 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -250,7 +250,6 @@ swfdec_as_context_gc (SwfdecAsContext *c
g_return_if_fail (context->state != SWFDEC_AS_CONTEXT_NEW);
SWFDEC_INFO ("invoking the garbage collector");
- g_print ("invoking the garbage collector\n");
klass = SWFDEC_AS_CONTEXT_GET_CLASS (context);
g_assert (klass->mark);
klass->mark (context);
diff-tree c9fbb629a9fafe3cb05322ef3c7653085cd1ace9 (from parents)
Merge: 40a2b740ee548eeed3bcbe19f80e3d4590cb4451 cd9873840a332c579bd8648cf1ce1f5d11ebb098
Author: Benjamin Otte <otte at gnome.org>
Date: Sun Jun 17 21:48:29 2007 +0200
Merge branch 'as' of ssh://company@git.freedesktop.org/git/swfdec into as
diff-tree 40a2b740ee548eeed3bcbe19f80e3d4590cb4451 (from 76768f1b38f075203c04d6bdcc9d0e009b2ab2e3)
Author: Benjamin Otte <otte at gnome.org>
Date: Sun Jun 17 21:44:12 2007 +0200
enable the GC
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 0b05320..8aaebbc 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -752,6 +752,7 @@ swfdec_player_unlock (SwfdecPlayer *play
g_assert (swfdec_ring_buffer_get_n_elements (player->actions) == 0);
SWFDEC_DEBUG ("UNLOCK");
+ swfdec_as_context_maybe_gc (SWFDEC_AS_CONTEXT (player));
swfdec_player_update_mouse_cursor (player);
g_object_thaw_notify (G_OBJECT (player));
swfdec_player_emit_signals (player);
diff-tree 76768f1b38f075203c04d6bdcc9d0e009b2ab2e3 (from 51bdd4e30a331ac9d4c21748097323187eed89f9)
Author: Benjamin Otte <otte at gnome.org>
Date: Sun Jun 17 19:15:16 2007 +0200
add swfdec_as_context_maybe_gc() and bookkeeping to trigger a GC every 8MB
diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index a63cf4d..b848ba3 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -104,6 +104,7 @@ swfdec_as_context_use_mem (SwfdecAsConte
g_return_val_if_fail (bytes > 0, FALSE);
context->memory += bytes;
+ context->memory_since_gc += bytes;
return TRUE;
}
@@ -244,15 +245,33 @@ swfdec_as_context_gc (SwfdecAsContext *c
SwfdecAsContextClass *klass;
g_return_if_fail (SWFDEC_IS_AS_CONTEXT (context));
-
+ g_return_if_fail (context->frame == NULL);
/* no GC during setup */
- if (context->state == SWFDEC_AS_CONTEXT_NEW)
- return;
+ g_return_if_fail (context->state != SWFDEC_AS_CONTEXT_NEW);
+
SWFDEC_INFO ("invoking the garbage collector");
+ g_print ("invoking the garbage collector\n");
klass = SWFDEC_AS_CONTEXT_GET_CLASS (context);
g_assert (klass->mark);
klass->mark (context);
swfdec_as_context_collect (context);
+ context->memory_since_gc = 0;
+}
+
+static gboolean
+swfdec_as_context_needs_gc (SwfdecAsContext *context)
+{
+ return context->memory_since_gc >= context->memory_until_gc;
+}
+
+void
+swfdec_as_context_maybe_gc (SwfdecAsContext *context)
+{
+ g_return_if_fail (SWFDEC_IS_AS_CONTEXT (context));
+ g_return_if_fail (context->frame == NULL);
+
+ if (swfdec_as_context_needs_gc (context))
+ swfdec_as_context_gc (context);
}
/*** SWFDEC_AS_CONTEXT ***/
@@ -309,6 +328,7 @@ swfdec_as_context_init (SwfdecAsContext
{
const char *s;
+ context->memory_until_gc = 8 * 1024 * 1024; /* 8 MB before we run the GC */
context->strings = g_hash_table_new (g_str_hash, g_str_equal);
context->objects = g_hash_table_new (g_direct_hash, g_direct_equal);
diff --git a/libswfdec/swfdec_as_context.h b/libswfdec/swfdec_as_context.h
index 5d2d7ba..d9815e4 100644
--- a/libswfdec/swfdec_as_context.h
+++ b/libswfdec/swfdec_as_context.h
@@ -52,8 +52,12 @@ struct _SwfdecAsContext {
GRand * rand; /* random number generator */
GTimeVal start_time; /* time this movie started (for GetTime action) */
+ /* GC properties */
+ gsize memory_until_gc;/* amount of memory allocations that trigger a GC */
+
/* bookkeeping for GC */
- gsize memory; /* memory currently in use */
+ gsize memory; /* total memory currently in use */
+ gsize memory_since_gc;/* memory allocated since last GC run */
GHashTable * strings; /* string=>memory mapping the context manages */
GHashTable * objects; /* all objects the context manages */
@@ -108,6 +112,7 @@ void swfdec_as_object_mark (SwfdecAsOb
void swfdec_as_value_mark (SwfdecAsValue * value);
void swfdec_as_string_mark (const char * string);
void swfdec_as_context_gc (SwfdecAsContext * context);
+void swfdec_as_context_maybe_gc (SwfdecAsContext * context);
void swfdec_as_context_run (SwfdecAsContext * context);
void swfdec_as_context_return (SwfdecAsContext * context);
More information about the Swfdec
mailing list