My Project  debian-1:4.1.1-p2+ds-4build2
omBinPage.h
Go to the documentation of this file.
1 /*******************************************************************
2  * File: omBinPage.h
3  * Purpose: declaration of routines for primitve BinPage managment
4  * Author: obachman (Olaf Bachmann)
5  * Created: 11/99
6  *******************************************************************/
7 #ifndef OM_BIN_PAGE_H
8 #define OM_BIN_PAGE_H
9 
10 /***********************************************************************
11  *
12  * Macros for page manipulations
13  *
14  **********************************************************************/
15 
16 #define omIsAddrPageAligned(addr) \
17  (((long) (addr) & (SIZEOF_SYSTEM_PAGE -1)) == 0)
18 
19 #define omGetPageOfAddr(addr) \
20  ((void*) (((long)addr) & ~(SIZEOF_SYSTEM_PAGE -1)))
21 
22 #define omGetBinPageOfAddr(addr) \
23  ((omBinPage) ((long) (addr) & ~(SIZEOF_SYSTEM_PAGE -1)))
24 
25 #define omIsAddrOnPage(addr, page) (omGetPageOfAddr(addr) == (void*) (page))
26 
27 #define omAreAddrOnSamePage(a1, a2) \
28  (omGetPageOfAddr(a1) == omGetPageOfAddr(a2))
29 
30 /***********************************************************************
31  *
32  * Identifying whether an address is a BinPageAddr:
33  *
34  *******************************************************************/
35 
36 /* Here is how it works (assume SIZEOF_LONG == 4, SIZEOF_SYSTEM_PAGE = 2^12):
37  Let
38  Addr: | 15 | 5 | 12 |
39  PAGE_INDEX PAGE_SHIFT PAGE_OFFSET
40 
41  PAGE_BASE
42 
43  om_PageIndicies is an array of bit-fields which is indexed by
44  PAGE_INDEX - om_MinBinPageIndex. Its maximal length
45  is 2^15. PAGE_SHIFT is used as index into the bit-field.
46  If it's value is 1, then addr is from omBinPage, else
47  not.
48 
49  om_MinPageIndex is minimal page index of registered BinPageAddr
50 
51  In other words: omIsBinPageAddr iff PAGE_INDEX >= om_MinBinPageIndex && PAGE_INDEX <= om_MaxBinPageIndex
52  && om_PageIndicies[PAGE_INDEX - om_MinPageIndex] & (1 << PAGE_SHIFT) */
53 
54 extern unsigned long om_MaxBinPageIndex;
55 extern unsigned long om_MinBinPageIndex;
56 extern unsigned long *om_BinPageIndicies;
57 
58 #define OM_SIZEOF_INDEX_PAGE (((unsigned long) SIZEOF_SYSTEM_PAGE) << LOG_BIT_SIZEOF_LONG)
59 
60 #define omGetPageShiftOfAddr(addr) \
61  ((((unsigned long) addr) & (OM_SIZEOF_INDEX_PAGE -1)) >> LOG_BIT_SIZEOF_SYSTEM_PAGE)
62 
63 #define omGetPageIndexOfAddr(addr) \
64  (((unsigned long) addr) >> (LOG_BIT_SIZEOF_LONG + LOG_BIT_SIZEOF_SYSTEM_PAGE))
65 
66 
67 #if !defined(OM_INLINE) || defined(OM_INTERNAL_DEBUG)
68 #define omIsBinPageAddr(addr) _omIsBinPageAddr(addr)
69 #else
70 /* let's hope the compiler can eliminate common subexpressions well */ \
71 #define omIsBinPageAddr(addr) \
72  ((omGetPageIndexOfAddr(addr) >= om_MinBinPageIndex) && \
73  (omGetPageIndexOfAddr(addr) <= om_MaxBinPageIndex) && \
74  ((om_BinPageIndicies[omGetPageIndexOfAddr(addr) - om_MinBinPageIndex] & \
75  (((unsigned long) 1) << omGetPageShiftOfAddr(addr))) != 0))
76 #endif
77 
78 /*BEGINPRIVATE*/
79 /*******************************************************************
80  *
81  * Alloc/Free of BinPages
82  *
83  *******************************************************************/
84 extern omBinPage omAllocBinPages(int how_many);
85 extern omBinPage omAllocBinPage();
86 
87 extern void omFreeBinPages(omBinPage page, int how_many);
88 #define omFreeBinPage(addr) omFreeBinPages(addr, 1)
89 /*ENDPRIVATE*/
90 
91 #endif /* OM_BIN_PAGE_H */
omAllocBinPages
omBinPage omAllocBinPages(int how_many)
Definition: omBinPage.c:147
omFreeBinPages
void omFreeBinPages(omBinPage page, int how_many)
Definition: omBinPage.c:204
om_MaxBinPageIndex
unsigned long om_MaxBinPageIndex
Definition: omBinPage.c:34
om_BinPageIndicies
unsigned long * om_BinPageIndicies
Definition: omBinPage.c:36
omAllocBinPage
omBinPage omAllocBinPage()
Definition: omBinPage.c:96
om_MinBinPageIndex
unsigned long om_MinBinPageIndex
Definition: omBinPage.c:35
omBinPage
omBinPage_t * omBinPage
Definition: omStructs.h:16