Updating branch refs/heads/master to cdea35f8845595383d55ccbe89e2a9cb3b755d21 (commit) from 59ec6358a566fe07a9d1ce9e3b2898b524c9d7b0 (commit)
commit cdea35f8845595383d55ccbe89e2a9cb3b755d21 Author: Nick Schermer <n...@xfce.org> Date: Fri Dec 7 23:10:31 2012 +0100 Don't use deprecated glib 2.32 API. tumblerd/main.c | 2 + tumblerd/tumbler-cache-service.c | 28 ++++++------ tumblerd/tumbler-group-scheduler.c | 39 ++++++++-------- tumblerd/tumbler-lifecycle-manager.c | 35 ++++++++------- tumblerd/tumbler-lifo-scheduler.c | 39 ++++++++-------- tumblerd/tumbler-manager.c | 68 ++++++++++++++-------------- tumblerd/tumbler-registry.c | 43 +++++++++--------- tumblerd/tumbler-service.c | 32 +++++++------- tumblerd/tumbler-specialized-thumbnailer.c | 46 +++++++++++++++--- tumblerd/tumbler-utils.h | 14 ++++++ 10 files changed, 199 insertions(+), 147 deletions(-) diff --git a/tumblerd/main.c b/tumblerd/main.c index e34b135..c42989d 100644 --- a/tumblerd/main.c +++ b/tumblerd/main.c @@ -85,9 +85,11 @@ main (int argc, /* initialize the GLib type system */ g_type_init (); +#if !GLIB_CHECK_VERSION (2, 32, 0) /* initialize threading system */ if (!g_thread_supported ()) g_thread_init (NULL); +#endif /* initial the D-Bus threading system */ dbus_g_thread_init (); diff --git a/tumblerd/tumbler-cache-service.c b/tumblerd/tumbler-cache-service.c index d9ecfe6..47d0b8e 100644 --- a/tumblerd/tumbler-cache-service.c +++ b/tumblerd/tumbler-cache-service.c @@ -94,7 +94,7 @@ struct _TumblerCacheService GThreadPool *delete_pool; GThreadPool *cleanup_pool; - GMutex *mutex; + TUMBLER_MUTEX (mutex); }; struct _MoveRequest @@ -150,7 +150,7 @@ tumbler_cache_service_class_init (TumblerCacheServiceClass *klass) static void tumbler_cache_service_init (TumblerCacheService *service) { - service->mutex = g_mutex_new (); + tumbler_mutex_create (service->mutex); } @@ -202,7 +202,7 @@ tumbler_cache_service_finalize (GObject *object) dbus_g_connection_unref (service->connection); - g_mutex_free (service->mutex); + tumbler_mutex_free (service->mutex); (*G_OBJECT_CLASS (tumbler_cache_service_parent_class)->finalize) (object); } @@ -261,7 +261,7 @@ tumbler_cache_service_move_thread (gpointer data, g_return_if_fail (TUMBLER_IS_CACHE_SERVICE (service)); g_return_if_fail (request != NULL); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); if (service->cache != NULL) { @@ -278,7 +278,7 @@ tumbler_cache_service_move_thread (gpointer data, * other requests are still to be processed) */ tumbler_component_decrement_use_count (TUMBLER_COMPONENT (service)); - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); } @@ -293,7 +293,7 @@ tumbler_cache_service_copy_thread (gpointer data, g_return_if_fail (TUMBLER_IS_CACHE_SERVICE (service)); g_return_if_fail (request != NULL); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); if (service->cache != NULL) { @@ -310,7 +310,7 @@ tumbler_cache_service_copy_thread (gpointer data, * other requests are still to be processed) */ tumbler_component_decrement_use_count (TUMBLER_COMPONENT (service)); - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); } @@ -325,7 +325,7 @@ tumbler_cache_service_delete_thread (gpointer data, g_return_if_fail (TUMBLER_IS_CACHE_SERVICE (service)); g_return_if_fail (request != NULL); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); if (service->cache != NULL) tumbler_cache_delete (service->cache, (const gchar *const *)request->uris); @@ -337,7 +337,7 @@ tumbler_cache_service_delete_thread (gpointer data, * other requests are still to be processed) */ tumbler_component_decrement_use_count (TUMBLER_COMPONENT (service)); - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); } @@ -352,7 +352,7 @@ tumbler_cache_service_cleanup_thread (gpointer data, g_return_if_fail (TUMBLER_IS_CACHE_SERVICE (service)); g_return_if_fail (request != NULL); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); if (service->cache != NULL) { @@ -368,7 +368,7 @@ tumbler_cache_service_cleanup_thread (gpointer data, * other requests are still to be processed) */ tumbler_component_decrement_use_count (TUMBLER_COMPONENT (service)); - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); } @@ -395,7 +395,7 @@ tumbler_cache_service_start (TumblerCacheService *service, g_return_val_if_fail (TUMBLER_IS_CACHE_SERVICE (service), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); /* get the native D-Bus connection */ connection = dbus_g_connection_get_connection (service->connection); @@ -413,12 +413,12 @@ tumbler_cache_service_start (TumblerCacheService *service, _("Another thumbnail cache service is already running")); } - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); return FALSE; } - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); return TRUE; } diff --git a/tumblerd/tumbler-group-scheduler.c b/tumblerd/tumbler-group-scheduler.c index 1e3dd2c..49cc70d 100644 --- a/tumblerd/tumbler-group-scheduler.c +++ b/tumblerd/tumbler-group-scheduler.c @@ -34,6 +34,7 @@ #include <tumblerd/tumbler-group-scheduler.h> #include <tumblerd/tumbler-scheduler.h> +#include <tumblerd/tumbler-utils.h> @@ -93,7 +94,7 @@ struct _TumblerGroupScheduler GObject __parent__; GThreadPool *pool; - GMutex *mutex; + TUMBLER_MUTEX (mutex); GList *requests; guint group; gboolean prioritized; @@ -151,7 +152,7 @@ tumbler_group_scheduler_iface_init (TumblerSchedulerIface *iface) static void tumbler_group_scheduler_init (TumblerGroupScheduler *scheduler) { - scheduler->mutex = g_mutex_new (); + tumbler_mutex_create (scheduler->mutex); scheduler->requests = NULL; /* Note that unless we convert this boolean to a TLS (thread-local), that @@ -187,7 +188,7 @@ tumbler_group_scheduler_finalize (GObject *object) g_free (scheduler->name); /* destroy the mutex */ - g_mutex_free (scheduler->mutex); + tumbler_mutex_free (scheduler->mutex); (*G_OBJECT_CLASS (tumbler_group_scheduler_parent_class)->finalize) (object); } @@ -246,7 +247,7 @@ tumbler_group_scheduler_push (TumblerScheduler *scheduler, g_return_if_fail (TUMBLER_IS_GROUP_SCHEDULER (scheduler)); g_return_if_fail (request != NULL); - g_mutex_lock (group_scheduler->mutex); + tumbler_mutex_lock (group_scheduler->mutex); /* gain ownership over the requests (sets request->scheduler) */ tumbler_scheduler_take_request (scheduler, request); @@ -257,7 +258,7 @@ tumbler_group_scheduler_push (TumblerScheduler *scheduler, /* enqueue the request in the pool */ g_thread_pool_push (group_scheduler->pool, request, NULL); - g_mutex_unlock (group_scheduler->mutex); + tumbler_mutex_unlock (group_scheduler->mutex); } @@ -272,14 +273,14 @@ tumbler_group_scheduler_dequeue (TumblerScheduler *scheduler, g_return_if_fail (TUMBLER_IS_GROUP_SCHEDULER (scheduler)); g_return_if_fail (handle != 0); - g_mutex_lock (group_scheduler->mutex); + tumbler_mutex_lock (group_scheduler->mutex); /* dequeue all requests (usually only one) with this handle */ g_list_foreach (group_scheduler->requests, (GFunc) tumbler_group_scheduler_dequeue_request, GUINT_TO_POINTER (handle)); - g_mutex_unlock (group_scheduler->mutex); + tumbler_mutex_unlock (group_scheduler->mutex); } @@ -301,7 +302,7 @@ tumbler_group_scheduler_cancel_by_mount (TumblerScheduler *scheduler, /* determine the root mount point */ mount_point = g_mount_get_root (mount); - g_mutex_lock (group_scheduler->mutex); + tumbler_mutex_lock (group_scheduler->mutex); /* iterate over all requests */ for (iter = group_scheduler->requests; iter != NULL; iter = iter->next) @@ -323,7 +324,7 @@ tumbler_group_scheduler_cancel_by_mount (TumblerScheduler *scheduler, } } - g_mutex_unlock (group_scheduler->mutex); + tumbler_mutex_unlock (group_scheduler->mutex); /* release the mount point */ g_object_unref (mount_point); @@ -438,27 +439,27 @@ tumbler_group_scheduler_thread (gpointer data, request->origin); /* finish the request if it was dequeued */ - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); if (request->dequeued) { tumbler_group_scheduler_finish_request (scheduler, request); - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); return; } - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); /* process URI by URI */ for (n = 0; n < request->length; ++n) { /* finish the request if it was dequeued */ - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); if (request->dequeued) { tumbler_group_scheduler_finish_request (scheduler, request); - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); return; } - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); /* ignore the the URI if has been cancelled already */ if (g_cancellable_is_cancelled (request->cancellables[n])) @@ -537,13 +538,13 @@ tumbler_group_scheduler_thread (gpointer data, n = GPOINTER_TO_INT (lp->data); /* finish the request if it was dequeued */ - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); if (request->dequeued) { tumbler_group_scheduler_finish_request (scheduler, request); return; } - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); /* connect to the error signal of the thumbnailer */ g_signal_connect (request->thumbnailers[n], "error", @@ -566,7 +567,7 @@ tumbler_group_scheduler_thread (gpointer data, 0, 0, NULL, NULL, request); } - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); /* We emit all the errors and ready signals together in order to * reduce the overall D-Bus traffic */ @@ -649,7 +650,7 @@ tumbler_group_scheduler_thread (gpointer data, /* notify others that we're finished processing the request */ tumbler_group_scheduler_finish_request (scheduler, request); - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); } diff --git a/tumblerd/tumbler-lifecycle-manager.c b/tumblerd/tumbler-lifecycle-manager.c index 00a381c..ee4ae10 100644 --- a/tumblerd/tumbler-lifecycle-manager.c +++ b/tumblerd/tumbler-lifecycle-manager.c @@ -29,6 +29,7 @@ #include <tumbler/tumbler.h> #include <tumblerd/tumbler-lifecycle-manager.h> +#include <tumblerd/tumbler-utils.h> @@ -58,7 +59,7 @@ struct _TumblerLifecycleManager { GObject __parent__; - GMutex *lock; + TUMBLER_MUTEX (lock); guint timeout_id; guint component_use_count; @@ -103,7 +104,7 @@ tumbler_lifecycle_manager_class_init (TumblerLifecycleManagerClass *klass) static void tumbler_lifecycle_manager_init (TumblerLifecycleManager *manager) { - manager->lock = g_mutex_new (); + tumbler_mutex_create (manager->lock); manager->timeout_id = 0; manager->component_use_count = 0; manager->shutdown_emitted = FALSE; @@ -114,9 +115,11 @@ tumbler_lifecycle_manager_init (TumblerLifecycleManager *manager) static void tumbler_lifecycle_manager_finalize (GObject *object) { +#if !GLIB_CHECK_VERSION (2, 32, 0) TumblerLifecycleManager *manager = TUMBLER_LIFECYCLE_MANAGER (object); +#endif - g_mutex_free (manager->lock); + tumbler_mutex_free (TUMBLER_LIFECYCLE_MANAGER (object)->lock); (*G_OBJECT_CLASS (tumbler_lifecycle_manager_parent_class)->finalize) (object); } @@ -128,12 +131,12 @@ tumbler_lifecycle_manager_timeout (TumblerLifecycleManager *manager) { g_return_val_if_fail (TUMBLER_IS_LIFECYCLE_MANAGER (manager), FALSE); - g_mutex_lock (manager->lock); + tumbler_mutex_lock (manager->lock); /* reschedule the timeout if one of the components is still in use */ if (manager->component_use_count > 0) { - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); return TRUE; } @@ -147,7 +150,7 @@ tumbler_lifecycle_manager_timeout (TumblerLifecycleManager *manager) * reschedule the timeout */ manager->shutdown_emitted = TRUE; - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); return FALSE; } @@ -167,12 +170,12 @@ tumbler_lifecycle_manager_start (TumblerLifecycleManager *manager) { g_return_if_fail (TUMBLER_IS_LIFECYCLE_MANAGER (manager)); - g_mutex_lock (manager->lock); + tumbler_mutex_lock (manager->lock); /* ignore if there already is a timeout scheduled */ if (manager->timeout_id > 0) { - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); return; } @@ -181,7 +184,7 @@ tumbler_lifecycle_manager_start (TumblerLifecycleManager *manager) (GSourceFunc) tumbler_lifecycle_manager_timeout, manager); - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); } @@ -193,13 +196,13 @@ tumbler_lifecycle_manager_keep_alive (TumblerLifecycleManager *manager, g_return_val_if_fail (TUMBLER_IS_LIFECYCLE_MANAGER (manager), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_mutex_lock (manager->lock); + tumbler_mutex_lock (manager->lock); /* if the shutdown signal has been emitted, there's nothing * we can do to prevent a shutdown anymore */ if (manager->shutdown_emitted) { - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); if (error != NULL) { @@ -220,7 +223,7 @@ tumbler_lifecycle_manager_keep_alive (TumblerLifecycleManager *manager, (GSourceFunc) tumbler_lifecycle_manager_timeout, manager); - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); return TRUE; } @@ -232,11 +235,11 @@ tumbler_lifecycle_manager_increment_use_count (TumblerLifecycleManager *manager) { g_return_if_fail (TUMBLER_IS_LIFECYCLE_MANAGER (manager)); - g_mutex_lock (manager->lock); + tumbler_mutex_lock (manager->lock); manager->component_use_count += 1; - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); } @@ -246,11 +249,11 @@ tumbler_lifecycle_manager_decrement_use_count (TumblerLifecycleManager *manager) { g_return_if_fail (TUMBLER_IS_LIFECYCLE_MANAGER (manager)); - g_mutex_lock (manager->lock); + tumbler_mutex_lock (manager->lock); /* decrement the use count, make sure not to drop below zero */ if (manager->component_use_count > 0) manager->component_use_count -= 1; - g_mutex_unlock (manager->lock); + tumbler_mutex_unlock (manager->lock); } diff --git a/tumblerd/tumbler-lifo-scheduler.c b/tumblerd/tumbler-lifo-scheduler.c index 8cc7e82..8445872 100644 --- a/tumblerd/tumbler-lifo-scheduler.c +++ b/tumblerd/tumbler-lifo-scheduler.c @@ -34,6 +34,7 @@ #include <tumblerd/tumbler-lifo-scheduler.h> #include <tumblerd/tumbler-scheduler.h> +#include <tumblerd/tumbler-utils.h> @@ -89,7 +90,7 @@ struct _TumblerLifoScheduler GObject __parent__; GThreadPool *pool; - GMutex *mutex; + TUMBLER_MUTEX (mutex); GList *requests; gchar *name; @@ -135,7 +136,7 @@ tumbler_lifo_scheduler_iface_init (TumblerSchedulerIface *iface) static void tumbler_lifo_scheduler_init (TumblerLifoScheduler *scheduler) { - scheduler->mutex = g_mutex_new (); + tumbler_mutex_create (scheduler->mutex); scheduler->requests = NULL; /* allocate a thread pool with a maximum of one thread */ @@ -167,7 +168,7 @@ tumbler_lifo_scheduler_finalize (GObject *object) g_free (scheduler->name); /* destroy the mutex */ - g_mutex_free (scheduler->mutex); + tumbler_mutex_free (scheduler->mutex); (*G_OBJECT_CLASS (tumbler_lifo_scheduler_parent_class)->finalize) (object); } @@ -225,7 +226,7 @@ tumbler_lifo_scheduler_push (TumblerScheduler *scheduler, g_return_if_fail (TUMBLER_IS_LIFO_SCHEDULER (scheduler)); g_return_if_fail (request != NULL); - g_mutex_lock (lifo_scheduler->mutex); + tumbler_mutex_lock (lifo_scheduler->mutex); /* gain ownership over the requests (sets request->scheduler) */ tumbler_scheduler_take_request (scheduler, request); @@ -236,7 +237,7 @@ tumbler_lifo_scheduler_push (TumblerScheduler *scheduler, /* enqueue the request in the pool */ g_thread_pool_push (lifo_scheduler->pool, request, NULL); - g_mutex_unlock (lifo_scheduler->mutex); + tumbler_mutex_unlock (lifo_scheduler->mutex); } @@ -250,14 +251,14 @@ tumbler_lifo_scheduler_dequeue (TumblerScheduler *scheduler, g_return_if_fail (TUMBLER_IS_LIFO_SCHEDULER (scheduler)); g_return_if_fail (handle != 0); - g_mutex_lock (lifo_scheduler->mutex); + tumbler_mutex_lock (lifo_scheduler->mutex); /* dequeue all requests (usually only one) with this handle */ g_list_foreach (lifo_scheduler->requests, (GFunc) tumbler_lifo_scheduler_dequeue_request, GUINT_TO_POINTER (handle)); - g_mutex_unlock (lifo_scheduler->mutex); + tumbler_mutex_unlock (lifo_scheduler->mutex); } @@ -279,7 +280,7 @@ tumbler_lifo_scheduler_cancel_by_mount (TumblerScheduler *scheduler, /* determine the root mount point */ mount_point = g_mount_get_root (mount); - g_mutex_lock (lifo_scheduler->mutex); + tumbler_mutex_lock (lifo_scheduler->mutex); /* iterate over all requests */ for (iter = lifo_scheduler->requests; iter != NULL; iter = iter->next) @@ -301,7 +302,7 @@ tumbler_lifo_scheduler_cancel_by_mount (TumblerScheduler *scheduler, } } - g_mutex_unlock (lifo_scheduler->mutex); + tumbler_mutex_unlock (lifo_scheduler->mutex); /* release the mount point */ g_object_unref (mount_point); @@ -374,27 +375,27 @@ tumbler_lifo_scheduler_thread (gpointer data, request->origin); /* finish the request if it was already dequeued */ - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); if (request->dequeued) { tumbler_lifo_scheduler_finish_request (scheduler, request); - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); return; } - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); /* process URI by URI */ for (n = 0; n < request->length; ++n) { /* finish the request if it was dequeued */ - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); if (request->dequeued) { tumbler_lifo_scheduler_finish_request (scheduler, request); - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); return; } - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); /* ignore the the URI if has been cancelled already */ if (g_cancellable_is_cancelled (request->cancellables[n])) @@ -469,9 +470,9 @@ tumbler_lifo_scheduler_thread (gpointer data, /* finish the request if it was dequeued */ if (request->dequeued) { - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); tumbler_lifo_scheduler_finish_request (scheduler, request); - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); return; } @@ -503,12 +504,12 @@ tumbler_lifo_scheduler_thread (gpointer data, /* free list */ g_list_free (missing_uris); - g_mutex_lock (scheduler->mutex); + tumbler_mutex_lock (scheduler->mutex); /* notify others that we're finished processing the request */ tumbler_lifo_scheduler_finish_request (scheduler, request); - g_mutex_unlock (scheduler->mutex); + tumbler_mutex_unlock (scheduler->mutex); } diff --git a/tumblerd/tumbler-manager.c b/tumblerd/tumbler-manager.c index e8bf162..db5d64e 100644 --- a/tumblerd/tumbler-manager.c +++ b/tumblerd/tumbler-manager.c @@ -127,7 +127,7 @@ struct _TumblerManager * (smaller directory index) coming first */ GHashTable *thumbnailers; - GMutex *mutex; + TUMBLER_MUTEX (mutex); }; struct _OverrideInfo @@ -187,7 +187,7 @@ tumbler_manager_init (TumblerManager *manager) { manager->directories = NULL; manager->monitors = NULL; - manager->mutex = g_mutex_new (); + tumbler_mutex_create (manager->mutex); /* create the overrides info hash table */ manager->overrides = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -224,7 +224,7 @@ tumbler_manager_finalize (GObject *object) { TumblerManager *manager = TUMBLER_MANAGER (object); - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); /* release all thumbnailer directory monitors */ g_list_foreach (manager->monitors, (GFunc) tumbler_manager_monitor_unref, manager); @@ -244,10 +244,10 @@ tumbler_manager_finalize (GObject *object) /* release the D-Bus connection object */ dbus_g_connection_unref (manager->connection); - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); /* destroy the mutex */ - g_mutex_free (manager->mutex); + tumbler_mutex_free (manager->mutex); (*G_OBJECT_CLASS (tumbler_manager_parent_class)->finalize) (object); } @@ -1188,13 +1188,13 @@ tumbler_manager_load (TumblerManager *manager) g_return_if_fail (TUMBLER_MANAGER (manager)); - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); /* this function may only be called once */ g_assert (manager->directories == NULL); g_assert (manager->monitors == NULL); - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); /* prepend $XDG_DATA_HOME/thumbnailers/ to the directory list */ dirname = g_build_filename (g_get_user_data_dir (), "thumbnailers", NULL); @@ -1216,7 +1216,7 @@ tumbler_manager_load (TumblerManager *manager) * priority come first */ directories = g_list_reverse (directories); - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); /* pass the ownership of the directories list to the manager */ manager->directories = directories; @@ -1246,7 +1246,7 @@ tumbler_manager_load (TumblerManager *manager) manager->monitors = g_list_prepend (manager->monitors, monitor); } - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } @@ -1561,46 +1561,46 @@ tumbler_manager_directory_changed (TumblerManager *manager, #ifdef DEBUG g_debug (" %s deleted", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_unload_overrides_file (manager, file); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_overrides (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } else if (g_str_has_suffix (base_name, ".service")) { #ifdef DEBUG g_debug (" %s deleted", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_thumbnailer_file_deleted (manager, file); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_thumbnailers (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } else { #ifdef DEBUG g_debug (" %s deleted", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); dir_index = tumbler_manager_get_dir_index (manager, file); - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); if (dir_index >= 0) { - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_directory_deleted (manager, file, dir_index); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_overrides (manager); dump_thumbnailers (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } } } @@ -1619,27 +1619,27 @@ tumbler_manager_directory_changed (TumblerManager *manager, #ifdef DEBUG g_debug (" %s created", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_load_overrides_file (manager, file); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_overrides (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } else if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { #ifdef DEBUG g_debug (" %s changed", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_unload_overrides_file (manager, file); tumbler_manager_load_overrides_file (manager, file); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_overrides (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } } else if (g_str_has_suffix (base_name, ".service")) @@ -1649,35 +1649,35 @@ tumbler_manager_directory_changed (TumblerManager *manager, #ifdef DEBUG g_debug (" %s created", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_load_thumbnailer (manager, file); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_thumbnailers (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } else if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { #ifdef DEBUG g_debug (" %s changed", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_thumbnailer_file_deleted (manager, file); tumbler_manager_load_thumbnailer (manager, file); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_thumbnailers (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } } } else { - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); dir_index = tumbler_manager_get_dir_index (manager, file); - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); if (dir_index >= 0) { @@ -1685,14 +1685,14 @@ tumbler_manager_directory_changed (TumblerManager *manager, g_debug (" %s created", g_file_get_path (file)); #endif - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); tumbler_manager_directory_created (manager, file, dir_index); tumbler_registry_update_supported (manager->registry); #ifdef DEBUG dump_overrides (manager); dump_thumbnailers (manager); #endif - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); } } } @@ -1850,7 +1850,7 @@ tumbler_manager_start (TumblerManager *manager, g_return_val_if_fail (TUMBLER_IS_MANAGER (manager), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); /* get the native D-Bus connection */ connection = dbus_g_connection_get_connection (manager->connection); @@ -1868,13 +1868,13 @@ tumbler_manager_start (TumblerManager *manager, _("Another thumbnailer manager is already running")); } - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); /* i can't work like this! */ return FALSE; } - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); /* load thumbnailers installed into the system permanently */ tumbler_manager_load (manager); @@ -1900,7 +1900,7 @@ tumbler_manager_register (TumblerManager *manager, sender_name = dbus_g_method_get_sender (context); - g_mutex_lock (manager->mutex); + tumbler_mutex_lock (manager->mutex); thumbnailer = tumbler_specialized_thumbnailer_new_foreign (manager->connection, sender_name, uri_schemes, @@ -1910,7 +1910,7 @@ tumbler_manager_register (TumblerManager *manager, g_object_unref (thumbnailer); - g_mutex_unlock (manager->mutex); + tumbler_mutex_unlock (manager->mutex); g_free (sender_name); diff --git a/tumblerd/tumbler-registry.c b/tumblerd/tumbler-registry.c index 4171b75..37c0e67 100644 --- a/tumblerd/tumbler-registry.c +++ b/tumblerd/tumbler-registry.c @@ -29,6 +29,7 @@ #include <tumblerd/tumbler-registry.h> #include <tumblerd/tumbler-specialized-thumbnailer.h> +#include <tumblerd/tumbler-utils.h> @@ -56,7 +57,7 @@ struct _TumblerRegistry GHashTable *thumbnailers; GHashTable *preferred_thumbnailers; - GMutex *mutex; + TUMBLER_MUTEX (mutex); gchar **uri_schemes; gchar **mime_types; @@ -90,7 +91,7 @@ tumbler_registry_class_init (TumblerRegistryClass *klass) static void tumbler_registry_init (TumblerRegistry *registry) { - registry->mutex = g_mutex_new (); + tumbler_mutex_create (registry->mutex); registry->thumbnailers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, tumbler_registry_list_free); registry->preferred_thumbnailers = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -113,7 +114,7 @@ tumbler_registry_finalize (GObject *object) g_strfreev (registry->mime_types); /* destroy the mutex */ - g_mutex_free (registry->mutex); + tumbler_mutex_free (registry->mutex); (*G_OBJECT_CLASS (tumbler_registry_parent_class)->finalize) (object); } @@ -348,7 +349,7 @@ tumbler_registry_add (TumblerRegistry *registry, g_return_if_fail (TUMBLER_IS_REGISTRY (registry)); g_return_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer)); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); /* determine the hash keys (all combinations of URI schemes and MIME types) * for this thumbnailer */ @@ -390,7 +391,7 @@ tumbler_registry_add (TumblerRegistry *registry, dump_registry (registry); #endif - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); } @@ -402,7 +403,7 @@ tumbler_registry_remove (TumblerRegistry *registry, g_return_if_fail (TUMBLER_IS_REGISTRY (registry)); g_return_if_fail (TUMBLER_IS_THUMBNAILER (thumbnailer)); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); g_signal_handlers_disconnect_matched (thumbnailer, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, registry); @@ -411,7 +412,7 @@ tumbler_registry_remove (TumblerRegistry *registry, g_hash_table_foreach (registry->thumbnailers, (GHFunc) tumbler_registry_remove_thumbnailer, thumbnailer); - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); } @@ -423,11 +424,11 @@ tumbler_registry_get_thumbnailers (TumblerRegistry *registry) g_return_val_if_fail (TUMBLER_IS_REGISTRY (registry), NULL); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); thumbnailers = tumbler_registry_get_thumbnailers_internal (registry); - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); /* return all active thumbnailers */ return thumbnailers; @@ -456,7 +457,7 @@ tumbler_registry_get_thumbnailer_array (TumblerRegistry *registry, /* iterate over all URIs */ for (n = 0; n < length; ++n) { - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); /* determine the URI scheme and generate a hash key */ scheme = g_uri_parse_scheme (tumbler_file_info_get_uri (infos[n])); @@ -470,7 +471,7 @@ tumbler_registry_get_thumbnailer_array (TumblerRegistry *registry, g_free (hash_key); g_free (scheme); - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); } /* NULL-terminate the array */ @@ -506,7 +507,7 @@ tumbler_registry_update_supported (TumblerRegistry *registry) g_return_if_fail (TUMBLER_IS_REGISTRY (registry)); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); /* free the old cache */ g_strfreev (registry->uri_schemes); @@ -517,7 +518,7 @@ tumbler_registry_update_supported (TumblerRegistry *registry) /* get a list of all active thumbnailers */ thumbnailers = tumbler_registry_get_thumbnailers_internal (registry); - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); /* abort if there are no thumbnailers */ if (thumbnailers == NULL) @@ -595,7 +596,7 @@ tumbler_registry_update_supported (TumblerRegistry *registry) n = g_hash_table_size (unique_pairs); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); /* allocate a string array for the URI scheme / MIME type pairs */ registry->uri_schemes = g_new0 (gchar *, n+1); @@ -617,7 +618,7 @@ tumbler_registry_update_supported (TumblerRegistry *registry) registry->uri_schemes[n] = NULL; registry->mime_types[n] = NULL; - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); /* destroy the hash table we used */ g_hash_table_unref (unique_pairs); @@ -636,7 +637,7 @@ tumbler_registry_get_supported (TumblerRegistry *registry, { g_return_if_fail (TUMBLER_IS_REGISTRY (registry)); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); if (uri_schemes != NULL) *uri_schemes = (const gchar *const *)registry->uri_schemes; @@ -644,7 +645,7 @@ tumbler_registry_get_supported (TumblerRegistry *registry, if (mime_types != NULL) *mime_types = (const gchar *const *)registry->mime_types; - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); } @@ -658,9 +659,9 @@ tumbler_registry_get_preferred (TumblerRegistry *registry, g_return_val_if_fail (TUMBLER_IS_REGISTRY (registry), NULL); g_return_val_if_fail (hash_key != NULL && *hash_key != '\0', NULL); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); thumbnailer = g_hash_table_lookup (registry->preferred_thumbnailers, hash_key); - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); return thumbnailer != NULL ? g_object_ref (thumbnailer) : NULL; } @@ -676,7 +677,7 @@ tumbler_registry_set_preferred (TumblerRegistry *registry, g_return_if_fail (hash_key != NULL && *hash_key != '\0'); g_return_if_fail (thumbnailer == NULL || TUMBLER_IS_THUMBNAILER (thumbnailer)); - g_mutex_lock (registry->mutex); + tumbler_mutex_lock (registry->mutex); if (thumbnailer == NULL) { @@ -692,5 +693,5 @@ tumbler_registry_set_preferred (TumblerRegistry *registry, dump_registry (registry); #endif - g_mutex_unlock (registry->mutex); + tumbler_mutex_unlock (registry->mutex); } diff --git a/tumblerd/tumbler-service.c b/tumblerd/tumbler-service.c index 3039df9..d46a2db 100644 --- a/tumblerd/tumbler-service.c +++ b/tumblerd/tumbler-service.c @@ -122,7 +122,7 @@ struct _TumblerService DBusGConnection *connection; TumblerRegistry *registry; - GMutex *mutex; + TUMBLER_MUTEX (mutex); GList *schedulers; GVolumeMonitor *volume_monitor; @@ -232,7 +232,7 @@ tumbler_service_class_init (TumblerServiceClass *klass) static void tumbler_service_init (TumblerService *service) { - service->mutex = g_mutex_new (); + tumbler_mutex_create (service->mutex); service->schedulers = NULL; service->volume_monitor = g_volume_monitor_get (); @@ -329,7 +329,7 @@ tumbler_service_finalize (GObject *object) dbus_g_connection_unref (service->connection); - g_mutex_free (service->mutex); + tumbler_mutex_free (service->mutex); (*G_OBJECT_CLASS (tumbler_service_parent_class)->finalize) (object); } @@ -687,13 +687,13 @@ tumbler_service_pre_unmount (TumblerService *service, g_return_if_fail (G_IS_MOUNT (mount)); g_return_if_fail (volume_monitor == service->volume_monitor); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); /* iterate over all schedulers, cancelling URIs belonging to the mount */ for (iter = service->schedulers; iter != NULL; iter = iter->next) tumbler_scheduler_cancel_by_mount (iter->data, mount); - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); } @@ -740,7 +740,7 @@ tumbler_service_start (TumblerService *service, g_return_val_if_fail (TUMBLER_IS_SERVICE (service), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); /* get the native D-Bus connection */ connection = dbus_g_connection_get_connection (service->connection); @@ -758,12 +758,12 @@ tumbler_service_start (TumblerService *service, _("Another generic thumbnailer is already running")); } - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); return FALSE; } - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); return TRUE; } @@ -795,7 +795,7 @@ tumbler_service_queue (TumblerService *service, dbus_async_return_if_fail (uris != NULL, context); dbus_async_return_if_fail (mime_hints != NULL, context); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); /* prevent the lifecycle manager to shut down the service as long * as the request is still being processed */ @@ -884,7 +884,7 @@ tumbler_service_queue (TumblerService *service, /* free the thumbnailer array */ tumbler_thumbnailer_array_free (thumbnailers, length); - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); dbus_g_method_return (context, handle); @@ -903,7 +903,7 @@ tumbler_service_dequeue (TumblerService *service, dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); if (handle != 0) { @@ -916,7 +916,7 @@ tumbler_service_dequeue (TumblerService *service, } } - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); dbus_g_method_return (context); @@ -935,12 +935,12 @@ tumbler_service_get_supported (TumblerService *service, dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); /* fetch all supported URI scheme / MIME type pairs from the registry */ tumbler_registry_get_supported (service->registry, &uri_schemes, &mime_types); - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); /* return the arrays to the caller */ dbus_g_method_return (context, uri_schemes, mime_types); @@ -1006,7 +1006,7 @@ tumbler_service_get_schedulers (TumblerService *service, dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context); - g_mutex_lock (service->mutex); + tumbler_mutex_lock (service->mutex); /* allocate an error for the schedulers */ supported_schedulers = g_new0 (gchar *, g_list_length (service->schedulers) + 2); @@ -1021,7 +1021,7 @@ tumbler_service_get_schedulers (TumblerService *service, tumbler_scheduler_get_name (TUMBLER_SCHEDULER (iter->data)); } - g_mutex_unlock (service->mutex); + tumbler_mutex_unlock (service->mutex); /* NULL-terminate the array */ supported_schedulers[n] = NULL; diff --git a/tumblerd/tumbler-specialized-thumbnailer.c b/tumblerd/tumbler-specialized-thumbnailer.c index ec6d80f..955a021 100644 --- a/tumblerd/tumbler-specialized-thumbnailer.c +++ b/tumblerd/tumbler-specialized-thumbnailer.c @@ -30,6 +30,7 @@ #include <tumbler/tumbler-marshal.h> #include <tumblerd/tumbler-specialized-thumbnailer.h> +#include <tumblerd/tumbler-utils.h> @@ -92,8 +93,12 @@ struct _TumblerSpecializedThumbnailer struct _SpecializedInfo { TumblerThumbnailer *thumbnailer; +#if GLIB_CHECK_VERSION (2, 32, 0) + GCond condition; +#else GCond *condition; - GMutex *mutex; +#endif + TUMBLER_MUTEX (mutex); const gchar *uri; const gchar *mime_type; gboolean had_callback; @@ -378,10 +383,14 @@ specialized_finished (DBusGProxy *proxy, if (info->handle == handle) { - g_mutex_lock (info->mutex); + tumbler_mutex_lock (info->mutex); +#if GLIB_CHECK_VERSION (2, 32, 0) + g_cond_broadcast (&info->condition); +#else g_cond_broadcast (info->condition); +#endif info->had_callback = TRUE; - g_mutex_unlock (info->mutex); + tumbler_mutex_unlock (info->mutex); } } @@ -392,7 +401,11 @@ tumbler_specialized_thumbnailer_create (TumblerThumbnailer *thumbnailer, { TumblerSpecializedThumbnailer *s; SpecializedInfo sinfo; +#if GLIB_CHECK_VERSION (2, 32, 0) + gint64 end_time; +#else GTimeVal timev; +#endif TumblerThumbnail *thumbnail; TumblerThumbnailFlavor *flavor; const gchar *flavor_name; @@ -409,9 +422,13 @@ tumbler_specialized_thumbnailer_create (TumblerThumbnailer *thumbnailer, s = TUMBLER_SPECIALIZED_THUMBNAILER (thumbnailer); +#if GLIB_CHECK_VERSION (2, 32, 0) + g_cond_init (&sinfo.condition); +#else sinfo.condition = g_cond_new (); +#endif sinfo.had_callback = FALSE; - sinfo.mutex = g_mutex_new (); + tumbler_mutex_create (sinfo.mutex); sinfo.uri = uri; sinfo.mime_type = tumbler_file_info_get_mime_type (info); sinfo.thumbnailer = thumbnailer; @@ -445,25 +462,32 @@ tumbler_specialized_thumbnailer_create (TumblerThumbnailer *thumbnailer, if (error == NULL) { + /* 100 seconds worth of timeout */ +#if GLIB_CHECK_VERSION (2, 32, 0) + end_time = g_get_monotonic_time () + 100 * G_TIME_SPAN_SECOND; +#else g_get_current_time (&timev); - - /* 100 seconds worth of timeout */ g_time_val_add (&timev, 100000000); +#endif - g_mutex_lock (sinfo.mutex); + tumbler_mutex_lock (sinfo.mutex); /* we are a thread, so the mainloop will still be * be running to receive the error and ready signals */ if (!sinfo.had_callback) { +#if GLIB_CHECK_VERSION (2, 32, 0) + if (!g_cond_wait_until (&sinfo.condition, &sinfo.mutex, end_time)) +#else if (!g_cond_timed_wait (sinfo.condition, sinfo.mutex, &timev)) +#endif { message = g_strdup (_("Failed to call the specialized thumbnailer: timeout")); g_signal_emit_by_name (thumbnailer, "error", uri, 1, message); g_free (message); } } - g_mutex_unlock (sinfo.mutex); + tumbler_mutex_unlock (sinfo.mutex); } else { @@ -485,6 +509,12 @@ tumbler_specialized_thumbnailer_create (TumblerThumbnailer *thumbnailer, dbus_g_proxy_disconnect_signal (s->proxy, "Error", G_CALLBACK (specialized_error), &sinfo); + +#if GLIB_CHECK_VERSION (2, 32, 0) + g_cond_clear (&sinfo.condition); +#else + g_cond_free (sinfo.condition); +#endif } static void diff --git a/tumblerd/tumbler-utils.h b/tumblerd/tumbler-utils.h index 9b0adfc..4553de9 100644 --- a/tumblerd/tumbler-utils.h +++ b/tumblerd/tumbler-utils.h @@ -41,6 +41,20 @@ G_BEGIN_DECLS } \ }G_STMT_END +#if GLIB_CHECK_VERSION (2, 32, 0) +#define TUMBLER_MUTEX(mtx) GMutex mtx +#define tumbler_mutex_free(mtx) G_STMT_START{ (void)0; }G_STMT_END +#define tumbler_mutex_lock(mtx) g_mutex_lock (&(mtx)) +#define tumbler_mutex_unlock(mtx) g_mutex_unlock (&(mtx)) +#define tumbler_mutex_create(mtx) g_mutex_init (&(mtx)) +#else +#define TUMBLER_MUTEX(mtx) GMutex *mtx +#define tumbler_mutex_free(mtx) g_mutex_free (mtx) +#define tumbler_mutex_lock(mtx) g_mutex_lock (mtx) +#define tumbler_mutex_unlock(mtx) g_mutex_unlock (mtx) +#define tumbler_mutex_create(mtx) (mtx) = g_mutex_new () +#endif + G_END_DECLS #endif /* !__TUMBLER_UTILS_H__ */ _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits