source: git/omalloc/omBinPage.h @ 08a955

spielwiese
Last change on this file since 08a955 was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 3.3 KB
Line 
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
54extern unsigned long om_MaxBinPageIndex;
55extern unsigned long om_MinBinPageIndex;
56extern 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 *******************************************************************/
84extern omBinPage omAllocBinPages(int how_many);
85extern omBinPage omAllocBinPage();
86
87extern void omFreeBinPages(omBinPage page, int how_many);
88#define omFreeBinPage(addr) omFreeBinPages(addr, 1)
89/*ENDPRIVATE*/
90
91#endif /* OM_BIN_PAGE_H */
Note: See TracBrowser for help on using the repository browser.