rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.git] / cinelerra-5.1 / cinelerra / garbage.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
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.
10  * 
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.
15  * 
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
19  * 
20  */
21
22 #include "bcsignals.h"
23 #include "garbage.h"
24 #include "mutex.h"
25
26 #include <string.h>
27
28 //Garbage *Garbage::garbage = 0;
29
30
31 Garbage::Garbage(const char *title)
32 {
33 //      Garbage::garbage->add_object(this);
34         users = 1;
35         deleted = 0;
36         this->title = new char[strlen(title) + 1];
37         strcpy(this->title, title);
38         lock = new Mutex("Garbage::lock", 1);
39 }
40
41 Garbage::~Garbage()
42 {
43         if(!deleted)
44                 printf("Garbage::~Garbage: title=%s users=%d was not deleted by Garbage::remove_user\n", 
45                         title, 
46                         users);
47         delete [] title;
48         delete lock;
49 }
50
51
52 void Garbage::add_user()
53 {
54         lock->lock("Garbage::add_user");
55         users++;
56         lock->unlock();
57 }
58
59 int Garbage::remove_user()
60 {
61         if(!this) return 0;
62
63 //printf("Garbage::remove_user %d lock=%p users=%d\n", __LINE__, lock, users);
64         if(users <= 0) {
65                 printf("Garbage::remove_user %d users=%d\n", __LINE__, users);
66                 return 0;
67         }
68         lock->lock("Garbage::delete_object");
69         if(--users > 0) {
70                 lock->unlock();
71                 return 1; // still has users
72         }
73         deleted = 1;
74         lock->unlock();
75         delete this; // this is now invalid.
76         return 0;
77 }
78
79
80 // void GarbageObject::remove_user()
81 // {
82 //      Garbage::garbage->lock->lock("GarbageObject::add_user");
83 //      users--;
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();
88 // }
89
90
91
92
93
94 // Garbage::Garbage()
95 // {
96 //      lock = new Mutex("Garbage::lock", 1);
97 // }
98 // 
99 // 
100 // Garbage::~Garbage()
101 // {
102 //      delete lock;
103 // }
104 // 
105 // // void Garbage::add_object(GarbageObject *ptr)
106 // // {
107 // //   lock->lock("Garbage::add_object");
108 // //   objects.append(ptr);
109 // //   lock->unlock();
110 // // }
111 // 
112 // void Garbage::delete_object(GarbageObject *ptr)
113 // {
114 //      if(!ptr) return;
115 // 
116 //      Garbage *garbage = Garbage::garbage;
117 //      garbage->lock->lock("Garbage::delete_object");
118 //      ptr->users--;
119 //      
120 //      if(ptr->users <= 0)
121 //      {
122 //              ptr->deleted = 1;
123 //              delete ptr;
124 // 
125 // // Remove expired objects here
126 // //           remove_expired();
127 //      }
128 //      garbage->lock->unlock();
129 // }
130 // 
131 // void Garbage::remove_expired()
132 // {
133 //      Garbage *garbage = Garbage::garbage;
134 //      for(int i = 0; i < garbage->objects.total; i++)
135 //      {
136 //              GarbageObject *ptr = garbage->objects.values[i];
137 //              if(ptr->users <= 0 && ptr->deleted)
138 //              {
139 // // Must remove pointer to prevent recursive deletion of the same object.
140 // // But i is still invalid.
141 //                      garbage->objects.remove_number(i);
142 // 
143 //                      delete ptr;
144 //                      i--;
145 //              }
146 //      }
147 // }
148
149
150