diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index ff6f8b5ea9dcc916f317c4b9ab0ab1a95967e822..d46d5a4f926170578da837b27527ad6d911012f2 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 a30a3c96bc15aa470e9db7dad2f4e735a84dfa92..426c4f5dcac90ed8ba4ddb35aeebaf9484a671de 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 17241f06eafc3d82bdfd2f15ba6da13d2b054471..7926de7321172389412d145fa7a0400977fb48df 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 ae297576b28aaa9d50c41fce031f2887d8e20e6e..b942cc0b78fa20ecd3e984e6a36fb19e6946b1e0 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 1cd183c0e3f440ac40f507330597095f52da9d10..77d9fe777a55166bba0c32a79bfdbc8a4e363587 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 8aafe0547b856f7fbb5848688c636643cc06ca2f..633af6f70f570ef3bd2932f196c0fb394b9b225a 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 b1679acad441aa53113357d26b6910bfd3b50a7f..578e0b47f11fe0a469826cacc625842724782dd8 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 29104ecddfd9aea00ed0b66521a74ed82e124399..8410e6cdfaf6e34aaea340b87871d52062a872e1 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 66c714795a89d780691efc2d0f27e1535014241d..2d916de1dfeb9c5e9f67bb250f9f6a77e1f681db 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 94f144636dcdcb702715c5df37e9e4753f88b97c..cfe43a70adfbc230d8a5bf1bf334bbcec0d33267 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 bf2e567edf5c335598712640cc7b239fef3f2973..f0550b9b21eecb339916462a336c99d78ecc37b8 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 c5f3a6de62e732ac3629a3980b0d3d8ced7c8ff8..076e3d3bff77c9f9f50ec90df6ac6f1ca2bdb231 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(); }); }