Compare commits
4 Commits
16954695dd
...
acb0ab1cd7
Author | SHA1 | Date | |
---|---|---|---|
acb0ab1cd7 | |||
ace674e518 | |||
2cbc9fa385 | |||
f77126768f |
@ -30,7 +30,7 @@ void heap_thread()
|
|||||||
{
|
{
|
||||||
CPU::disable_interrupts();
|
CPU::disable_interrupts();
|
||||||
dump_heap_usage();
|
dump_heap_usage();
|
||||||
kdbgln("uses %lu vm pages", KernelVM::used() / ARCH_PAGE_SIZE);
|
kdbgln("Kernel uses %lu vm pages", KernelVM::used() / ARCH_PAGE_SIZE);
|
||||||
while (true) kernel_sleep(UINT64_MAX);
|
while (true) kernel_sleep(UINT64_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <luna/TypeTraits.h>
|
||||||
|
|
||||||
// Must ALWAYS be called with a power of two as alignment.
|
// Must ALWAYS be called with a power of two as alignment.
|
||||||
template <usize alignment, typename T> constexpr T is_aligned(T value)
|
template <usize alignment, typename T> constexpr T is_aligned(T value)
|
||||||
{
|
{
|
||||||
static_assert((alignment & (alignment - 1)) == 0);
|
static_assert(IsPowerOfTwo<usize, alignment>);
|
||||||
return (value % alignment == 0);
|
return (value % alignment == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ static_assert(is_aligned<4096>(40960u));
|
|||||||
// Must ALWAYS be called with a power of two as alignment.
|
// Must ALWAYS be called with a power of two as alignment.
|
||||||
template <usize alignment, typename T> constexpr T align_down(T value)
|
template <usize alignment, typename T> constexpr T align_down(T value)
|
||||||
{
|
{
|
||||||
static_assert((alignment & (alignment - 1)) == 0);
|
static_assert(IsPowerOfTwo<usize, alignment>);
|
||||||
return value - value % alignment;
|
return value - value % alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <luna/Option.h>
|
#include <luna/Option.h>
|
||||||
|
#include <luna/TypeTraits.h>
|
||||||
|
|
||||||
template <typename T> inline Option<T*> nonnull_or_error(T* ptr)
|
template <typename T> inline Option<T*> nonnull_or_error(T* ptr)
|
||||||
{
|
{
|
||||||
@ -57,6 +58,8 @@ template <typename T> class DoublyLinkedList
|
|||||||
{
|
{
|
||||||
using Node = DoublyLinkedListNode<T>;
|
using Node = DoublyLinkedListNode<T>;
|
||||||
|
|
||||||
|
static_assert(IsBaseOf<DoublyLinkedListNode<T>, T>);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void append(T* ptr)
|
void append(T* ptr)
|
||||||
{
|
{
|
||||||
|
4
luna/include/luna/TypeTraits.h
Normal file
4
luna/include/luna/TypeTraits.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
template <typename Base, typename Derived> inline constexpr bool IsBaseOf = __is_base_of(Base, Derived);
|
||||||
|
template <typename T, T value> inline constexpr bool IsPowerOfTwo = (value & (value - 1)) == 0;
|
Loading…
Reference in New Issue
Block a user