mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 07:56:17 +01:00
[gio] minor improvements to g_cancellable_cancel()
- make this function not crash when cancellable is NULL - avoid locking when the cancellable has already been cancelled
This commit is contained in:
parent
8a2e617e41
commit
c85ff0c750
@ -514,27 +514,27 @@ g_cancellable_make_pollfd (GCancellable *cancellable, GPollFD *pollfd)
|
|||||||
void
|
void
|
||||||
g_cancellable_cancel (GCancellable *cancellable)
|
g_cancellable_cancel (GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
|
static const char ch = 'x';
|
||||||
gboolean cancel;
|
gboolean cancel;
|
||||||
GCancellablePrivate *priv;
|
GCancellablePrivate *priv;
|
||||||
|
|
||||||
|
if (cancellable == NULL ||
|
||||||
|
priv->cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
priv = cancellable->priv;
|
priv = cancellable->priv;
|
||||||
cancel = FALSE;
|
cancel = FALSE;
|
||||||
|
|
||||||
G_LOCK(cancellable);
|
G_LOCK(cancellable);
|
||||||
if (cancellable != NULL &&
|
cancel = TRUE;
|
||||||
!priv->cancelled)
|
priv->cancelled = TRUE;
|
||||||
{
|
priv->cancelled_running = TRUE;
|
||||||
char ch = 'x';
|
|
||||||
cancel = TRUE;
|
|
||||||
priv->cancelled = TRUE;
|
|
||||||
priv->cancelled_running = TRUE;
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
if (priv->event)
|
if (priv->event)
|
||||||
SetEvent(priv->event);
|
SetEvent(priv->event);
|
||||||
#endif
|
#endif
|
||||||
if (priv->cancel_pipe[1] != -1)
|
if (priv->cancel_pipe[1] != -1)
|
||||||
write (priv->cancel_pipe[1], &ch, 1);
|
write (priv->cancel_pipe[1], &ch, 1);
|
||||||
}
|
|
||||||
G_UNLOCK(cancellable);
|
G_UNLOCK(cancellable);
|
||||||
|
|
||||||
if (cancel)
|
if (cancel)
|
||||||
|
Loading…
Reference in New Issue
Block a user