gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22979 - Extractor/src/main


From: gnunet
Subject: [GNUnet-SVN] r22979 - Extractor/src/main
Date: Mon, 30 Jul 2012 15:05:17 +0200

Author: grothoff
Date: 2012-07-30 15:05:17 +0200 (Mon, 30 Jul 2012)
New Revision: 22979

Modified:
   Extractor/src/main/extractor.c
   Extractor/src/main/extractor_ipc.h
   Extractor/src/main/extractor_ipc_gnu.c
   Extractor/src/main/extractor_plugins.c
Log:
add reference counting for shm and destroy them when they are finished

Modified: Extractor/src/main/extractor.c
===================================================================
--- Extractor/src/main/extractor.c      2012-07-30 13:04:23 UTC (rev 22978)
+++ Extractor/src/main/extractor.c      2012-07-30 13:05:17 UTC (rev 22979)
@@ -387,6 +387,7 @@
         (EXTRACTOR_OPTION_IN_PROCESS == pos->flags) )
       {
        pos->shm = shm;
+       (void) EXTRACTOR_IPC_shared_memory_change_rc_ (shm, 1);
        pos->channel = EXTRACTOR_IPC_channel_create_ (pos,
                                                      shm);
       }

Modified: Extractor/src/main/extractor_ipc.h
===================================================================
--- Extractor/src/main/extractor_ipc.h  2012-07-30 13:04:23 UTC (rev 22978)
+++ Extractor/src/main/extractor_ipc.h  2012-07-30 13:05:17 UTC (rev 22979)
@@ -337,6 +337,18 @@
 
 
 /**
+ * Change the reference counter for this shm instance.
+ *
+ * @param shm instance to update
+ * @param delta value to change RC by
+ * @return new RC
+ */
+unsigned int
+EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
+                                       int delta);
+
+
+/**
  * Initialize shared memory area from data source.
  *
  * @param shm memory area to initialize

Modified: Extractor/src/main/extractor_ipc_gnu.c
===================================================================
--- Extractor/src/main/extractor_ipc_gnu.c      2012-07-30 13:04:23 UTC (rev 
22978)
+++ Extractor/src/main/extractor_ipc_gnu.c      2012-07-30 13:05:17 UTC (rev 
22979)
@@ -66,6 +66,11 @@
    */ 
   char shm_name[MAX_SHM_NAME + 1];
 
+  /**
+   * Reference counter describing how many references share this SHM.
+   */
+  unsigned int rc;
+
 };
 
 
@@ -163,11 +168,28 @@
     return NULL;
   }
   shm->shm_size = size;
+  shm->rc = 0;
   return shm; 
 }
 
 
 /**
+ * Change the reference counter for this shm instance.
+ *
+ * @param shm instance to update
+ * @param delta value to change RC by
+ * @return new RC
+ */
+unsigned int
+EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
+                                       int delta)
+{
+  shm->rc += delta;
+  return shm->rc;
+}
+
+
+/**
  * Destroy shared memory area.
  *
  * @param shm memory area to destroy
@@ -175,7 +197,7 @@
  */
 void
 EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
-{
+{  
   munmap (shm->shm_ptr, shm->shm_size);
   (void) close (shm->shm_id);
   (void) shm_unlink (shm->shm_name);

Modified: Extractor/src/main/extractor_plugins.c
===================================================================
--- Extractor/src/main/extractor_plugins.c      2012-07-30 13:04:23 UTC (rev 
22978)
+++ Extractor/src/main/extractor_plugins.c      2012-07-30 13:05:17 UTC (rev 
22979)
@@ -351,8 +351,8 @@
  * @return the reduced list, unchanged if the plugin was not loaded
  */
 struct EXTRACTOR_PluginList *
-EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList * prev,
-                        const char * library)
+EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
+                        const char *library)
 {
   struct EXTRACTOR_PluginList *pos;
   struct EXTRACTOR_PluginList *first;
@@ -381,8 +381,8 @@
     prev->next = pos->next;
   if (NULL != pos->channel)
     EXTRACTOR_IPC_channel_destroy_ (pos->channel);
-  // FIXME: need to also destroy pos->shm if this is
-  // the last user; need to add some RC to the SHM!
+  if (0 == EXTRACTOR_IPC_shared_memory_change_rc_ (pos->shm, -1))
+    EXTRACTOR_IPC_shared_memory_destroy_ (pos->shm);
   free (pos->short_libname);
   free (pos->libname);
   free (pos->plugin_options);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]