[prev in list] [next in list] [prev in thread] [next in thread] 

List:       prelude-cvslog
Subject:    [prelude-cvslog] r4557 - trunk/libprelude/src
From:       noreply () prelude-ids ! org
Date:       2004-12-11 3:32:19
Message-ID: 20041211033219.E38493BC80E () mail ! prelude-ids ! org
[Download RAW message or body]

Author: yoann
Date: 2004-12-11 04:32:19 +0100 (Sat, 11 Dec 2004)
New Revision: 4557

Modified:
   trunk/libprelude/src/idmef-object.c
Log:
Only flush the cached element if flush_cache is positionned to TRUE.
Otherwise, we should not flush since the object might still be in use.



Modified: trunk/libprelude/src/idmef-object.c
===================================================================
--- trunk/libprelude/src/idmef-object.c	2004-12-11 02:57:02 UTC (rev 4556)
+++ trunk/libprelude/src/idmef-object.c	2004-12-11 03:32:19 UTC (rev 4557)
@@ -87,10 +87,19 @@
 
 
 
+static prelude_bool_t flush_cache = FALSE;
 static prelude_hash_t *cached_objects = NULL;
 static pthread_mutex_t cached_object_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 
+static void flush_cache_if_wanted(void *ptr)
+{
+        if ( flush_cache )
+                idmef_object_destroy(ptr);
+}
+
+
+
 /*
  * call with mutex held.
  */
@@ -99,7 +108,7 @@
         if ( cached_objects )
                 return 0;
                         
-        cached_objects = prelude_hash_new(NULL, NULL, NULL, (void *) idmef_object_destroy);
+        cached_objects = prelude_hash_new(NULL, NULL, NULL, flush_cache_if_wanted);
         if ( ! cached_objects ) 
                 return -1;
 
@@ -662,7 +671,7 @@
 
 
 void idmef_object_destroy(idmef_object_t *object)
-{
+{        
 	pthread_mutex_lock(&object->mutex);
 
 	if ( --object->refcount ) {
@@ -864,5 +873,7 @@
         if ( ! cached_objects )
                 return;
 
+        flush_cache = TRUE;
         prelude_hash_destroy(cached_objects);
+        flush_cache = FALSE;
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic