changeset 2562:07b990906823 trunk

[svn] - add reference-counting to VFS and add new function, vfs_dup() to mark a VFS handle as duplicated.
author nenolod
date Sat, 24 Feb 2007 06:01:39 -0800
parents 5b761b745289
children bdd0ee5888e0
files ChangeLog src/audacious/build_stamp.c src/audacious/vfs.c src/audacious/vfs.h src/audacious/vfs_buffer.c src/audacious/vfs_buffered_file.c
diffstat 6 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Feb 23 20:10:54 2007 -0800
+++ b/ChangeLog	Sat Feb 24 06:01:39 2007 -0800
@@ -1,3 +1,11 @@
+2007-02-24 04:10:54 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [4132]
+  - provide fd->uri for buffered files
+  
+  trunk/src/audacious/vfs_buffered_file.c |    1 +
+  1 file changed, 1 insertion(+)
+
+
 2007-02-21 23:02:54 +0000  Giacomo Lozito <james@develia.org>
   revision [4130]
   - added custom field in tuple, for internal use by plugins or by whatever wanting to use it
--- a/src/audacious/build_stamp.c	Fri Feb 23 20:10:54 2007 -0800
+++ b/src/audacious/build_stamp.c	Sat Feb 24 06:01:39 2007 -0800
@@ -1,2 +1,2 @@
 #include <glib.h>
-const gchar *svn_stamp = "20070221-4130";
+const gchar *svn_stamp = "20070224-4132";
--- a/src/audacious/vfs.c	Fri Feb 23 20:10:54 2007 -0800
+++ b/src/audacious/vfs.c	Sat Feb 24 06:01:39 2007 -0800
@@ -95,6 +95,7 @@
 
     file->uri = g_strdup(path);
     file->base = vtable;
+    file->ref = 1;
 
     g_free(decpath);
 
@@ -117,6 +118,9 @@
     if (file == NULL)
         return -1;
 
+    if (--file->ref > 0)
+        return -1;
+
     if (file->base->vfs_fclose_impl(file) != 0)
         ret = -1;
 
@@ -351,3 +355,23 @@
 
     return (info.st_mode & S_IWUSR);
 }
+
+/**
+ * vfs_dup:
+ * @in: The VFSFile handle to mark as duplicated.
+ *
+ * Increments the amount of references that are using this FD.
+ * References are removed by calling vfs_fclose on the handle returned
+ * from this function.
+ * If the amount of references reaches zero, then the file will be
+ * closed.
+ **/
+VFSFile *
+vfs_dup(VFSFile *in)
+{
+    g_return_val_if_fail(in != NULL, NULL);
+
+    in->ref++;
+
+    return in;
+}
--- a/src/audacious/vfs.h	Fri Feb 23 20:10:54 2007 -0800
+++ b/src/audacious/vfs.h	Sat Feb 24 06:01:39 2007 -0800
@@ -30,6 +30,7 @@
  * @uri: The URI of the stream.
  * @handle: Opaque data used by the transport plugins.
  * @base: The base vtable used for VFS functions.
+ * @ref: The amount of references that the VFSFile object has.
  *
  * #VFSFile objects describe a VFS stream.
  **/
@@ -37,6 +38,7 @@
 	gchar *uri;
 	gpointer handle;
 	VFSConstructor *base;
+	gint ref;
 };
 
 /**
@@ -83,6 +85,8 @@
                     const gchar * mode);
 extern gint vfs_fclose(VFSFile * file);
 
+extern VFSFile * vfs_dup(VFSFile *in);
+
 extern size_t vfs_fread(gpointer ptr,
                  size_t size,
                  size_t nmemb,
--- a/src/audacious/vfs_buffer.c	Fri Feb 23 20:10:54 2007 -0800
+++ b/src/audacious/vfs_buffer.c	Sat Feb 24 06:01:39 2007 -0800
@@ -220,6 +220,7 @@
 
     handle->handle = buffer;
     handle->base = &buffer_const;
+    handle->ref = 1;
 
     return handle;
 }
--- a/src/audacious/vfs_buffered_file.c	Fri Feb 23 20:10:54 2007 -0800
+++ b/src/audacious/vfs_buffered_file.c	Sat Feb 24 06:01:39 2007 -0800
@@ -208,6 +208,7 @@
     handle->handle = fd;
     handle->base = &buffered_file_const;
     handle->uri = g_strdup(uri);
+    handle->ref = 1;
 
     return handle;
 }