Skip to content

Truly independent web browser

994 B
Raw Blame
/*
 * Copyright (c) 2021, Andreas Kling <[email protected]>
 * Copyright (c) 2022, Linus Groh <[email protected]>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibGC/Heap.h>
#include <LibGC/HeapAccess.h>
#include <LibGC/RootVector.h>

namespace GC {

RootVectorBase::RootVectorBase()
    : RootVectorBase(Heap::the())
{
}

RootVectorBase::RootVectorBase(Heap& heap)
    : m_heap(&heap)
{
    ASSERT(!heap_access_is_forbidden_on_this_thread());
    ASSERT(m_heap->is_on_owner_thread());
    m_heap->did_create_root_vector({}, *this);
}

RootVectorBase::~RootVectorBase()
{
    ASSERT(!heap_access_is_forbidden_on_this_thread());
    ASSERT(m_heap->is_on_owner_thread());
    m_heap->did_destroy_root_vector({}, *this);
}

void RootVectorBase::assign_heap(Heap* heap)
{
    if (m_heap == heap)
        return;

    m_heap = heap;

    // NOTE: IntrusiveList will remove this RootVectorBase from the old heap it was part of.
    m_heap->did_create_root_vector({}, *this);
}

}