Reuse existing CaptiveVfsObject to support multiple LUFS threads (=channels).
authorshort <>
Fri, 22 Aug 2003 11:51:16 +0000 (11:51 +0000)
committershort <>
Fri, 22 Aug 2003 11:51:16 +0000 (11:51 +0000)
src/client/lufs/captivefs-vfs.c
src/client/lufs/captivefs-vfs.h

index 3943766..5d38bae 100644 (file)
@@ -36,6 +36,9 @@ gboolean captivefs_vfs_validate(struct captivefs_vfs *captivefs_vfs)
        g_return_val_if_fail(captivefs_vfs!=NULL,FALSE);
 
        G_LOCK(libcaptive);
+       g_assert(captivefs_vfs->inits>0);
+       g_assert(captivefs_vfs->mounts>=0);
+       g_assert(captivefs_vfs->mounts<=captivefs_vfs->inits);
        if (!captivefs_vfs->captive_vfs_object) {
 GnomeVFSResult errvfsresult;
 
@@ -74,7 +77,7 @@ GnomeVFSResult errvfsresult;
  *   global_ctx parameter.  
  */
 struct captivefs_vfs *captivefs_init
-               (struct list_head *cfg,struct dir_cache *cache,const struct credentials *cred,void **global_ctx)
+               (struct list_head *cfg,struct dir_cache *cache,const struct credentials *cred,struct captivefs_vfs **global_ctx)
 {
 struct captivefs_vfs *captivefs_vfs;
 const struct poptOption *cpopt;
@@ -83,12 +86,28 @@ const gchar *cgs;
 poptContext context;
 int errint;
 
+       g_return_val_if_fail(global_ctx!=NULL,NULL);
+
        /* Do not: g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_init");
         * as we do not yet have 'VFS_DEBUG_MESSAGES(captive_vfs_object)' set.
         * Generally we make all g_log() conditional here as we do not want to mess
         * with overriden GLog handlers of libcaptive itself.
         */
 
+       G_LOCK(libcaptive);
+       if ((captivefs_vfs=*global_ctx)) {
+               g_assert(captivefs_vfs->inits>0);
+               /* We do not support multiple LUFS threads if they could not be cross-locked. */
+               g_return_val_if_fail(g_thread_supported(),NULL);
+               captivefs_vfs->inits++;
+               G_UNLOCK(libcaptive);
+               return captivefs_vfs;
+               }
+       G_UNLOCK(libcaptive);
+
+       if (!g_thread_supported())
+               g_thread_init(NULL);    /* g_thread_init() fails on second initialization */
+
        arg_array=g_ptr_array_new();
        if (!(cgs=lu_opt_getchar(cfg,"MOUNT","fs")))
                cgs="captivefs";
@@ -116,6 +135,10 @@ const gchar *dashdashname,*value;
        captive_new(captivefs_vfs);
        captivefs_vfs->captive_vfs_object=NULL;
        captivefs_vfs->parent_pid=getpid();
+       captivefs_vfs->global_ctx=global_ctx;
+       *global_ctx=captivefs_vfs;
+       captivefs_vfs->inits=1;
+       captivefs_vfs->mounts=0;
 
        captive_options_init(&captivefs_vfs->options);
        captive_options=&captivefs_vfs->options;        /* for parsing by 'CAPTIVE_POPT_INCLUDE' */
@@ -182,9 +205,19 @@ fail_free_options:
 void captivefs_free(struct captivefs_vfs *captivefs_vfs)
 {
        g_return_if_fail(captivefs_vfs_validate(captivefs_vfs));
+       g_return_if_fail(captivefs_vfs->inits>0);
 
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_free");
+       
+       if (--captivefs_vfs->inits>0) {
+               g_assert(captivefs_vfs_validate(captivefs_vfs));
+               return;
+               }
+       g_assert(captivefs_vfs->mounts==0);
+       G_LOCK(libcaptive);
+       *captivefs_vfs->global_ctx=NULL;
+       G_UNLOCK(libcaptive);
 
        g_assert(G_OBJECT(captivefs_vfs->captive_vfs_object)->ref_count==1);
 
@@ -219,6 +252,10 @@ int captivefs_mount(struct captivefs_vfs *captivefs_vfs)
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_mount");
 
+       captivefs_vfs->mounts++;
+
+       captivefs_vfs_validate(captivefs_vfs);  /* It may return FALSE. */
+
        return 1;       /* NEVER return 0 */
 }
 
@@ -229,7 +266,12 @@ int captivefs_mount(struct captivefs_vfs *captivefs_vfs)
 void captivefs_umount(struct captivefs_vfs *captivefs_vfs)
 {
        g_return_if_fail(captivefs_vfs_validate(captivefs_vfs));
+       g_return_if_fail(captivefs_vfs->mounts>0);
 
        if (captivefs_vfs->options.debug_messages)
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_umount");
+
+       captivefs_vfs->mounts--;
+
+       g_assert(captivefs_vfs_validate(captivefs_vfs));
 }
index c763d9e..e5c9378 100644 (file)
@@ -33,6 +33,8 @@ struct captivefs_vfs {
        CaptiveVfsObject *captive_vfs_object;
        struct captive_options options;
        pid_t parent_pid;
+       struct captivefs_vfs **global_ctx;
+       gint inits,mounts;
        };
 
 gboolean captivefs_vfs_validate(struct captivefs_vfs *captivefs_vfs);