summaryrefslogtreecommitdiff
path: root/gvfs
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@src.gnome.org>2007-09-13 10:11:55 +0000
committerAlexander Larsson <alexl@src.gnome.org>2007-09-13 10:11:55 +0000
commit490e56516909c83140cfdb79d499e49e82eb5ef6 (patch)
treef7230282b86bd7f8a6f23912fe578939e23990b4 /gvfs
parent1df175beb5a3beb5bb42db97d2962186c90ad497 (diff)
downloadgvfs-490e56516909c83140cfdb79d499e49e82eb5ef6.tar.gz
Allocate pipe() as needed
Original git commit by Alexander Larsson <alex@greebo.(none)> at 1164375247 +0100 svn path=/trunk/; revision=185
Diffstat (limited to 'gvfs')
-rw-r--r--gvfs/gcancellable.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/gvfs/gcancellable.c b/gvfs/gcancellable.c
index 81b49365..04412e27 100644
--- a/gvfs/gcancellable.c
+++ b/gvfs/gcancellable.c
@@ -9,7 +9,8 @@ struct _GCancellable
{
GObject parent_instance;
- gboolean cancelled;
+ guint cancelled : 1;
+ guint allocated_pipe : 1;
int cancel_pipe[2];
};
@@ -58,7 +59,7 @@ set_fd_nonblocking (int fd)
}
static void
-g_cancellable_init (GCancellable *cancellable)
+g_cancellable_open_pipe (GCancellable *cancellable)
{
if (pipe (cancellable->cancel_pipe) == 0)
{
@@ -68,11 +69,13 @@ g_cancellable_init (GCancellable *cancellable)
set_fd_nonblocking (cancellable->cancel_pipe[0]);
set_fd_nonblocking (cancellable->cancel_pipe[1]);
}
- else
- {
- cancellable->cancel_pipe[0] = -1;
- cancellable->cancel_pipe[1] = -1;
- }
+}
+
+static void
+g_cancellable_init (GCancellable *cancellable)
+{
+ cancellable->cancel_pipe[0] = -1;
+ cancellable->cancel_pipe[1] = -1;
}
GCancellable *
@@ -144,9 +147,21 @@ g_cancellable_is_cancelled (GCancellable *cancellable)
int
g_cancellable_get_fd (GCancellable *cancellable)
{
+ int fd;
if (cancellable == NULL)
return -1;
- return cancellable->cancel_pipe[0];
+
+ G_LOCK(cancellable);
+ if (!cancellable->allocated_pipe)
+ {
+ cancellable->allocated_pipe = TRUE;
+ g_cancellable_open_pipe (cancellable);
+ }
+
+ fd = cancellable->cancel_pipe[0];
+ G_UNLOCK(cancellable);
+
+ return fd;
}
/* This is safe to call from another thread */