[nautilus/gnome-3-20] query: make prepared words thread safe
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gnome-3-20] query: make prepared words thread safe
- Date: Wed, 2 Mar 2016 18:49:46 +0000 (UTC)
commit d6e68d1954056708c2107e57f21db0e35e49f1bd
Author: Carlos Soriano <csoriano gnome org>
Date: Thu Feb 25 17:00:03 2016 +0100
query: make prepared words thread safe
The query is shared between threads, so make sure we access private data
in a thread safe way.
libnautilus-private/nautilus-query.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/libnautilus-private/nautilus-query.c b/libnautilus-private/nautilus-query.c
index 86dbac4..eb66ff5 100644
--- a/libnautilus-private/nautilus-query.c
+++ b/libnautilus-private/nautilus-query.c
@@ -46,6 +46,7 @@ struct _NautilusQuery {
gboolean searching;
gboolean recursive;
char **prepared_words;
+ GMutex prepared_words_mutex;
};
static void nautilus_query_class_init (NautilusQueryClass *class);
@@ -77,6 +78,7 @@ finalize (GObject *object)
g_strfreev (query->prepared_words);
g_clear_object (&query->location);
g_clear_pointer (&query->date_range, g_ptr_array_unref);
+ g_mutex_clear (&query->prepared_words_mutex);
G_OBJECT_CLASS (nautilus_query_parent_class)->finalize (object);
}
@@ -301,6 +303,7 @@ nautilus_query_init (NautilusQuery *query)
query->location = g_file_new_for_path (g_get_home_dir ());
query->search_type = g_settings_get_enum (nautilus_preferences, "search-filter-time-type");
query->search_content = NAUTILUS_QUERY_SEARCH_CONTENT_SIMPLE;
+ g_mutex_init (&query->prepared_words_mutex);
}
static gchar *
@@ -328,6 +331,7 @@ nautilus_query_matches_string (NautilusQuery *query,
return -1;
}
+ g_mutex_lock (&query->prepared_words_mutex);
if (!query->prepared_words) {
prepared_string = prepare_string_for_compare (query->text);
query->prepared_words = g_strsplit (prepared_string, " ", -1);
@@ -347,6 +351,7 @@ nautilus_query_matches_string (NautilusQuery *query,
nonexact_malus += strlen (ptr) - strlen (query->prepared_words[idx]);
}
+ g_mutex_unlock (&query->prepared_words_mutex);
if (!found) {
g_free (prepared_string);
@@ -382,8 +387,10 @@ nautilus_query_set_text (NautilusQuery *query, const char *text)
g_free (query->text);
query->text = g_strstrip (g_strdup (text));
+ g_mutex_lock (&query->prepared_words_mutex);
g_strfreev (query->prepared_words);
query->prepared_words = NULL;
+ g_mutex_unlock (&query->prepared_words_mutex);
g_object_notify (G_OBJECT (query), "text");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]