1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

AK: Rename Retainable => RefCounted.

(And various related renames that go along with it.)
This commit is contained in:
Andreas Kling 2019-06-21 15:29:31 +02:00
parent ef1bfcb9d8
commit 77b9fa89dd
45 changed files with 118 additions and 118 deletions

View file

@ -8,7 +8,7 @@
namespace AK { namespace AK {
class ByteBufferImpl : public Retainable<ByteBufferImpl> { class ByteBufferImpl : public RefCounted<ByteBufferImpl> {
public: public:
static Retained<ByteBufferImpl> create_uninitialized(int size); static Retained<ByteBufferImpl> create_uninitialized(int size);
static Retained<ByteBufferImpl> create_zeroed(int); static Retained<ByteBufferImpl> create_zeroed(int);

View file

@ -30,7 +30,7 @@ void JsonValue::copy_from(const JsonValue& other)
switch (m_type) { switch (m_type) {
case Type::String: case Type::String:
m_value.as_string = other.m_value.as_string; m_value.as_string = other.m_value.as_string;
AK::retain_if_not_null(m_value.as_string); AK::ref_if_not_null(m_value.as_string);
break; break;
case Type::Object: case Type::Object:
m_value.as_object = new JsonObject(*other.m_value.as_object); m_value.as_object = new JsonObject(*other.m_value.as_object);
@ -101,7 +101,7 @@ JsonValue::JsonValue(const String& value)
} else { } else {
m_type = Type::String; m_type = Type::String;
m_value.as_string = const_cast<StringImpl*>(value.impl()); m_value.as_string = const_cast<StringImpl*>(value.impl());
AK::retain_if_not_null(m_value.as_string); AK::ref_if_not_null(m_value.as_string);
} }
} }
@ -121,7 +121,7 @@ void JsonValue::clear()
{ {
switch (m_type) { switch (m_type) {
case Type::String: case Type::String:
AK::release_if_not_null(m_value.as_string); AK::deref_if_not_null(m_value.as_string);
break; break;
case Type::Object: case Type::Object:
delete m_value.as_object; delete m_value.as_object;

View file

@ -16,22 +16,22 @@ public:
RetainPtr(const T* ptr) RetainPtr(const T* ptr)
: m_ptr(const_cast<T*>(ptr)) : m_ptr(const_cast<T*>(ptr))
{ {
retain_if_not_null(m_ptr); ref_if_not_null(m_ptr);
} }
RetainPtr(T* ptr) RetainPtr(T* ptr)
: m_ptr(ptr) : m_ptr(ptr)
{ {
retain_if_not_null(m_ptr); ref_if_not_null(m_ptr);
} }
RetainPtr(T& object) RetainPtr(T& object)
: m_ptr(&object) : m_ptr(&object)
{ {
m_ptr->retain(); m_ptr->ref();
} }
RetainPtr(const T& object) RetainPtr(const T& object)
: m_ptr(const_cast<T*>(&object)) : m_ptr(const_cast<T*>(&object))
{ {
m_ptr->retain(); m_ptr->ref();
} }
RetainPtr(AdoptTag, T& object) RetainPtr(AdoptTag, T& object)
: m_ptr(&object) : m_ptr(&object)
@ -79,7 +79,7 @@ public:
RetainPtr& operator=(RetainPtr&& other) RetainPtr& operator=(RetainPtr&& other)
{ {
if (this != &other) { if (this != &other) {
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = other.leak_ref(); m_ptr = other.leak_ref();
} }
return *this; return *this;
@ -89,7 +89,7 @@ public:
RetainPtr& operator=(RetainPtr<U>&& other) RetainPtr& operator=(RetainPtr<U>&& other)
{ {
if (this != static_cast<void*>(&other)) { if (this != static_cast<void*>(&other)) {
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = other.leak_ref(); m_ptr = other.leak_ref();
} }
return *this; return *this;
@ -98,7 +98,7 @@ public:
template<typename U> template<typename U>
RetainPtr& operator=(Retained<U>&& other) RetainPtr& operator=(Retained<U>&& other)
{ {
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = &other.leak_ref(); m_ptr = &other.leak_ref();
return *this; return *this;
} }
@ -107,10 +107,10 @@ public:
RetainPtr& operator=(const Retained<U>& other) RetainPtr& operator=(const Retained<U>& other)
{ {
if (m_ptr != other.ptr()) if (m_ptr != other.ptr())
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = const_cast<T*>(other.ptr()); m_ptr = const_cast<T*>(other.ptr());
ASSERT(m_ptr); ASSERT(m_ptr);
retain_if_not_null(m_ptr); ref_if_not_null(m_ptr);
return *this; return *this;
} }
@ -118,27 +118,27 @@ public:
RetainPtr& operator=(const RetainPtr<U>& other) RetainPtr& operator=(const RetainPtr<U>& other)
{ {
if (m_ptr != other.ptr()) if (m_ptr != other.ptr())
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = const_cast<T*>(other.ptr()); m_ptr = const_cast<T*>(other.ptr());
retain_if_not_null(m_ptr); ref_if_not_null(m_ptr);
return *this; return *this;
} }
RetainPtr& operator=(const T* ptr) RetainPtr& operator=(const T* ptr)
{ {
if (m_ptr != ptr) if (m_ptr != ptr)
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = const_cast<T*>(ptr); m_ptr = const_cast<T*>(ptr);
retain_if_not_null(m_ptr); ref_if_not_null(m_ptr);
return *this; return *this;
} }
RetainPtr& operator=(const T& object) RetainPtr& operator=(const T& object)
{ {
if (m_ptr != &object) if (m_ptr != &object)
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = const_cast<T*>(&object); m_ptr = const_cast<T*>(&object);
retain_if_not_null(m_ptr); ref_if_not_null(m_ptr);
return *this; return *this;
} }
@ -155,7 +155,7 @@ public:
void clear() void clear()
{ {
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = nullptr; m_ptr = nullptr;
} }

View file

@ -18,61 +18,61 @@ constexpr auto call_will_be_destroyed_if_present(...) -> FalseType
} }
template<class T> template<class T>
constexpr auto call_one_retain_left_if_present(T* object) -> decltype(object->one_retain_left(), TrueType {}) constexpr auto call_one_ref_left_if_present(T* object) -> decltype(object->one_ref_left(), TrueType {})
{ {
object->one_retain_left(); object->one_ref_left();
return {}; return {};
} }
constexpr auto call_one_retain_left_if_present(...) -> FalseType constexpr auto call_one_ref_left_if_present(...) -> FalseType
{ {
return {}; return {};
} }
class RetainableBase { class RefCountedBase {
public: public:
void retain() void ref()
{ {
ASSERT(m_retain_count); ASSERT(m_ref_count);
++m_retain_count; ++m_ref_count;
} }
int retain_count() const int ref_count() const
{ {
return m_retain_count; return m_ref_count;
} }
protected: protected:
RetainableBase() {} RefCountedBase() {}
~RetainableBase() ~RefCountedBase()
{ {
ASSERT(!m_retain_count); ASSERT(!m_ref_count);
} }
void release_base() void deref_base()
{ {
ASSERT(m_retain_count); ASSERT(m_ref_count);
--m_retain_count; --m_ref_count;
} }
int m_retain_count { 1 }; int m_ref_count { 1 };
}; };
template<typename T> template<typename T>
class Retainable : public RetainableBase { class RefCounted : public RefCountedBase {
public: public:
void release() void deref()
{ {
release_base(); deref_base();
if (m_retain_count == 0) { if (m_ref_count == 0) {
call_will_be_destroyed_if_present(static_cast<T*>(this)); call_will_be_destroyed_if_present(static_cast<T*>(this));
delete static_cast<T*>(this); delete static_cast<T*>(this);
} else if (m_retain_count == 1) { } else if (m_ref_count == 1) {
call_one_retain_left_if_present(static_cast<T*>(this)); call_one_ref_left_if_present(static_cast<T*>(this));
} }
} }
}; };
} }
using AK::Retainable; using AK::RefCounted;

View file

@ -18,17 +18,17 @@
namespace AK { namespace AK {
template<typename T> template<typename T>
inline void retain_if_not_null(T* ptr) inline void ref_if_not_null(T* ptr)
{ {
if (ptr) if (ptr)
ptr->retain(); ptr->ref();
} }
template<typename T> template<typename T>
inline void release_if_not_null(T* ptr) inline void deref_if_not_null(T* ptr)
{ {
if (ptr) if (ptr)
ptr->release(); ptr->deref();
} }
template<typename T> template<typename T>
@ -42,14 +42,14 @@ public:
Retained(const T& object) Retained(const T& object)
: m_ptr(const_cast<T*>(&object)) : m_ptr(const_cast<T*>(&object))
{ {
m_ptr->retain(); m_ptr->ref();
} }
template<typename U> template<typename U>
RETURN_TYPESTATE(unconsumed) RETURN_TYPESTATE(unconsumed)
Retained(const U& object) Retained(const U& object)
: m_ptr(&const_cast<T&>(static_cast<const T&>(object))) : m_ptr(&const_cast<T&>(static_cast<const T&>(object)))
{ {
m_ptr->retain(); m_ptr->ref();
} }
RETURN_TYPESTATE(unconsumed) RETURN_TYPESTATE(unconsumed)
Retained(AdoptTag, T& object) Retained(AdoptTag, T& object)
@ -85,7 +85,7 @@ public:
} }
~Retained() ~Retained()
{ {
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = nullptr; m_ptr = nullptr;
#ifdef SANITIZE_PTRS #ifdef SANITIZE_PTRS
if constexpr (sizeof(T*) == 8) if constexpr (sizeof(T*) == 8)
@ -99,7 +99,7 @@ public:
Retained& operator=(Retained&& other) Retained& operator=(Retained&& other)
{ {
if (this != &other) { if (this != &other) {
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = &other.leak_ref(); m_ptr = &other.leak_ref();
} }
return *this; return *this;
@ -110,7 +110,7 @@ public:
Retained& operator=(Retained<U>&& other) Retained& operator=(Retained<U>&& other)
{ {
if (this != static_cast<void*>(&other)) { if (this != static_cast<void*>(&other)) {
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = &other.leak_ref(); m_ptr = &other.leak_ref();
} }
return *this; return *this;
@ -120,9 +120,9 @@ public:
Retained& operator=(T& object) Retained& operator=(T& object)
{ {
if (m_ptr != &object) if (m_ptr != &object)
release_if_not_null(m_ptr); deref_if_not_null(m_ptr);
m_ptr = &object; m_ptr = &object;
m_ptr->retain(); m_ptr->ref();
return *this; return *this;
} }

View file

@ -12,7 +12,7 @@ enum ShouldChomp {
Chomp Chomp
}; };
class StringImpl : public Retainable<StringImpl> { class StringImpl : public RefCounted<StringImpl> {
public: public:
static Retained<StringImpl> create_uninitialized(int length, char*& buffer); static Retained<StringImpl> create_uninitialized(int length, char*& buffer);
static RetainPtr<StringImpl> create(const char* cstring, ShouldChomp = NoChomp); static RetainPtr<StringImpl> create(const char* cstring, ShouldChomp = NoChomp);

View file

@ -12,7 +12,7 @@ template<typename T>
class WeakPtr; class WeakPtr;
template<typename T> template<typename T>
class WeakLink : public Retainable<WeakLink<T>> { class WeakLink : public RefCounted<WeakLink<T>> {
friend class Weakable<T>; friend class Weakable<T>;
public: public:

View file

@ -11,7 +11,7 @@ class IRCClient;
class IRCChannelMemberListModel; class IRCChannelMemberListModel;
class IRCWindow; class IRCWindow;
class IRCChannel : public Retainable<IRCChannel> { class IRCChannel : public RefCounted<IRCChannel> {
public: public:
static Retained<IRCChannel> create(IRCClient&, const String&); static Retained<IRCChannel> create(IRCClient&, const String&);
~IRCChannel(); ~IRCChannel();

View file

@ -8,7 +8,7 @@
class IRCLogBufferModel; class IRCLogBufferModel;
class IRCLogBuffer : public Retainable<IRCLogBuffer> { class IRCLogBuffer : public RefCounted<IRCLogBuffer> {
public: public:
static Retained<IRCLogBuffer> create(); static Retained<IRCLogBuffer> create();
~IRCLogBuffer(); ~IRCLogBuffer();

View file

@ -10,7 +10,7 @@
class IRCClient; class IRCClient;
class IRCWindow; class IRCWindow;
class IRCQuery : public Retainable<IRCQuery> { class IRCQuery : public RefCounted<IRCQuery> {
public: public:
static Retained<IRCQuery> create(IRCClient&, const String& name); static Retained<IRCQuery> create(IRCClient&, const String& name);
~IRCQuery(); ~IRCQuery();

View file

@ -39,7 +39,7 @@ inline void for_each_direction(Callback callback)
callback(Direction::DownLeft); callback(Direction::DownLeft);
} }
class VBWidget : public Retainable<VBWidget> class VBWidget : public RefCounted<VBWidget>
, public Weakable<VBWidget> { , public Weakable<VBWidget> {
friend class VBWidgetPropertyModel; friend class VBWidgetPropertyModel;

View file

@ -6,7 +6,7 @@
// FIXME: Support 64-bit DiskOffset // FIXME: Support 64-bit DiskOffset
typedef dword DiskOffset; typedef dword DiskOffset;
class DiskDevice : public Retainable<DiskDevice> { class DiskDevice : public RefCounted<DiskDevice> {
public: public:
virtual ~DiskDevice(); virtual ~DiskDevice();

View file

@ -39,7 +39,7 @@ class Region;
// - Called by mmap() when userspace wants to memory-map this File somewhere. // - Called by mmap() when userspace wants to memory-map this File somewhere.
// - Should create a Region in the Process and return it if successful. // - Should create a Region in the Process and return it if successful.
class File : public Retainable<File> { class File : public RefCounted<File> {
public: public:
virtual ~File(); virtual ~File();

View file

@ -10,7 +10,7 @@ class VFS;
// FIXME: Custody needs some locking. // FIXME: Custody needs some locking.
class Custody : public Retainable<Custody> { class Custody : public RefCounted<Custody> {
public: public:
static Custody* get_if_cached(Custody* parent, const String& name); static Custody* get_if_cached(Custody* parent, const String& name);
static Retained<Custody> get_or_create(Custody* parent, const String& name, Inode&); static Retained<Custody> get_or_create(Custody* parent, const String& name, Inode&);

View file

@ -1232,7 +1232,7 @@ InodeIdentifier Ext2FSInode::lookup(StringView name)
return {}; return {};
} }
void Ext2FSInode::one_retain_left() void Ext2FSInode::one_ref_left()
{ {
// FIXME: I would like to not live forever, but uncached Ext2FS is fucking painful right now. // FIXME: I would like to not live forever, but uncached Ext2FS is fucking painful right now.
} }

View file

@ -21,7 +21,7 @@ public:
bool is_symlink() const { return ::is_symlink(m_raw_inode.i_mode); } bool is_symlink() const { return ::is_symlink(m_raw_inode.i_mode); }
// ^Inode (Retainable magic) // ^Inode (Retainable magic)
virtual void one_retain_left() override; virtual void one_ref_left() override;
private: private:
// ^Inode // ^Inode

View file

@ -19,7 +19,7 @@ class Region;
class CharacterDevice; class CharacterDevice;
class SharedMemory; class SharedMemory;
class FileDescription : public Retainable<FileDescription> { class FileDescription : public RefCounted<FileDescription> {
public: public:
static Retained<FileDescription> create(RetainPtr<Custody>&&); static Retained<FileDescription> create(RetainPtr<Custody>&&);
static Retained<FileDescription> create(RetainPtr<File>&&, SocketRole = SocketRole::None); static Retained<FileDescription> create(RetainPtr<File>&&, SocketRole = SocketRole::None);

View file

@ -23,7 +23,7 @@ class FileDescription;
class LocalSocket; class LocalSocket;
class VMObject; class VMObject;
class FS : public Retainable<FS> { class FS : public RefCounted<FS> {
friend class Inode; friend class Inode;
public: public:

View file

@ -14,14 +14,14 @@ class FileDescription;
class LocalSocket; class LocalSocket;
class VMObject; class VMObject;
class Inode : public Retainable<Inode> { class Inode : public RefCounted<Inode> {
friend class VFS; friend class VFS;
friend class FS; friend class FS;
public: public:
virtual ~Inode(); virtual ~Inode();
virtual void one_retain_left() {} virtual void one_ref_left() {}
FS& fs() { return m_fs; } FS& fs() { return m_fs; }
const FS& fs() const { return m_fs; } const FS& fs() const { return m_fs; }

View file

@ -293,13 +293,13 @@ ByteBuffer procfs$pid_vmo(InodeIdentifier identifier)
region->vmo().is_anonymous() ? "anonymous" : "file-backed", region->vmo().is_anonymous() ? "anonymous" : "file-backed",
region->vmo().name().characters(), region->vmo().name().characters(),
&region->vmo(), &region->vmo(),
region->vmo().retain_count()); region->vmo().ref_count());
for (size_t i = 0; i < region->vmo().page_count(); ++i) { for (size_t i = 0; i < region->vmo().page_count(); ++i) {
auto& physical_page = region->vmo().physical_pages()[i]; auto& physical_page = region->vmo().physical_pages()[i];
builder.appendf("P%x%s(%u) ", builder.appendf("P%x%s(%u) ",
physical_page ? physical_page->paddr().get() : 0, physical_page ? physical_page->paddr().get() : 0,
region->should_cow(i) ? "!" : "", region->should_cow(i) ? "!" : "",
physical_page ? physical_page->retain_count() : 0); physical_page ? physical_page->ref_count() : 0);
} }
builder.appendf("\n"); builder.appendf("\n");
} }
@ -406,7 +406,7 @@ ByteBuffer procfs$mm(InodeIdentifier)
builder.appendf("VMO: %p %s(%u): p:%4u %s\n", builder.appendf("VMO: %p %s(%u): p:%4u %s\n",
vmo, vmo,
vmo->is_anonymous() ? "anon" : "file", vmo->is_anonymous() ? "anon" : "file",
vmo->retain_count(), vmo->ref_count(),
vmo->page_count(), vmo->page_count(),
vmo->name().characters()); vmo->name().characters());
} }
@ -615,7 +615,7 @@ ByteBuffer procfs$inodes(InodeIdentifier)
StringBuilder builder; StringBuilder builder;
for (auto it : all_inodes()) { for (auto it : all_inodes()) {
RetainPtr<Inode> inode = *it; RetainPtr<Inode> inode = *it;
builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode.ptr(), inode->fsid(), inode->index(), inode->retain_count()); builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode.ptr(), inode->fsid(), inode->index(), inode->ref_count());
} }
return builder.to_byte_buffer(); return builder.to_byte_buffer();
} }

View file

@ -2032,7 +2032,7 @@ size_t Process::amount_shared() const
{ {
// FIXME: This will double count if multiple regions use the same physical page. // FIXME: This will double count if multiple regions use the same physical page.
// FIXME: It doesn't work at the moment, since it relies on PhysicalPage retain counts, // FIXME: It doesn't work at the moment, since it relies on PhysicalPage retain counts,
// and each PhysicalPage is only retained by its VMObject. This needs to be refactored // and each PhysicalPage is only reffed by its VMObject. This needs to be refactored
// so that every Region contributes +1 retain to each of its PhysicalPages. // so that every Region contributes +1 retain to each of its PhysicalPages.
size_t amount = 0; size_t amount = 0;
for (auto& region : m_regions) { for (auto& region : m_regions) {
@ -2417,8 +2417,8 @@ struct SharedBuffer {
pid_t pid1() const { return m_pid1; } pid_t pid1() const { return m_pid1; }
pid_t pid2() const { return m_pid2; } pid_t pid2() const { return m_pid2; }
unsigned pid1_retain_count() const { return m_pid1_retain_count; } unsigned pid1_ref_count() const { return m_pid1_retain_count; }
unsigned pid2_retain_count() const { return m_pid2_retain_count; } unsigned pid2_ref_count() const { return m_pid2_retain_count; }
size_t size() const { return m_vmo->size(); } size_t size() const { return m_vmo->size(); }
void destroy_if_unused(); void destroy_if_unused();

View file

@ -61,11 +61,11 @@ bool MasterPTY::can_write(FileDescription&) const
void MasterPTY::notify_slave_closed(Badge<SlavePTY>) void MasterPTY::notify_slave_closed(Badge<SlavePTY>)
{ {
#ifdef MASTERPTY_DEBUG #ifdef MASTERPTY_DEBUG
dbgprintf("MasterPTY(%u): slave closed, my retains: %u, slave retains: %u\n", m_index, retain_count(), m_slave->retain_count()); dbgprintf("MasterPTY(%u): slave closed, my retains: %u, slave retains: %u\n", m_index, ref_count(), m_slave->ref_count());
#endif #endif
// +1 retain for my MasterPTY::m_slave // +1 retain for my MasterPTY::m_slave
// +1 retain for FileDescription::m_device // +1 retain for FileDescription::m_device
if (m_slave->retain_count() == 2) if (m_slave->ref_count() == 2)
m_slave = nullptr; m_slave = nullptr;
} }
@ -86,7 +86,7 @@ bool MasterPTY::can_write_from_slave() const
void MasterPTY::close() void MasterPTY::close()
{ {
if (retain_count() == 2) { if (ref_count() == 2) {
InterruptDisabler disabler; InterruptDisabler disabler;
// After the closing FileDescription dies, slave is the only thing keeping me alive. // After the closing FileDescription dies, slave is the only thing keeping me alive.
// From this point, let's consider ourselves closed. // From this point, let's consider ourselves closed.

View file

@ -324,7 +324,7 @@ bool MemoryManager::copy_on_write(Region& region, unsigned page_index_in_region)
{ {
ASSERT_INTERRUPTS_DISABLED(); ASSERT_INTERRUPTS_DISABLED();
auto& vmo = region.vmo(); auto& vmo = region.vmo();
if (vmo.physical_pages()[page_index_in_region]->retain_count() == 1) { if (vmo.physical_pages()[page_index_in_region]->ref_count() == 1) {
#ifdef PAGE_FAULT_DEBUG #ifdef PAGE_FAULT_DEBUG
dbgprintf(" >> It's a COW page but nobody is sharing it anymore. Remap r/w\n"); dbgprintf(" >> It's a COW page but nobody is sharing it anymore. Remap r/w\n");
#endif #endif

View file

@ -6,7 +6,7 @@
#include <Kernel/VM/PhysicalPage.h> #include <Kernel/VM/PhysicalPage.h>
#include <Kernel/VM/RangeAllocator.h> #include <Kernel/VM/RangeAllocator.h>
class PageDirectory : public Retainable<PageDirectory> { class PageDirectory : public RefCounted<PageDirectory> {
friend class MemoryManager; friend class MemoryManager;
public: public:

View file

@ -12,13 +12,13 @@ class PhysicalPage {
public: public:
PhysicalAddress paddr() const { return m_paddr; } PhysicalAddress paddr() const { return m_paddr; }
void retain() void ref()
{ {
ASSERT(m_retain_count); ASSERT(m_retain_count);
++m_retain_count; ++m_retain_count;
} }
void release() void deref()
{ {
ASSERT(m_retain_count); ASSERT(m_retain_count);
if (!--m_retain_count) { if (!--m_retain_count) {
@ -30,7 +30,7 @@ public:
static Retained<PhysicalPage> create(PhysicalAddress, bool supervisor, bool may_return_to_freelist = true); static Retained<PhysicalPage> create(PhysicalAddress, bool supervisor, bool may_return_to_freelist = true);
word retain_count() const { return m_retain_count; } word ref_count() const { return m_retain_count; }
private: private:
PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist = true); PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist = true);

View file

@ -6,7 +6,7 @@
#include <Kernel/PhysicalAddress.h> #include <Kernel/PhysicalAddress.h>
#include <Kernel/VM/PhysicalPage.h> #include <Kernel/VM/PhysicalPage.h>
class PhysicalRegion : public Retainable<PhysicalRegion> { class PhysicalRegion : public RefCounted<PhysicalRegion> {
AK_MAKE_ETERNAL AK_MAKE_ETERNAL
public: public:

View file

@ -129,7 +129,7 @@ size_t Region::amount_shared() const
size_t bytes = 0; size_t bytes = 0;
for (size_t i = 0; i < page_count(); ++i) { for (size_t i = 0; i < page_count(); ++i) {
auto& physical_page = m_vmo->physical_pages()[first_page_index() + i]; auto& physical_page = m_vmo->physical_pages()[first_page_index() + i];
if (physical_page && physical_page->retain_count() > 1) if (physical_page && physical_page->ref_count() > 1)
bytes += PAGE_SIZE; bytes += PAGE_SIZE;
} }
return bytes; return bytes;

View file

@ -8,7 +8,7 @@
class Inode; class Inode;
class VMObject; class VMObject;
class Region : public Retainable<Region> { class Region : public RefCounted<Region> {
friend class MemoryManager; friend class MemoryManager;
public: public:

View file

@ -13,7 +13,7 @@
class Inode; class Inode;
class PhysicalPage; class PhysicalPage;
class VMObject : public Retainable<VMObject> class VMObject : public RefCounted<VMObject>
, public Weakable<VMObject> { , public Weakable<VMObject> {
friend class MemoryManager; friend class MemoryManager;

View file

@ -3,7 +3,7 @@
#include <AK/RetainPtr.h> #include <AK/RetainPtr.h>
#include <AK/Retainable.h> #include <AK/Retainable.h>
class SharedBuffer : public Retainable<SharedBuffer> { class SharedBuffer : public RefCounted<SharedBuffer> {
public: public:
static RetainPtr<SharedBuffer> create(pid_t peer, int); static RetainPtr<SharedBuffer> create(pid_t peer, int);
static RetainPtr<SharedBuffer> create_from_shared_buffer_id(int); static RetainPtr<SharedBuffer> create_from_shared_buffer_id(int);

View file

@ -7,7 +7,7 @@
#include <AK/Vector.h> #include <AK/Vector.h>
#include <SharedGraphics/Color.h> #include <SharedGraphics/Color.h>
class CConfigFile : public Retainable<CConfigFile> { class CConfigFile : public RefCounted<CConfigFile> {
public: public:
static Retained<CConfigFile> get_for_app(const String& app_name); static Retained<CConfigFile> get_for_app(const String& app_name);
static Retained<CConfigFile> get_for_system(const String& app_name); static Retained<CConfigFile> get_for_system(const String& app_name);

View file

@ -3,7 +3,7 @@
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/Retainable.h> #include <AK/Retainable.h>
class CNetworkResponse : public Retainable<CNetworkResponse> { class CNetworkResponse : public RefCounted<CNetworkResponse> {
public: public:
virtual ~CNetworkResponse(); virtual ~CNetworkResponse();

View file

@ -15,7 +15,7 @@ class GButton;
class GMenuItem; class GMenuItem;
class GWidget; class GWidget;
class GAction : public Retainable<GAction> class GAction : public RefCounted<GAction>
, public Weakable<GAction> { , public Weakable<GAction> {
public: public:
enum class ShortcutScope { enum class ShortcutScope {

View file

@ -3,7 +3,7 @@
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <SharedGraphics/GraphicsBitmap.h> #include <SharedGraphics/GraphicsBitmap.h>
class GIconImpl : public Retainable<GIconImpl> { class GIconImpl : public RefCounted<GIconImpl> {
public: public:
static Retained<GIconImpl> create() { return adopt(*new GIconImpl); } static Retained<GIconImpl> create() { return adopt(*new GIconImpl); }
~GIconImpl() {} ~GIconImpl() {}

View file

@ -39,7 +39,7 @@ private:
GModelIndex m_index; GModelIndex m_index;
}; };
class GModel : public Retainable<GModel> { class GModel : public RefCounted<GModel> {
public: public:
struct ColumnMetadata { struct ColumnMetadata {
int preferred_width { 0 }; int preferred_width { 0 };

View file

@ -14,13 +14,13 @@ void GVariant::clear()
{ {
switch (m_type) { switch (m_type) {
case Type::String: case Type::String:
AK::release_if_not_null(m_value.as_string); AK::deref_if_not_null(m_value.as_string);
break; break;
case Type::Bitmap: case Type::Bitmap:
AK::release_if_not_null(m_value.as_bitmap); AK::deref_if_not_null(m_value.as_bitmap);
break; break;
case Type::Icon: case Type::Icon:
AK::release_if_not_null(m_value.as_icon); AK::deref_if_not_null(m_value.as_icon);
break; break;
default: default:
break; break;
@ -51,21 +51,21 @@ GVariant::GVariant(const String& value)
: m_type(Type::String) : m_type(Type::String)
{ {
m_value.as_string = const_cast<StringImpl*>(value.impl()); m_value.as_string = const_cast<StringImpl*>(value.impl());
AK::retain_if_not_null(m_value.as_string); AK::ref_if_not_null(m_value.as_string);
} }
GVariant::GVariant(const GraphicsBitmap& value) GVariant::GVariant(const GraphicsBitmap& value)
: m_type(Type::Bitmap) : m_type(Type::Bitmap)
{ {
m_value.as_bitmap = const_cast<GraphicsBitmap*>(&value); m_value.as_bitmap = const_cast<GraphicsBitmap*>(&value);
AK::retain_if_not_null(m_value.as_bitmap); AK::ref_if_not_null(m_value.as_bitmap);
} }
GVariant::GVariant(const GIcon& value) GVariant::GVariant(const GIcon& value)
: m_type(Type::Icon) : m_type(Type::Icon)
{ {
m_value.as_icon = &const_cast<GIconImpl&>(value.impl()); m_value.as_icon = &const_cast<GIconImpl&>(value.impl());
AK::retain_if_not_null(m_value.as_icon); AK::ref_if_not_null(m_value.as_icon);
} }
GVariant::GVariant(Color color) GVariant::GVariant(Color color)
@ -133,15 +133,15 @@ void GVariant::copy_from(const GVariant& other)
break; break;
case Type::String: case Type::String:
m_value.as_string = other.m_value.as_string; m_value.as_string = other.m_value.as_string;
AK::retain_if_not_null(m_value.as_bitmap); AK::ref_if_not_null(m_value.as_bitmap);
break; break;
case Type::Bitmap: case Type::Bitmap:
m_value.as_bitmap = other.m_value.as_bitmap; m_value.as_bitmap = other.m_value.as_bitmap;
AK::retain_if_not_null(m_value.as_bitmap); AK::ref_if_not_null(m_value.as_bitmap);
break; break;
case Type::Icon: case Type::Icon:
m_value.as_icon = other.m_value.as_icon; m_value.as_icon = other.m_value.as_icon;
AK::retain_if_not_null(m_value.as_icon); AK::ref_if_not_null(m_value.as_icon);
break; break;
case Type::Color: case Type::Color:
m_value.as_color = other.m_value.as_color; m_value.as_color = other.m_value.as_color;

View file

@ -2,7 +2,7 @@
#include <AK/Retainable.h> #include <AK/Retainable.h>
class StyleValue : public Retainable<StyleValue> { class StyleValue : public RefCounted<StyleValue> {
public: public:
virtual ~StyleValue(); virtual ~StyleValue();

View file

@ -10,13 +10,13 @@ Node::~Node()
{ {
} }
void Node::retain() void Node::ref()
{ {
ASSERT(m_retain_count); ASSERT(m_retain_count);
++m_retain_count; ++m_retain_count;
} }
void Node::release() void Node::deref()
{ {
ASSERT(m_retain_count); ASSERT(m_retain_count);
if (!--m_retain_count) if (!--m_retain_count)

View file

@ -18,9 +18,9 @@ class Node {
public: public:
virtual ~Node(); virtual ~Node();
void retain(); void ref();
void release(); void deref();
int retain_count() const { return m_retain_count; } int ref_count() const { return m_retain_count; }
ParentNode* parent_node() { return m_parent_node; } ParentNode* parent_node() { return m_parent_node; }
const ParentNode* parent_node() const { return m_parent_node; } const ParentNode* parent_node() const { return m_parent_node; }

View file

@ -9,13 +9,13 @@ LayoutNode::~LayoutNode()
{ {
} }
void LayoutNode::retain() void LayoutNode::ref()
{ {
ASSERT(m_retain_count); ASSERT(m_retain_count);
++m_retain_count; ++m_retain_count;
} }
void LayoutNode::release() void LayoutNode::deref()
{ {
ASSERT(m_retain_count); ASSERT(m_retain_count);
if (!--m_retain_count) if (!--m_retain_count)

View file

@ -11,9 +11,9 @@ class LayoutNode {
public: public:
virtual ~LayoutNode(); virtual ~LayoutNode();
void retain(); void ref();
void release(); void deref();
int retain_count() const { return m_retain_count; } int ref_count() const { return m_retain_count; }
const Rect& rect() const { return m_rect; } const Rect& rect() const { return m_rect; }
Rect& rect() { return m_rect; } Rect& rect() { return m_rect; }

View file

@ -12,7 +12,7 @@ enum class WSStandardCursor {
ResizeDiagonalBLTR, ResizeDiagonalBLTR,
}; };
class WSCursor : public Retainable<WSCursor> { class WSCursor : public RefCounted<WSCursor> {
public: public:
static Retained<WSCursor> create(Retained<GraphicsBitmap>&&, const Point& hotspot); static Retained<WSCursor> create(Retained<GraphicsBitmap>&&, const Point& hotspot);
static Retained<WSCursor> create(Retained<GraphicsBitmap>&&); static Retained<WSCursor> create(Retained<GraphicsBitmap>&&);

View file

@ -4,7 +4,7 @@
#include <AK/RetainPtr.h> #include <AK/RetainPtr.h>
#include <AK/Retainable.h> #include <AK/Retainable.h>
class CharacterBitmap : public Retainable<CharacterBitmap> { class CharacterBitmap : public RefCounted<CharacterBitmap> {
public: public:
static Retained<CharacterBitmap> create_from_ascii(const char* asciiData, unsigned width, unsigned height); static Retained<CharacterBitmap> create_from_ascii(const char* asciiData, unsigned width, unsigned height);
~CharacterBitmap(); ~CharacterBitmap();

View file

@ -40,7 +40,7 @@ private:
Size m_size; Size m_size;
}; };
class Font : public Retainable<Font> { class Font : public RefCounted<Font> {
public: public:
static Font& default_font(); static Font& default_font();
static Font& default_bold_font(); static Font& default_bold_font();

View file

@ -10,7 +10,7 @@
#include <AK/StringView.h> #include <AK/StringView.h>
#include <SharedBuffer.h> #include <SharedBuffer.h>
class GraphicsBitmap : public Retainable<GraphicsBitmap> { class GraphicsBitmap : public RefCounted<GraphicsBitmap> {
public: public:
enum class Format { enum class Format {
Invalid, Invalid,