From 3de5439579c58d833b3e23768ed2ecb4a16e9d3c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 23 Jan 2020 15:14:21 +0100 Subject: [PATCH] AK: Let's call decrementing reference counts "unref" instead of "deref" It always bothered me that we're using the overloaded "dereference" term for this. Let's call it "unreference" instead. :^) --- AK/JsonValue.cpp | 2 +- AK/NonnullRefPtr.h | 6 +++--- AK/RefCounted.h | 2 +- AK/RefPtr.h | 2 +- AK/Tests/TestNonnullRefPtr.cpp | 2 +- AK/Tests/TestRefPtr.cpp | 2 +- Applications/SystemMonitor/main.cpp | 12 ++++++------ Documentation/SmartPointers.md | 2 +- Kernel/VM/PhysicalPage.h | 2 +- Libraries/LibGUI/GVariant.cpp | 6 +++--- Libraries/LibHTML/TreeNode.h | 6 +++--- Libraries/LibThread/BackgroundAction.h | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index ff6f8b5ea9..d46d5a4f92 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -176,7 +176,7 @@ void JsonValue::clear() { switch (m_type) { case Type::String: - m_value.as_string->deref(); + m_value.as_string->unref(); break; case Type::Object: delete m_value.as_object; diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index a30a3c96bc..426c4f5dca 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -46,10 +46,10 @@ inline void ref_if_not_null(T* ptr) } template -inline void deref_if_not_null(T* ptr) +inline void unref_if_not_null(T* ptr) { if (ptr) - ptr->deref(); + ptr->unref(); } template @@ -103,7 +103,7 @@ public: } ~NonnullRefPtr() { - deref_if_not_null(m_ptr); + unref_if_not_null(m_ptr); m_ptr = nullptr; #ifdef SANITIZE_PTRS if constexpr (sizeof(T*) == 8) diff --git a/AK/RefCounted.h b/AK/RefCounted.h index 17241f06ea..7926de7321 100644 --- a/AK/RefCounted.h +++ b/AK/RefCounted.h @@ -87,7 +87,7 @@ protected: template class RefCounted : public RefCountedBase { public: - void deref() + void unref() { deref_base(); if (m_ref_count == 0) { diff --git a/AK/RefPtr.h b/AK/RefPtr.h index ae297576b2..b942cc0b78 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -198,7 +198,7 @@ public: void clear() { - deref_if_not_null(m_ptr); + unref_if_not_null(m_ptr); m_ptr = nullptr; } diff --git a/AK/Tests/TestNonnullRefPtr.cpp b/AK/Tests/TestNonnullRefPtr.cpp index 1cd183c0e3..77d9fe777a 100644 --- a/AK/Tests/TestNonnullRefPtr.cpp +++ b/AK/Tests/TestNonnullRefPtr.cpp @@ -40,7 +40,7 @@ TEST_CASE(basics) EXPECT_EQ(object->ref_count(), 1); object->ref(); EXPECT_EQ(object->ref_count(), 2); - object->deref(); + object->unref(); EXPECT_EQ(object->ref_count(), 1); { diff --git a/AK/Tests/TestRefPtr.cpp b/AK/Tests/TestRefPtr.cpp index 8aafe0547b..633af6f70f 100644 --- a/AK/Tests/TestRefPtr.cpp +++ b/AK/Tests/TestRefPtr.cpp @@ -40,7 +40,7 @@ TEST_CASE(basics) EXPECT_EQ(object->ref_count(), 1); object->ref(); EXPECT_EQ(object->ref_count(), 2); - object->deref(); + object->unref(); EXPECT_EQ(object->ref_count(), 1); { diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index b1679acad4..578e0b47f1 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -105,7 +105,12 @@ int main(int argc, char** argv) unveil(nullptr, nullptr); + auto window = GWindow::construct(); + window->set_title("System Monitor"); + window->set_rect(20, 200, 680, 400); + auto keeper = GWidget::construct(); + window->set_main_widget(keeper); keeper->set_layout(make(Orientation::Vertical)); keeper->set_fill_with_background_color(true); keeper->layout()->set_margins({ 4, 4, 4, 4 }); @@ -140,7 +145,7 @@ int main(int argc, char** argv) process_table_view->refresh(); if (auto* memory_stats_widget = MemoryStatsWidget::the()) memory_stats_widget->refresh(); - }); + }, window); auto kill_action = GAction::create("Kill process", { Mod_Ctrl, Key_K }, GraphicsBitmap::load_from_file("/res/icons/kill16.png"), [process_table_view](const GAction&) { pid_t pid = process_table_view->selected_pid(); @@ -164,11 +169,6 @@ int main(int argc, char** argv) toolbar->add_action(stop_action); toolbar->add_action(continue_action); - auto window = GWindow::construct(); - window->set_title("System Monitor"); - window->set_rect(20, 200, 680, 400); - window->set_main_widget(keeper); - auto menubar = make(); auto app_menu = GMenu::construct("System Monitor"); app_menu->add_action(GCommonActions::make_quit_action([](auto&) { diff --git a/Documentation/SmartPointers.md b/Documentation/SmartPointers.md index 29104ecddf..8410e6cdfa 100644 --- a/Documentation/SmartPointers.md +++ b/Documentation/SmartPointers.md @@ -35,7 +35,7 @@ Shared ownership is implemented via reference counting. NonnullRefPtr is a special variant of RefPtr with one additional property: it cannot be null. NonnullRefPtr is suitable as a return type from functions that are guaranteed to never return null, and as an argument type where the argument may not be null. In other words, if RefPtr is "\*", then NonnullRefPtr is "&". -Objects can only be held by RefPtr if they meet certain criteria. Specifically, they need to implement the functions `ref()` and `deref()`. +Objects can only be held by RefPtr if they meet certain criteria. Specifically, they need to implement the functions `ref()` and `unref()`. To make a class T reference counted, you can simply make it inherit from RefCounted. This will add all the necessary pieces to T. diff --git a/Kernel/VM/PhysicalPage.h b/Kernel/VM/PhysicalPage.h index 66c714795a..2d916de1df 100644 --- a/Kernel/VM/PhysicalPage.h +++ b/Kernel/VM/PhysicalPage.h @@ -46,7 +46,7 @@ public: ++m_retain_count; } - void deref() + void unref() { ASSERT(m_retain_count); if (!--m_retain_count) { diff --git a/Libraries/LibGUI/GVariant.cpp b/Libraries/LibGUI/GVariant.cpp index 94f144636d..cfe43a70ad 100644 --- a/Libraries/LibGUI/GVariant.cpp +++ b/Libraries/LibGUI/GVariant.cpp @@ -61,13 +61,13 @@ void GVariant::clear() { switch (m_type) { case Type::String: - AK::deref_if_not_null(m_value.as_string); + AK::unref_if_not_null(m_value.as_string); break; case Type::Bitmap: - AK::deref_if_not_null(m_value.as_bitmap); + AK::unref_if_not_null(m_value.as_bitmap); break; case Type::Icon: - AK::deref_if_not_null(m_value.as_icon); + AK::unref_if_not_null(m_value.as_icon); break; default: break; diff --git a/Libraries/LibHTML/TreeNode.h b/Libraries/LibHTML/TreeNode.h index bf2e567edf..f0550b9b21 100644 --- a/Libraries/LibHTML/TreeNode.h +++ b/Libraries/LibHTML/TreeNode.h @@ -48,7 +48,7 @@ public: ++m_ref_count; } - void deref() + void unref() { ASSERT(m_ref_count); if (!--m_ref_count) { @@ -60,7 +60,7 @@ public: for (auto* child = m_first_child; child; child = next_child) { next_child = child->m_next_sibling; child->m_parent = nullptr; - child->deref(); + child->unref(); } delete static_cast(this); } @@ -221,7 +221,7 @@ inline NonnullRefPtr TreeNode::remove_child(NonnullRefPtr node, bool ca if (call_removed_from) node->removed_from(static_cast(*this)); - node->deref(); + node->unref(); return node; } diff --git a/Libraries/LibThread/BackgroundAction.h b/Libraries/LibThread/BackgroundAction.h index c5f3a6de62..076e3d3bff 100644 --- a/Libraries/LibThread/BackgroundAction.h +++ b/Libraries/LibThread/BackgroundAction.h @@ -81,11 +81,11 @@ private: if (m_on_complete) { CEventLoop::main().post_event(*this, make([this](CObject&) { m_on_complete(m_result.release_value()); - this->deref(); + this->unref(); })); CEventLoop::main().wake(); } else - this->deref(); + this->unref(); }); }