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()
61 if(!(void *)this) return 0;
63 //printf("Garbage::remove_user %d lock=%p users=%d\n", __LINE__, lock, users);
65 printf("Garbage::remove_user %d users=%d\n", __LINE__, users);
68 lock->lock("Garbage::delete_object");
71 return 1; // still has users
75 delete this; // this is now invalid.
80 // void GarbageObject::remove_user()
82 // Garbage::garbage->lock->lock("GarbageObject::add_user");
84 // if(users < 0) printf("GarbageObject::remove_user: users=%d Should be >= 0.\n", users);
85 // Garbage::garbage->remove_expired();
86 // // *this is now invalid
87 // Garbage::garbage->lock->unlock();
96 // lock = new Mutex("Garbage::lock", 1);
100 // Garbage::~Garbage()
105 // // void Garbage::add_object(GarbageObject *ptr)
107 // // lock->lock("Garbage::add_object");
108 // // objects.append(ptr);
109 // // lock->unlock();
112 // void Garbage::delete_object(GarbageObject *ptr)
116 // Garbage *garbage = Garbage::garbage;
117 // garbage->lock->lock("Garbage::delete_object");
120 // if(ptr->users <= 0)
125 // // Remove expired objects here
126 // // remove_expired();
128 // garbage->lock->unlock();
131 // void Garbage::remove_expired()
133 // Garbage *garbage = Garbage::garbage;
134 // for(int i = 0; i < garbage->objects.total; i++)
136 // GarbageObject *ptr = garbage->objects.values[i];
137 // if(ptr->users <= 0 && ptr->deleted)
139 // // Must remove pointer to prevent recursive deletion of the same object.
140 // // But i is still invalid.
141 // garbage->objects.remove_number(i);