[gnome-logs/wip/current-boot: 7/7] Make GlJournalResult a ref-counted boxed type
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/current-boot: 7/7] Make GlJournalResult a ref-counted boxed type
- Date: Fri, 1 Nov 2013 11:01:56 +0000 (UTC)
commit b5a7ed7566859af9130005da1b248a9e2f32f119
Author: David King <davidk gnome org>
Date: Fri Nov 1 10:54:24 2013 +0000
Make GlJournalResult a ref-counted boxed type
src/gl-eventview.c | 14 +++++++-------
src/gl-journal.c | 46 +++++++++++++++++++++++++++++-----------------
src/gl-journal.h | 10 ++++++++--
3 files changed, 44 insertions(+), 26 deletions(-)
---
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 6851063..5785c9f 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -125,7 +125,7 @@ listbox_search_filter_func (GtkListBoxRow *row,
{
if (search_in_result (result, priv->search_text))
{
- gl_journal_result_free (priv->journal, result);
+ gl_journal_result_unref (result);
return TRUE;
}
@@ -165,7 +165,7 @@ listbox_search_filter_func (GtkListBoxRow *row,
g_free (casefolded_text);
}
- gl_journal_result_free (priv->journal, result);
+ gl_journal_result_unref (result);
}
out:
@@ -242,7 +242,7 @@ on_listbox_row_activated (GtkListBox *listbox,
gtk_stack_add_named (stack, grid, "detail");
gl_event_view_set_mode (view, GL_EVENT_VIEW_MODE_DETAIL);
- gl_journal_result_free (priv->journal, result);
+ gl_journal_result_unref (result);
return;
}
@@ -541,7 +541,7 @@ insert_journal_query_devices (GlEventView *view,
g_free (time);
}
- gl_journal_results_free (priv->journal, results);
+ gl_journal_results_free (results);
}
static void
@@ -632,7 +632,7 @@ insert_journal_query_security (GlEventView *view,
g_free (time);
}
- gl_journal_results_free (priv->journal, results);
+ gl_journal_results_free (results);
}
static void
@@ -705,7 +705,7 @@ insert_journal_query_simple (GlEventView *view,
g_free (time);
}
- gl_journal_results_free (priv->journal, results);
+ gl_journal_results_free (results);
}
static void
@@ -789,7 +789,7 @@ insert_journal_query_cmdline (GlEventView *view,
g_free (time);
}
- gl_journal_results_free (priv->journal, results);
+ gl_journal_results_free (results);
}
static GtkWidget *
diff --git a/src/gl-journal.c b/src/gl-journal.c
index af4a1bb..a7a4671 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -31,6 +31,9 @@ typedef struct
G_DEFINE_TYPE_WITH_PRIVATE (GlJournal, gl_journal, G_TYPE_OBJECT)
+G_DEFINE_BOXED_TYPE (GlJournalResult, gl_journal_result, gl_journal_result_ref,
+ gl_journal_result_unref)
+
GQuark
gl_journal_error_quark (void)
{
@@ -203,6 +206,8 @@ _gl_journal_query_result (GlJournal *self)
result = g_slice_new (GlJournalResult);
+ result->ref_count = 1;
+
ret = sd_journal_get_realtime_usec (journal, &result->timestamp);
if (ret < 0)
@@ -491,32 +496,39 @@ out:
}
static void
-_gl_journal_result_free (GlJournalResult *result,
- G_GNUC_UNUSED gpointer user_data)
+gl_journal_result_free (GlJournalResult *result,
+ G_GNUC_UNUSED gpointer user_data)
{
- free (result->cursor);
- free (result->catalog);
- g_free (result->message);
- g_free (result->comm);
- g_free (result->kernel_device);
- g_free (result->audit_session);
- g_slice_free (GlJournalResult, result);
+ gl_journal_result_unref (result);
}
void
-gl_journal_result_free (G_GNUC_UNUSED GlJournal *self,
- GlJournalResult *result)
+gl_journal_results_free (GList *results)
{
- _gl_journal_result_free (result, NULL);
+ g_list_foreach (results, (GFunc)gl_journal_result_free, NULL);
+ g_list_free (results);
+}
+
+GlJournalResult *
+gl_journal_result_ref (GlJournalResult *result)
+{
+ g_atomic_int_inc (&result->ref_count);
+ return result;
}
void
-gl_journal_results_free (G_GNUC_UNUSED GlJournal *self,
- GList *results)
+gl_journal_result_unref (GlJournalResult *result)
{
- /* As self is unused, ignore it. */
- g_list_foreach (results, (GFunc)_gl_journal_result_free, NULL);
- g_list_free (results);
+ if (g_atomic_int_dec_and_test (&result->ref_count))
+ {
+ free (result->cursor);
+ free (result->catalog);
+ g_free (result->message);
+ g_free (result->comm);
+ g_free (result->kernel_device);
+ g_free (result->audit_session);
+ g_slice_free (GlJournalResult, result);
+ }
}
GlJournal *
diff --git a/src/gl-journal.h b/src/gl-journal.h
index 47f3e37..e6ab003 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -51,6 +51,10 @@ typedef struct
typedef struct
{
+ /*< private >*/
+ guint ref_count;
+
+ /*< public >*/
guint64 timestamp;
gchar *cursor;
gchar *message;
@@ -76,10 +80,12 @@ typedef struct
#define GL_TYPE_JOURNAL (gl_journal_get_type ())
#define GL_JOURNAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_JOURNAL, GlJournal))
+GType gl_journal_result_get_type (void);
GType gl_journal_get_type (void);
GList * gl_journal_query (GlJournal *self, const GlJournalQuery *query);
-void gl_journal_result_free (G_GNUC_UNUSED GlJournal *self, GlJournalResult *result);
-void gl_journal_results_free (G_GNUC_UNUSED GlJournal *self, GList *results);
+GlJournalResult * gl_journal_result_ref (GlJournalResult *result);
+void gl_journal_result_unref (GlJournalResult *result);
+void gl_journal_results_free (GList *results);
GlJournalResult * gl_journal_query_cursor (GlJournal *self, const gchar *cursor);
GlJournal * gl_journal_new (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]