Add a bunch of unrefs.

Thu Dec  7 15:22:30 2000  Owen Taylor  <otaylor@redhat.com>

	* tests/mainloop-test.c (recurser_start): Add a bunch
	of unrefs.

	* gmain.c (g_source_attach): Reference the source
	when adding (pointed out by Elliot)
This commit is contained in:
Owen Taylor 2000-12-07 20:29:58 +00:00 committed by Owen Taylor
parent e5c1f207c9
commit 1084477e03
3 changed files with 26 additions and 4 deletions

View File

@ -752,6 +752,7 @@ g_source_attach (GSource *source,
source->context = context; source->context = context;
result = source->id = context->next_id++; result = source->id = context->next_id++;
source->ref_count++;
g_source_list_add (source, context); g_source_list_add (source, context);
tmp_list = source->poll_fds; tmp_list = source->poll_fds;
@ -2618,6 +2619,7 @@ g_timeout_add_full (gint priority,
GDestroyNotify notify) GDestroyNotify notify)
{ {
GSource *source; GSource *source;
guint id;
g_return_val_if_fail (function != NULL, 0); g_return_val_if_fail (function != NULL, 0);
@ -2627,7 +2629,10 @@ g_timeout_add_full (gint priority,
g_source_set_priority (source, priority); g_source_set_priority (source, priority);
g_source_set_callback (source, function, data, notify); g_source_set_callback (source, function, data, notify);
return g_source_attach (source, NULL); id = g_source_attach (source, NULL);
g_source_unref (source);
return id;
} }
/** /**
@ -2731,6 +2736,7 @@ g_idle_add_full (gint priority,
GDestroyNotify notify) GDestroyNotify notify)
{ {
GSource *source; GSource *source;
guint id;
g_return_val_if_fail (function != NULL, 0); g_return_val_if_fail (function != NULL, 0);
@ -2740,7 +2746,10 @@ g_idle_add_full (gint priority,
g_source_set_priority (source, priority); g_source_set_priority (source, priority);
g_source_set_callback (source, function, data, notify); g_source_set_callback (source, function, data, notify);
return g_source_attach (source, NULL); id = g_source_attach (source, NULL);
g_source_unref (source);
return id;
} }
/** /**

13
gmain.c
View File

@ -752,6 +752,7 @@ g_source_attach (GSource *source,
source->context = context; source->context = context;
result = source->id = context->next_id++; result = source->id = context->next_id++;
source->ref_count++;
g_source_list_add (source, context); g_source_list_add (source, context);
tmp_list = source->poll_fds; tmp_list = source->poll_fds;
@ -2618,6 +2619,7 @@ g_timeout_add_full (gint priority,
GDestroyNotify notify) GDestroyNotify notify)
{ {
GSource *source; GSource *source;
guint id;
g_return_val_if_fail (function != NULL, 0); g_return_val_if_fail (function != NULL, 0);
@ -2627,7 +2629,10 @@ g_timeout_add_full (gint priority,
g_source_set_priority (source, priority); g_source_set_priority (source, priority);
g_source_set_callback (source, function, data, notify); g_source_set_callback (source, function, data, notify);
return g_source_attach (source, NULL); id = g_source_attach (source, NULL);
g_source_unref (source);
return id;
} }
/** /**
@ -2731,6 +2736,7 @@ g_idle_add_full (gint priority,
GDestroyNotify notify) GDestroyNotify notify)
{ {
GSource *source; GSource *source;
guint id;
g_return_val_if_fail (function != NULL, 0); g_return_val_if_fail (function != NULL, 0);
@ -2740,7 +2746,10 @@ g_idle_add_full (gint priority,
g_source_set_priority (source, priority); g_source_set_priority (source, priority);
g_source_set_callback (source, function, data, notify); g_source_set_callback (source, function, data, notify);
return g_source_attach (source, NULL); id = g_source_attach (source, NULL);
g_source_unref (source);
return id;
} }
/** /**

View File

@ -138,11 +138,13 @@ adder_thread (gpointer data)
adder_source = g_io_create_watch (channels[0], G_IO_IN | G_IO_HUP); adder_source = g_io_create_watch (channels[0], G_IO_IN | G_IO_HUP);
g_source_set_callback (adder_source, (GSourceFunc)adder_callback, &addr_data, NULL); g_source_set_callback (adder_source, (GSourceFunc)adder_callback, &addr_data, NULL);
g_source_attach (adder_source, context); g_source_attach (adder_source, context);
g_source_unref (adder_source);
timeout_source = g_timeout_source_new (10); timeout_source = g_timeout_source_new (10);
g_source_set_callback (timeout_source, (GSourceFunc)timeout_callback, &addr_data, NULL); g_source_set_callback (timeout_source, (GSourceFunc)timeout_callback, &addr_data, NULL);
g_source_set_priority (timeout_source, G_PRIORITY_HIGH); g_source_set_priority (timeout_source, G_PRIORITY_HIGH);
g_source_attach (timeout_source, context); g_source_attach (timeout_source, context);
g_source_unref (timeout_source);
g_main_run (addr_data.loop); g_main_run (addr_data.loop);
@ -312,6 +314,7 @@ create_crawler (void)
G_LOCK (context_array_lock); G_LOCK (context_array_lock);
g_source_attach (source, context_array->pdata[g_random_int_range (0, context_array->len)]); g_source_attach (source, context_array->pdata[g_random_int_range (0, context_array->len)]);
g_source_unref (source);
G_UNLOCK (context_array_lock); G_UNLOCK (context_array_lock);
G_LOCK (crawler_array_lock); G_LOCK (crawler_array_lock);
@ -359,6 +362,7 @@ recurser_start (gpointer data)
source = g_idle_source_new (); source = g_idle_source_new ();
g_source_set_callback (source, recurser_idle, context, NULL); g_source_set_callback (source, recurser_idle, context, NULL);
g_source_attach (source, context); g_source_attach (source, context);
g_source_unref (source);
G_UNLOCK (context_array_lock); G_UNLOCK (context_array_lock);
return TRUE; return TRUE;