mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-22 18:22:11 +01:00
Merge branch 'wip/3v1n0/gfilemonitor-atomic-cancelled' into 'main'
gio/gfilemonitor: Use atomic API to get / store cancelled state See merge request GNOME/glib!4487
This commit is contained in:
commit
40fd0e4759
@ -23,12 +23,13 @@
|
||||
#include "config.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "gfile.h"
|
||||
#include "gfilemonitor.h"
|
||||
#include "gioenumtypes.h"
|
||||
#include "gmarshal-internal.h"
|
||||
#include "gfile.h"
|
||||
#include "gvfs.h"
|
||||
#include "glib.h"
|
||||
#include "glibintl.h"
|
||||
#include "gmarshal-internal.h"
|
||||
#include "gvfs.h"
|
||||
|
||||
/**
|
||||
* GFileMonitor:
|
||||
@ -50,9 +51,15 @@
|
||||
|
||||
#define DEFAULT_RATE_LIMIT_MSECS 800
|
||||
|
||||
typedef enum {
|
||||
CANCEL_STATE_NONE,
|
||||
CANCEL_STATE_CANCELLING,
|
||||
CANCEL_STATE_CANCELLED,
|
||||
} GFileMonitorCancelState;
|
||||
|
||||
struct _GFileMonitorPrivate
|
||||
{
|
||||
gboolean cancelled;
|
||||
int cancelled; /* atomic */
|
||||
};
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GFileMonitor, g_file_monitor, G_TYPE_OBJECT)
|
||||
@ -219,13 +226,9 @@ g_file_monitor_class_init (GFileMonitorClass *klass)
|
||||
gboolean
|
||||
g_file_monitor_is_cancelled (GFileMonitor *monitor)
|
||||
{
|
||||
gboolean res;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
|
||||
|
||||
res = monitor->priv->cancelled;
|
||||
|
||||
return res;
|
||||
return g_atomic_int_get (&monitor->priv->cancelled) == CANCEL_STATE_CANCELLED;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,11 +244,13 @@ g_file_monitor_cancel (GFileMonitor *monitor)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
|
||||
|
||||
if (!monitor->priv->cancelled)
|
||||
if (g_atomic_int_compare_and_exchange (&monitor->priv->cancelled,
|
||||
CANCEL_STATE_NONE,
|
||||
CANCEL_STATE_CANCELLING))
|
||||
{
|
||||
G_FILE_MONITOR_GET_CLASS (monitor)->cancel (monitor);
|
||||
|
||||
monitor->priv->cancelled = TRUE;
|
||||
g_atomic_int_set (&monitor->priv->cancelled, CANCEL_STATE_CANCELLED);
|
||||
g_object_notify (G_OBJECT (monitor), "cancelled");
|
||||
}
|
||||
|
||||
@ -293,7 +298,7 @@ g_file_monitor_emit_event (GFileMonitor *monitor,
|
||||
g_return_if_fail (G_IS_FILE (child));
|
||||
g_return_if_fail (!other_file || G_IS_FILE (other_file));
|
||||
|
||||
if (monitor->priv->cancelled)
|
||||
if (g_atomic_int_get (&monitor->priv->cancelled) != CANCEL_STATE_NONE)
|
||||
return;
|
||||
|
||||
g_signal_emit (monitor, g_file_monitor_changed_signal, 0, child, other_file, event_type);
|
||||
|
@ -134,7 +134,11 @@ gio_tests = {
|
||||
'vfs' : {},
|
||||
'volumemonitor' : {},
|
||||
'glistmodel' : {},
|
||||
'testfilemonitor' : {'suite' : ['slow', 'flaky']},
|
||||
'testfilemonitor' : {
|
||||
'suite' : ['slow'],
|
||||
# FIXME: https://gitlab.gnome.org/GNOME/glib/-/issues/1392
|
||||
'can_fail' : host_system in ['darwin'],
|
||||
},
|
||||
'thumbnail-verification' : {},
|
||||
'tls-certificate' : {'extra_sources' : ['gtesttlsbackend.c']},
|
||||
'tls-interaction' : {'extra_sources' : ['gtesttlsbackend.c']},
|
||||
|
Loading…
x
Reference in New Issue
Block a user