LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
bitmap.h
Go to the documentation of this file.
1#ifndef _BITMAP_H_INCLUDED
2#define _BITMAP_H_INCLUDED
3
4#include <stdint.h>
5#include <stdbool.h>
6
9
11static inline size_t bitmap_size(size_t num_entries) {
12 return (num_entries + 7) / 8;
13}
14
17 return entry / 8;
18}
19
22 return 1 << (entry % 8);
23}
24
26static inline bool bitmap_get(bitmap_t bitmap, uint64_t entry) {
27 return (bitmap[bitmap_idx(entry)] & bitmap_bit(entry)) != 0;
28}
29
31static inline void bitmap_set(bitmap_t bitmap, uint64_t entry) {
32 bitmap[bitmap_idx(entry)] |= bitmap_bit(entry);
33}
34
36static inline void bitmap_clear(bitmap_t bitmap, uint64_t entry) {
37 bitmap[bitmap_idx(entry)] &= ~bitmap_bit(entry);
38}
39
40#endif
unsigned long uint64_t
Definition arch.h:14
unsigned char uint8_t
Definition arch.h:5
static bool bitmap_get(bitmap_t bitmap, uint64_t entry)
Retrieve state of the given entry from bitmap.
Definition bitmap.h:26
static uint8_t bitmap_bit(uint64_t entry)
Return the bitmask for the given bitmap index.
Definition bitmap.h:21
static size_t bitmap_size(size_t num_entries)
Return the size of the bitmap in bytes for a given amount of entries.
Definition bitmap.h:11
static uint64_t bitmap_idx(uint64_t entry)
Return the index in the bitmap array for the given bitmap index.
Definition bitmap.h:16
uint8_t * bitmap_t
Type for a single entry in the array.
Definition bitmap.h:8
static void bitmap_clear(bitmap_t bitmap, uint64_t entry)
Unset given entry in bitmap.
Definition bitmap.h:36
static void bitmap_set(bitmap_t bitmap, uint64_t entry)
Set given entry in bitmap.
Definition bitmap.h:31
static void * entry
Definition syscalls.h:34