src folder -> source folder; makes merging with dev a bit easier.
This commit is contained in:
40
source/kernel/kstructures/bitmap.h
Normal file
40
source/kernel/kstructures/bitmap.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
inline void bitmap_set( uint32_t* map , int index )
|
||||
{
|
||||
map[index/32] |= (1 << (index % 32));
|
||||
}
|
||||
|
||||
inline void bitmap_unset(uint32_t* map , int index)
|
||||
{
|
||||
map[index/32] &= ~(1 << (index % 32));
|
||||
}
|
||||
|
||||
inline uint32_t bitmap_first_unset( uint32_t* map , int map_size)
|
||||
{
|
||||
for ( int i = 0 ; i < map_size ; i ++ )
|
||||
{
|
||||
// a bit or more is set within this byte!
|
||||
if( (map[i] & 0xFFFFFFFF) > 0 ){
|
||||
|
||||
// which bit is set?
|
||||
for(int j = 0 ; j < 32 ; j++){
|
||||
if ( (map[i] & (0x00000001 << j)) > 0)
|
||||
{
|
||||
printf("Found bit: byte 0x%x , bit 0x%x\n", i , j);
|
||||
return (i*32)+j;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
Reference in New Issue
Block a user