captive_shared_cache_map_object_FileSizes_changed(): Improved performance.
[captive.git] / src / libcaptive / cc / sharedcachemap-priv.h
1 /* $Id$
2  * Object-private include file for reactos Cache Manager (Cc*) SharedCacheMap structure of libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #ifndef _CAPTIVE_CC_SHARED_CACHE_MAP_PRIV_H
21 #define _CAPTIVE_CC_SHARED_CACHE_MAP_PRIV_H 1
22
23
24 #include <glib/gmacros.h>
25 #include <glib-object.h>
26 #include "reactos/ddk/cctypes.h"
27 #include "privatebcbmap.h"
28
29
30 G_BEGIN_DECLS
31
32 typedef struct _CaptiveSharedCacheMapObject_page CaptiveSharedCacheMapObject_page;
33
34 struct _CaptiveSharedCacheMapObject_page {
35         gboolean data_valid;
36         gboolean dirty;
37         gint64 lsn_oldest,lsn_newest;
38         };
39
40 struct _CaptiveSharedCacheMapObject {
41         GObject parent_instance;
42
43         gint w32_ref_count;
44         FILE_OBJECT *FileObject;
45         SECTION_OBJECT_POINTERS *SectionObjectPointer;
46         /* ValidDataLength<=FileSize<=AllocationSize */
47         /* 'AllocationSize' sets the mmap(2)ed area of buffers of this SharedCacheMap.
48          * We must reallocate this area if 'AllocationSize' changes and in such case
49          * there must exist no map-Bcb or pin-Bcbs for it.
50          * We would cope with 'buffer' change with existing Bcbs but W32 client could not.
51          */
52         guint64 AllocationSize; /* ==CC_FILE_SIZES.AllocationSize.QuadPart */
53         /* We generally check against CAPTIVE_ROUND_UP64(FileSize,PAGE_SIZE)
54          * as the offsets are usually PAGE_SIZE aligned due to pin-Bcb expectations.
55          */
56         guint64 FileSize;       /* ==CC_FILE_SIZES.FileSize.QuadPart */
57         /* We use do not use 'ValidDataLength' as I assume W32
58          * automatically increases 'ValidDataLength' during Cache Manager write operations.
59          * We do not increase it and therefore it is mostly useless for us.
60          */
61         guint64 ValidDataLength;        /* ==CC_FILE_SIZES.ValidDataLength.QuadPart */
62         /* The real allocation size of 'buffer' and 'pages'.
63          * Maintained by captive_shared_cache_map_object_FileSizes_changed()
64          * to prevent continous reallocation to (n+1) size.
65          * We use (n*2) sizes for logaritmic time complexity.
66          */
67         guint64 alloc_length;
68         CACHE_MANAGER_CALLBACKS CallBacks;
69         VOID *LazyWriterContext;
70         gboolean PinAccess;
71         CaptivePrivateBcbMapObject *map;        /* 'map' will g_object_ref(CaptiveSharedCacheMapObject). */
72         GHashTable *pin_hash;   /* map: (guint64 *) -> (CaptivePrivateBcbPinObject *) */
73         gboolean LogHandle_set;
74         gboolean FlushToLsnRoutine_set;
75
76         gpointer buffer;        /* FileOffset 0 based */
77         CaptiveSharedCacheMapObject_page *pages;        /* FileOffset 0 based, item corresponds to 'buffer' PAGE_SIZE */
78         };
79 struct _CaptiveSharedCacheMapObjectClass {
80         GObjectClass parent_class;
81
82         void (*FileSizes_changed)(CaptiveSharedCacheMapObject *captive_shared_cache_map_object,
83                         guint64 AllocationSize,guint64 FileSize,guint64 ValidDataLength);
84         void (*purge)(CaptiveSharedCacheMapObject *captive_shared_cache_map_object);
85         };
86
87 G_END_DECLS
88
89
90 #endif /* _CAPTIVE_CC_SHARED_CACHE_MAP_PRIV_H */