1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:47:46 +00:00

Import the "gerbert" kernel I worked on earlier this year.

It's a lot crappier than I remembered it. It's gonna need a lot of work.
This commit is contained in:
Andreas Kling 2018-10-16 11:01:38 +02:00
parent f608629704
commit 9396108034
55 changed files with 4600 additions and 0 deletions

48
Kernel/RefCounted.h Normal file
View file

@ -0,0 +1,48 @@
#pragma once
#include "Assertions.h"
#include "VGA.h"
#define DEBUG_REFCOUNTED
class RefCountedBase {
protected:
bool derefBase() const
{
return !--m_refCount;
}
mutable size_t m_refCount { 1 };
#ifdef DEBUG_REFCOUNTED
//mutable bool m_adopted { false };
#endif
};
template<typename T>
class RefCounted : public RefCountedBase {
public:
size_t refCount() const { return m_refCount; }
void ref() const
{
#ifdef DEBUG_REFCOUNTED
ASSERT(m_refCount);
//ASSERT(m_adopted);
#endif
++m_refCount;
}
void deref() const
{
#ifdef DEBUG_REFCOUNTED
ASSERT(m_refCount);
//ASSERT(m_adopted);
#endif
if (derefBase())
delete static_cast<const T*>(this);
}
protected:
RefCounted() { }
~RefCounted() { }
};