Removed redundant 'length' and 'buffer' object fields.
authorshort <>
Wed, 13 Aug 2003 09:12:28 +0000 (09:12 +0000)
committershort <>
Wed, 13 Aug 2003 09:12:28 +0000 (09:12 +0000)
Fixed captive_private_bcb_pin_object_hash_new_key_compare_func().
Used PAGE_SIZE-aligned 'FileSize' instead of non-aligned 'ValidDataLength'.
+captive_private_bcb_pin_object_get() to just query existing objects hash.

src/libcaptive/cc/privatebcbpin.c

index 5b08c0a..e9d21d2 100644 (file)
@@ -24,6 +24,7 @@
 #include "privatebcb-priv.h"
 #include "sharedcachemap-priv.h"
 #include <glib-object.h>
+#include "captive/macros.h"
 
 
 struct _CaptivePrivateBcbPinObject {
@@ -33,8 +34,6 @@ struct _CaptivePrivateBcbPinObject {
        gulong FileSizes_changed_after_handler_id;
        gulong purge_handler_id;
        guint64 offset;
-       guint32 length;
-       gpointer buffer;
        };
 struct _CaptivePrivateBcbPinObjectClass {
        CaptivePrivateBcbObjectClass parent_class;
@@ -131,9 +130,9 @@ static guint captive_private_bcb_pin_object_hash_new_hash_func(const guint64 *of
        return (*offsetp)^((*offsetp)>>32);
 }
 
-static gint captive_private_bcb_pin_object_hash_new_key_compare_func(const guint64 *offset_ap,const guint64 *offset_bp)
+static gboolean captive_private_bcb_pin_object_hash_new_key_compare_func(const guint64 *offset_ap,const guint64 *offset_bp)
 {
-       return (*offset_bp>*offset_ap)-(*offset_bp<*offset_ap);
+       return (*offset_ap)==(*offset_bp);
 }
 
 GHashTable *captive_private_bcb_pin_object_hash_new(void)
@@ -159,9 +158,10 @@ guint64 start,end;
                        CAPTIVE_PRIVATE_BCB_OBJECT(captive_private_bcb_pin_object)->SharedCacheMap));
 
        start=captive_private_bcb_pin_object->offset;
-       end  =captive_private_bcb_pin_object->offset+captive_private_bcb_pin_object->length;
+       end  =captive_private_bcb_pin_object->offset+PAGE_SIZE;
 
-       g_assert(end<=CAPTIVE_PRIVATE_BCB_OBJECT(captive_private_bcb_pin_object)->SharedCacheMap->ValidDataLength);
+       g_assert(end<=CAPTIVE_ROUND_UP64(
+                       CAPTIVE_PRIVATE_BCB_OBJECT(captive_private_bcb_pin_object)->SharedCacheMap->FileSize,PAGE_SIZE));
 }
 
 static void captive_private_bcb_pin_object_FileSizes_changed(CaptiveSharedCacheMapObject *captive_shared_cache_map_object,
@@ -239,6 +239,7 @@ CaptivePrivateBcbPinObject *captive_private_bcb_pin_object_new(CaptiveSharedCach
 CaptivePrivateBcbPinObject *captive_private_bcb_pin_object;
 
        g_return_val_if_fail(CAPTIVE_SHARED_CACHE_MAP_IS_OBJECT(captive_shared_cache_map_object),NULL);
+       g_return_val_if_fail(0==CAPTIVE_ROUND_DOWN_EXCEEDING64(offset,PAGE_SIZE),NULL);
 
        g_assert(captive_shared_cache_map_object->PinAccess);
 
@@ -247,13 +248,10 @@ CaptivePrivateBcbPinObject *captive_private_bcb_pin_object;
                        NULL);  /* first_property_name; FIXME: support properties */
 
        captive_private_bcb_pin_object->offset=offset;
-       captive_private_bcb_pin_object->length=PAGE_SIZE;
 
        _captive_private_bcb_pin_object_connect_SharedCacheMap(captive_private_bcb_pin_object,
                        captive_shared_cache_map_object);
 
-       captive_private_bcb_pin_object->buffer=captive_shared_cache_map_object->buffer+offset;
-
        g_assert(captive_shared_cache_map_object->pin_hash!=NULL);
        g_assert(!g_hash_table_lookup(captive_shared_cache_map_object->pin_hash,
                        &captive_private_bcb_pin_object->offset));
@@ -264,16 +262,32 @@ CaptivePrivateBcbPinObject *captive_private_bcb_pin_object;
        return captive_private_bcb_pin_object;
 }
 
-CaptivePrivateBcbPinObject *captive_private_bcb_pin_object_get_ref(CaptiveSharedCacheMapObject *captive_shared_cache_map_object,
+CaptivePrivateBcbPinObject *captive_private_bcb_pin_object_get(CaptiveSharedCacheMapObject *captive_shared_cache_map_object,
                guint64 offset)
 {
 CaptivePrivateBcbPinObject *captive_private_bcb_pin_object;
 
        g_return_val_if_fail(CAPTIVE_SHARED_CACHE_MAP_IS_OBJECT(captive_shared_cache_map_object),NULL);
+       g_return_val_if_fail(0==CAPTIVE_ROUND_DOWN_EXCEEDING64(offset,PAGE_SIZE),NULL);
 
        if ((captive_private_bcb_pin_object=g_hash_table_lookup(captive_shared_cache_map_object->pin_hash,
                        &offset))) {
                g_assert(CAPTIVE_PRIVATE_BCB_PIN_IS_OBJECT(captive_private_bcb_pin_object));
+               return captive_private_bcb_pin_object;
+               }
+       return NULL;
+}
+
+CaptivePrivateBcbPinObject *captive_private_bcb_pin_object_get_ref(CaptiveSharedCacheMapObject *captive_shared_cache_map_object,
+               guint64 offset)
+{
+CaptivePrivateBcbPinObject *captive_private_bcb_pin_object;
+
+       g_return_val_if_fail(CAPTIVE_SHARED_CACHE_MAP_IS_OBJECT(captive_shared_cache_map_object),NULL);
+       g_return_val_if_fail(0==CAPTIVE_ROUND_DOWN_EXCEEDING64(offset,PAGE_SIZE),NULL);
+
+       if ((captive_private_bcb_pin_object=captive_private_bcb_pin_object_get(captive_shared_cache_map_object,offset))) {
+               g_assert(CAPTIVE_PRIVATE_BCB_PIN_IS_OBJECT(captive_private_bcb_pin_object));
                g_object_ref(captive_private_bcb_pin_object);
                return captive_private_bcb_pin_object;
                }
@@ -300,7 +314,7 @@ void captive_private_bcb_pin_object_flush(CaptivePrivateBcbPinObject *captive_pr
        /* Flush synchronously here. */
        captive_shared_cache_map_flush(CAPTIVE_PRIVATE_BCB_OBJECT(captive_private_bcb_pin_object)->SharedCacheMap,
                        captive_private_bcb_pin_object->offset,
-                       captive_private_bcb_pin_object->offset+captive_private_bcb_pin_object->length);
+                       captive_private_bcb_pin_object->offset+PAGE_SIZE);
 }
 
 void captive_private_bcb_pin_object_set_dirty(CaptivePrivateBcbPinObject *captive_private_bcb_pin_object)
@@ -311,7 +325,7 @@ void captive_private_bcb_pin_object_set_dirty(CaptivePrivateBcbPinObject *captiv
 
        captive_shared_cache_map_set_dirty(CAPTIVE_PRIVATE_BCB_OBJECT(captive_private_bcb_pin_object)->SharedCacheMap,
                        captive_private_bcb_pin_object->offset,
-                       captive_private_bcb_pin_object->offset+captive_private_bcb_pin_object->length);
+                       captive_private_bcb_pin_object->offset+PAGE_SIZE);
 }
 
 void captive_private_bcb_pin_object_set_lsn(CaptivePrivateBcbPinObject *captive_private_bcb_pin_object,gint64 lsn)