Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/lib/file


Modified Files:
        evas_module.c 


Log Message:


and i implemented module UNLOADING. given enough cycles of non-use of a
module and no references, it will get.... UNLOADED :)

===================================================================
RCS file: /cvs/e/e17/libs/evas/src/lib/file/evas_module.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- evas_module.c       6 Sep 2006 07:33:40 -0000       1.18
+++ evas_module.c       18 Sep 2006 09:40:29 -0000      1.19
@@ -158,7 +158,7 @@
               {
                  Evas_Module *em;
                  
-                 em = malloc(sizeof(Evas_Module));
+                 em = calloc(1, sizeof(Evas_Module));
                  if (!em) continue;
                  em->name = strdup(de->d_name);
                  em->path = strdup(mp->path);
@@ -223,6 +223,7 @@
    
    if (em->loaded) return 1;
 
+//   printf("LOAD %s\n", em->name);
    snprintf(buf, sizeof(buf), "%s/%s/%s/module.so", em->path, em->name, 
MODULE_ARCH);
    if (!evas_file_path_exists(buf))
      {
@@ -282,6 +283,76 @@
    em->loaded = 0;
 }
 
+void
+evas_module_ref(Evas_Module *em)
+{
+   em->ref++;
+//   printf("M: %s ref++ = %i\n", em->name, em->ref);
+}
+
+void
+evas_module_unref(Evas_Module *em)
+{
+   em->ref--;
+//   printf("M: %s ref-- = %i\n", em->name, em->ref);
+}
+
+static int use_count = 0;
+
+void
+evas_module_use(Evas_Module *em)
+{
+   em->last_used = use_count;
+}
+
+void
+evas_module_clean(void)
+{
+   static int call_count = 0;
+   int ago;
+   int noclean = -1;
+   Evas_List *l;
+   Evas_Module *em;
+
+   /* only clean modules every 32 calls */
+   call_count++;
+   if (call_count <= 32) return;
+   call_count = 0;
+
+   if (noclean == -1)
+     {
+       if (getenv("EVAS_NOCLEAN"))
+         {
+            noclean = 1;
+         }
+       noclean = 0;
+     }
+   if (noclean == 1) return;
+   
+   /* incriment use counter = 28bits */
+   use_count++;
+   if (use_count > 0x0fffffff) use_count = 0;
+   
+//   printf("CLEAN!\n");
+   /* go through all modules */
+   for (l = evas_modules; l; l = l->next)
+     {
+       em = l->data;
+//     printf("M %s %i %i\n", em->name, em->ref, em->loaded);
+       /* if the module is refernced - skip */
+       if ((em->ref > 0) || (!em->loaded)) continue;
+       /* how many clean cycles ago was this module last used */
+       ago = use_count - em->last_used;
+       if (em->last_used > use_count) ago += 0x10000000;
+       /* if it was used last more than N clean cycles ago - unload */
+       if (ago > 3)
+         {
+//          printf("  UNLOAD %s\n", em->name);
+            evas_module_unload(em);
+         }
+     }
+}
+
 /* will dlclose all the modules loaded and free all the structs */
 void
 evas_module_shutdown(void)
@@ -329,6 +400,9 @@
      {
        if (evas_module_load(em))
          {
+            /* FIXME: no way to unref */
+            evas_module_ref(em);
+            evas_module_use(em);
             *funcs = *((Evas_Func *)(em->functions));
             return 1;
          }



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to