diff options
-rw-r--r-- | gtk/src/callbacks.c | 22 | ||||
-rw-r--r-- | gtk/src/callbacks.h | 1 | ||||
-rw-r--r-- | gtk/src/main.c | 1 |
3 files changed, 17 insertions, 7 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index d4728895f..da6039ce6 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -366,6 +366,7 @@ get_dvd_device_name(GDrive *gd) #endif static GHashTable *volname_hash = NULL; +static GMutex *volname_mutex = NULL; static void free_volname_key(gpointer data) @@ -414,8 +415,9 @@ get_dvd_volume_name(GDrive *gd) drive = get_dvd_device_name(gd); if (g_drive_has_media (gd)) { - if (volname_hash != NULL) - label = g_strdup(g_hash_table_lookup(volname_hash, drive)); + g_mutex_lock(volname_mutex); + label = g_strdup(g_hash_table_lookup(volname_hash, drive)); + g_mutex_unlock(volname_mutex); if (label != NULL) { if (uppers_and_unders(label)) @@ -442,6 +444,14 @@ get_dvd_volume_name(GDrive *gd) return result; } +void +ghb_volname_cache_init(void) +{ + volname_mutex = g_mutex_new(); + volname_hash = g_hash_table_new_full(g_str_hash, g_str_equal, + free_volname_key, free_volname_value); +} + gpointer ghb_cache_volnames(signal_user_data_t *ud) { @@ -452,11 +462,8 @@ ghb_cache_volnames(signal_user_data_t *ud) if (drives == NULL) return NULL; - if (volname_hash == NULL) - { - volname_hash = g_hash_table_new_full(g_str_hash, g_str_equal, - free_volname_key, free_volname_value); - } + g_mutex_lock(volname_mutex); + g_hash_table_remove_all(volname_hash); while (link != NULL) { gchar *drive = get_dvd_device_name(link->data); @@ -476,6 +483,7 @@ ghb_cache_volnames(signal_user_data_t *ud) g_object_unref(link->data); link = link->next; } + g_mutex_unlock(volname_mutex); g_list_free(drives); diff --git a/gtk/src/callbacks.h b/gtk/src/callbacks.h index 787aa4455..22de6ef7c 100644 --- a/gtk/src/callbacks.h +++ b/gtk/src/callbacks.h @@ -59,6 +59,7 @@ void ghb_inhibit_gpm(void); void wm_drive_changed(MSG *msg, signal_user_data_t *ud); #endif gpointer ghb_cache_volnames(signal_user_data_t *ud); +void ghb_volname_cache_init(void); #endif // _CALLBACKS_H_ diff --git a/gtk/src/main.c b/gtk/src/main.c index fc0a78d8c..2294666e3 100644 --- a/gtk/src/main.c +++ b/gtk/src/main.c @@ -788,6 +788,7 @@ main (int argc, char *argv[]) g_timeout_add (500, ghb_timer_cb, (gpointer)ud); // Add dvd devices to File menu + ghb_volname_cache_init(); g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL); GtkStatusIcon *si; |