Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
gc.cpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #include "gc.hpp"
12 
13 QList<Huggle::Collectable*> Huggle::GC::list;
14 QMutex Huggle::GC::Lock(QMutex::Recursive);
15 
17 {
18  Huggle::GC::Lock.lock();
19  int x=0;
20  while(x < GC::list.count())
21  {
22  Collectable *q = GC::list.at(x);
23  q->Lock();
24  if (!q->IsManaged())
25  {
26  GC::list.removeAt(x);
27  delete q;
28  continue;
29  }
30  if (!q->SafeDelete())
31  {
32  q->Unlock();
33  x++;
34  }
35  }
36  Huggle::GC::Lock.unlock();
37 }
bool IsManaged()
IsManaged Managed class is deleted by GC and must not be deleted by hand.
virtual bool SafeDelete()
Use this if you are not sure if you can delete this object in this moment.
Definition: collectable.cpp:38
Base for all items that are supposed to be collected by garbage collector.
Definition: collectable.hpp:34
void Unlock()
Unlock this object for deletion by other threads.
static void DeleteOld()
Function that walks through the list and delete these that can be deleted.
Definition: gc.cpp:16
static QMutex Lock
QMutex that is used to lock the GC::list object.
Definition: gc.hpp:47
void Lock()
Lock this object so that other threads can&#39;t change consumers or modify its properties.
static QList< Collectable * > list
List of all managed queries that qgc keeps track of.
Definition: gc.hpp:42