4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcsignals.h"
28 //Garbage *Garbage::garbage = 0;
31 Garbage::Garbage(const char *title)
33 // Garbage::garbage->add_object(this);
36 this->title = new char[strlen(title) + 1];
37 strcpy(this->title, title);
38 lock = new Mutex("Garbage::lock", 1);
44 printf("Garbage::~Garbage: title=%s users=%d was not deleted by Garbage::remove_user\n",
52 void Garbage::add_user()
54 lock->lock("Garbage::add_user");
59 int Garbage::remove_user()
64 //printf("Garbage::remove_user %d lock=%p users=%d\n", __LINE__, lock, users);
66 printf("Garbage::remove_user %d users=%d\n", __LINE__, users);
69 lock->lock("Garbage::delete_object");
72 return 1; // still has users
76 delete this; // this is now invalid.
81 // void GarbageObject::remove_user()
83 // Garbage::garbage->lock->lock("GarbageObject::add_user");
85 // if(users < 0) printf("GarbageObject::remove_user: users=%d Should be >= 0.\n", users);
86 // Garbage::garbage->remove_expired();
87 // // *this is now invalid
88 // Garbage::garbage->lock->unlock();
97 // lock = new Mutex("Garbage::lock", 1);
101 // Garbage::~Garbage()
106 // // void Garbage::add_object(GarbageObject *ptr)
108 // // lock->lock("Garbage::add_object");
109 // // objects.append(ptr);
110 // // lock->unlock();
113 // void Garbage::delete_object(GarbageObject *ptr)
117 // Garbage *garbage = Garbage::garbage;
118 // garbage->lock->lock("Garbage::delete_object");
121 // if(ptr->users <= 0)
126 // // Remove expired objects here
127 // // remove_expired();
129 // garbage->lock->unlock();
132 // void Garbage::remove_expired()
134 // Garbage *garbage = Garbage::garbage;
135 // for(int i = 0; i < garbage->objects.total; i++)
137 // GarbageObject *ptr = garbage->objects.values[i];
138 // if(ptr->users <= 0 && ptr->deleted)
140 // // Must remove pointer to prevent recursive deletion of the same object.
141 // // But i is still invalid.
142 // garbage->objects.remove_number(i);