Revision: 7259
          http://svn.sourceforge.net/mahogany/?rev=7259&view=rev
Author:   vadz
Date:     2007-04-30 07:48:48 -0700 (Mon, 30 Apr 2007)

Log Message:
-----------
reuse the same memory map of hash database files for all contexts instead of 
un/remapping the file all the time (restores the logic of code prior to rev 
7143 but now it works with hash driver and not sqlite one)

Revision Links:
--------------
    http://svn.sourceforge.net/mahogany/?rev=7143&view=rev

Modified Paths:
--------------
    trunk/M/src/modules/spam/DspamFilter.cpp

Modified: trunk/M/src/modules/spam/DspamFilter.cpp
===================================================================
--- trunk/M/src/modules/spam/DspamFilter.cpp    2007-04-30 14:46:27 UTC (rev 
7258)
+++ trunk/M/src/modules/spam/DspamFilter.cpp    2007-04-30 14:48:48 UTC (rev 
7259)
@@ -48,6 +48,8 @@
 // wrappers around DSPAM_CTX
 // ----------------------------------------------------------------------------
 
+static const char *DSPAM_USER_NAME = "mahogany";
+
 // base class used by DspamProcess/ClassifyCtx
 class DspamCtx
 {
@@ -57,8 +59,8 @@
    {
       m_ctx = dspam_create
               (
-                  "mahogany", // user
-                  NULL,       // no group
+                  DSPAM_USER_NAME,  // user name used as base file name
+                  NULL,             // no group
                   mApplication->GetLocalDir().fn_str(),
                   mode,
                   flags
@@ -75,11 +77,22 @@
 
       // and now that the attributes are set we can attach the context to the
       // storage
-      if ( dspam_attach(m_ctx, NULL) != 0 )
+      if ( dspam_attach(m_ctx, ms_hashMap) != 0 )
       {
          dspam_destroy(m_ctx);
          m_ctx = NULL;
       }
+      else if ( !ms_hashMap )
+      {
+         // this is the first context we create so it has just mapped the hash
+         // database into memory: tell it to not unmap it when we're done with
+         // it and keep the pointer to reuse for the subsequent contexts
+         _hash_drv_storage *storage = (_hash_drv_storage *)m_ctx->storage;
+         storage->dbh_attached = 1;
+
+         ms_hashMap = storage->map;
+         ms_hashLock = storage->lock;
+      }
    }
 
    // destroy the context
@@ -92,12 +105,34 @@
    operator DSPAM_CTX *() const { return m_ctx; }
    DSPAM_CTX *operator->() const { return m_ctx; }
 
+   // close the database connection     
+   static void CloseHashStorage()       
+   {    
+      if ( ms_hashMap )         
+      {         
+         _hash_drv_close(ms_hashMap);   
+         free(ms_hashMap);
+         ms_hashMap = NULL;     
+
+         _hash_drv_lock_free(&ms_hashLock, DSPAM_USER_NAME);
+      }         
+   }
+
 private:
+   // the hash driver data reused by all contexts
+   static hash_drv_map_t ms_hashMap;
+   static _ds_lock_t ms_hashLock;
+
    DSPAM_CTX *m_ctx;
 
    DECLARE_NO_COPY_CLASS(DspamCtx);
 };
 
+hash_drv_map_t DspamCtx::ms_hashMap = NULL;
+_ds_lock_t DspamCtx::ms_hashLock = NULL;
+
+MMODULE_CLEANUP(DspamCtx::CloseHashStorage)
+
 // normal DSPAM context
 class DspamProcessCtx : public DspamCtx
 {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to