src/GlobalRoots.cpp
author David Anderson <dvander@alliedmods.net>
Sun Nov 18 22:18:23 2012 -0800 (2012-11-18)
changeset 219 99e534728b76
parent 195 c1ba166f3fc4
child 251 ca99a81745fe
permissions -rw-r--r--
Moved another test case.
     1 /* vim: set ts=4 sw=4 tw=99 et:
     2  *
     3  * Copyright (C) 2004-2012 David Anderson
     4  *
     5  * This file is part of SourcePawn.
     6  *
     7  * SourcePawn is free software: you can redistribute it and/or modify it under
     8  * the terms of the GNU General Public License as published by the Free
     9  * Software Foundation, either version 3 of the License, or (at your option)
    10  * any later version.
    11  * 
    12  * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License along with
    17  * SourcePawn. If not, see http://www.gnu.org/licenses/.
    18  */
    19 #include "GlobalRoots.h"
    20 #include "Zone.h"
    21 #include "Spaces-inl.h"
    22 #include "Heap-inl.h"
    23 
    24 using namespace ke;
    25 
    26 GlobalRoots::GlobalRoots(Zone *zone)
    27   : zone_(zone)
    28 {
    29 }
    30 
    31 GlobalRoots::~GlobalRoots()
    32 {
    33     InlineList<HeapRoot>::iterator iter = roots_.begin();
    34     while (iter != roots_.end()) {
    35 		HeapRoot *root = *iter;
    36         iter = roots_.erase(iter);
    37 		delete root;
    38     }
    39 }
    40 
    41 bool
    42 GlobalRoots::initialize()
    43 {
    44     return true;
    45 }
    46 
    47 void
    48 GlobalRoots::accept(VirtualObjectVisitor *visitor)
    49 {
    50     for (InlineList<HeapRoot>::iterator iter = roots_.begin(); iter != roots_.end(); iter++)
    51         visitor->visit(&iter->obj);
    52 }
    53 
    54 HeapRoot *
    55 GlobalRoots::create()
    56 {
    57     HeapRoot *root = new HeapRoot();
    58     if (!root) {
    59         ZONE()->reportOutOfMemory();
    60         return NULL;
    61     }
    62 
    63     root->obj = NULL;
    64 
    65     roots_.append(root);
    66     return root;
    67 }
    68 
    69 void
    70 GlobalRoots::destroy(HeapRoot *root)
    71 {
    72     roots_.remove(root);
    73     delete root;
    74 }