Zero  0.1.0
alloc_page.h
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2013, Hewlett-Packard Development Company, LP
3  */
4 
5 #ifndef __ALLOC_PAGE_H
6 #define __ALLOC_PAGE_H
7 
8 #include "generic_page.h"
9 #include "sm_base.h"
10 #include "w_defines.h"
11 
12 typedef uint32_t extent_id_t;
13 
29 public:
30 
31  // First half of page (4KB) is the bitmap
32 
44  static constexpr int bitmapsize = sizeof(generic_page) / 2;
45 
46  static constexpr int bits_held = bitmapsize * 8;
47 
48  uint8_t bitmap[bitmapsize];
49 
50  // Fill second half of the page with char array (unused part). This is
51  // currently 4KB, whereas the bitmap occupies the remaining 4KB.
52  // This reserved space of 4KB is kept here just for future uses; it is
53  // currently not used.
54  char _fill[sizeof(generic_page) / 2 - sizeof(generic_page_header)];
55 
56  uint32_t byte_place(uint32_t index) {
57  return index >> 3;
58  }
59 
60  uint32_t bit_place(uint32_t index) {
61  return index & 0x7;
62  }
63 
64  uint32_t bit_mask(uint32_t index) {
65  return 1 << bit_place(index);
66  }
67 
68  bool get_bit(uint32_t index) {
69  return (bitmap[byte_place(index)] & bit_mask(index)) != 0;
70  }
71 
72  void unset_bit(uint32_t index) {
73  bitmap[byte_place(index)] &= ~bit_mask(index);
74  }
75 
76  void set_bit(uint32_t index) {
77  bitmap[byte_place(index)] |= bit_mask(index);
78  }
79 
80  uint32_t get_last_set_bit();
81 
82  void set_bits(uint32_t from, uint32_t to);
83 
84  void format_empty();
85 
86  // Used to generate page_img_format log records
87  char* unused_part(size_t& length) {
88  auto first_unset_byte = byte_place(get_last_set_bit()) + 1;
89  char* pos = reinterpret_cast<char*>(&bitmap[first_unset_byte]);
90  length = sizeof(alloc_page) - (pos - reinterpret_cast<char*>(this));
91  w_assert1(length >= sizeof(_fill));
92  return pos;
93  }
94 };
95 
97 
98 #endif // __ALLOC_PAGE_H
void format_empty()
Definition: alloc_page.cpp:7
void set_bit(uint32_t index)
Definition: alloc_page.h:76
#define w_assert1(x)
Level 1 should not add significant extra time.
Definition: w_base.h:198
BOOST_STATIC_ASSERT(sizeof(alloc_page)==generic_page_header::page_sz)
void unset_bit(uint32_t index)
Definition: alloc_page.h:72
A generic page view: any Zero page can be viewed as being of this type but it only exposes fields sha...
Definition: generic_page.h:121
Page headers shared by all Zero pages.
Definition: generic_page.h:34
uint32_t bit_place(uint32_t index)
Definition: alloc_page.h:60
char * unused_part(size_t &length)
Definition: alloc_page.h:87
uint32_t extent_id_t
Definition: alloc_page.h:12
bool get_bit(uint32_t index)
Definition: alloc_page.h:68
uint8_t bitmap[bitmapsize]
Definition: alloc_page.h:48
Free-page allocation/deallocation page.
Definition: alloc_page.h:28
uint32_t get_last_set_bit()
Definition: alloc_page.cpp:35
void set_bits(uint32_t from, uint32_t to)
Definition: alloc_page.cpp:14
static constexpr int bits_held
Definition: alloc_page.h:46
static constexpr int bitmapsize
Definition: alloc_page.h:44
uint32_t bit_mask(uint32_t index)
Definition: alloc_page.h:64
char _fill[sizeof(generic_page)/2 - sizeof(generic_page_header)]
Definition: alloc_page.h:54
static const size_t page_sz
Size of all Zero pages.
Definition: generic_page.h:37
uint32_t byte_place(uint32_t index)
Definition: alloc_page.h:56