Commit 0594aa16 authored by Cosimo Cecchi's avatar Cosimo Cecchi

all: don't use deprecated GMutex/GThread API

Also, threads area always enabled, so we can remove the
G_THREADS_ENABLED conditionals.
Require GLib 2.31 for this.
parent 04975e6c
......@@ -25,14 +25,6 @@
#include "nautilus-directory-notify.h"
#ifdef G_THREADS_ENABLED
#define MUTEX_LOCK(a) if ((a) != NULL) g_mutex_lock (a)
#define MUTEX_UNLOCK(a) if ((a) != NULL) g_mutex_unlock (a)
#else
#define MUTEX_LOCK(a)
#define MUTEX_UNLOCK(a)
#endif
typedef enum {
CHANGE_FILE_INITIAL,
CHANGE_FILE_ADDED,
......@@ -54,9 +46,7 @@ typedef struct {
typedef struct {
GList *head;
GList *tail;
#ifdef G_THREADS_ENABLED
GMutex *mutex;
#endif
GMutex mutex;
} NautilusFileChangesQueue;
static NautilusFileChangesQueue *
......@@ -65,10 +55,8 @@ nautilus_file_changes_queue_new (void)
NautilusFileChangesQueue *result;
result = g_new0 (NautilusFileChangesQueue, 1);
#ifdef G_THREADS_ENABLED
result->mutex = g_mutex_new ();
#endif
g_mutex_init (&result->mutex);
return result;
}
......@@ -84,58 +72,18 @@ nautilus_file_changes_queue_get (void)
return file_changes_queue;
}
#if 0 /* no public free call yet */
static void
nautilus_file_change_free (NautilusFileChange *change)
{
if (change->from) {
g_object_unref (change->from);
}
if (change->to) {
g_object_unref (change->to);
}
}
void
nautilus_file_changes_queue_free (NautilusFileChangesQueue *queue)
{
GList *p;
if (queue == NULL) {
return;
}
#ifdef G_THREADS_ENABLED
/* if lock on a defunct mutex were defined (returning a failure)
* we would lock here
*/
#endif
for (p = queue->head; p != NULL; p = p->next) {
nautilus_file_change_free (p->data);
}
g_list_free (queue->head);
#ifdef G_THREADS_ENABLED
g_mutex_free (queue->mutex);
#endif
g_free (queue);
}
#endif /* no public free call yet */
static void
nautilus_file_changes_queue_add_common (NautilusFileChangesQueue *queue,
NautilusFileChange *new_item)
{
/* enqueue the new queue item while locking down the list */
MUTEX_LOCK (queue->mutex);
g_mutex_lock (&queue->mutex);
queue->head = g_list_prepend (queue->head, new_item);
if (queue->tail == NULL)
queue->tail = queue->head;
MUTEX_UNLOCK (queue->mutex);
g_mutex_unlock (&queue->mutex);
}
void
......@@ -237,7 +185,7 @@ nautilus_file_changes_queue_get_change (NautilusFileChangesQueue *queue)
g_assert (queue != NULL);
/* dequeue the tail item while locking down the list */
MUTEX_LOCK (queue->mutex);
g_mutex_lock (&queue->mutex);
if (queue->tail == NULL) {
result = NULL;
......@@ -250,7 +198,7 @@ nautilus_file_changes_queue_get_change (NautilusFileChangesQueue *queue)
queue->tail = new_tail;
}
MUTEX_UNLOCK (queue->mutex);
g_mutex_unlock (&queue->mutex);
return result;
}
......
......@@ -173,8 +173,7 @@ typedef struct {
} TransferInfo;
#define SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE 15
#define NSEC_PER_SEC 1000000000
#define NSEC_PER_MSEC 1000000
#define NSEC_PER_MICROSEC 1000
#define MAXIMUM_DISPLAYED_FILE_NAME_LENGTH 50
......@@ -1393,12 +1392,12 @@ report_delete_progress (CommonJob *job,
int files_left;
double elapsed, transfer_rate;
int remaining_time;
guint64 now;
gint64 now;
char *files_left_s;
now = g_thread_gettime ();
now = g_get_monotonic_time ();
if (transfer_info->last_report_time != 0 &&
ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MSEC) {
ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC) {
return;
}
transfer_info->last_report_time = now;
......@@ -2844,10 +2843,10 @@ report_copy_progress (CopyMoveJob *copy_job,
is_move = copy_job->is_move;
now = g_thread_gettime ();
now = g_get_monotonic_time ();
if (transfer_info->last_report_time != 0 &&
ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MSEC) {
ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC) {
return;
}
transfer_info->last_report_time = now;
......
......@@ -31,7 +31,7 @@ struct _NautilusIconInfo
GObject parent;
gboolean sole_owner;
guint64 last_use_time;
gint64 last_use_time;
GdkPixbuf *pixbuf;
gboolean got_embedded_rect;
......@@ -56,7 +56,7 @@ G_DEFINE_TYPE (NautilusIconInfo,
static void
nautilus_icon_info_init (NautilusIconInfo *icon)
{
icon->last_use_time = g_thread_gettime ();
icon->last_use_time = g_get_monotonic_time ();
icon->sole_owner = TRUE;
}
......@@ -78,7 +78,7 @@ pixbuf_toggle_notify (gpointer info,
g_object_remove_toggle_ref (object,
pixbuf_toggle_notify,
info);
icon->last_use_time = g_thread_gettime ();
icon->last_use_time = g_get_monotonic_time ();
schedule_reap_cache ();
}
}
......@@ -182,7 +182,7 @@ static GHashTable *loadable_icon_cache = NULL;
static GHashTable *themed_icon_cache = NULL;
static guint reap_cache_timeout = 0;
#define NSEC_PER_SEC ((guint64)1000000000L)
#define MICROSEC_PER_SEC ((guint64)1000000L)
static guint time_now;
......@@ -195,7 +195,7 @@ reap_old_icon (gpointer key,
gboolean *reapable_icons_left = user_info;
if (icon->sole_owner) {
if (time_now - icon->last_use_time > 30 * NSEC_PER_SEC) {
if (time_now - icon->last_use_time > 30 * MICROSEC_PER_SEC) {
/* This went unused 30 secs ago. reap */
return TRUE;
} else {
......@@ -214,7 +214,7 @@ reap_cache (gpointer data)
reapable_icons_left = TRUE;
time_now = g_thread_gettime ();
time_now = g_get_monotonic_time ();
if (loadable_icon_cache) {
g_hash_table_foreach_remove (loadable_icon_cache,
......
......@@ -327,6 +327,7 @@ nautilus_search_engine_simple_start (NautilusSearchEngine *engine)
{
NautilusSearchEngineSimple *simple;
SearchThreadData *data;
GThread *thread;
simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (engine);
......@@ -340,9 +341,10 @@ nautilus_search_engine_simple_start (NautilusSearchEngine *engine)
data = search_thread_data_new (simple, simple->details->query);
g_thread_create (search_thread_func, data, FALSE, NULL);
thread = g_thread_new ("nautilus-search-simple", search_thread_func, data);
simple->details->active_search = data;
g_thread_unref (thread);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment