r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / garbage.h
blobeb1948e56b9cf913c81e30057fe4f43df8b9eae7
1 #ifndef GARBAGE_H
2 #define GARBAGE_H
5 #include "arraylist.h"
6 #include "garbage.inc"
7 #include "mutex.inc"
9 // Garbage collection
10 // The objects inherit from GarbageObject.
11 // The constructor sets users to 0 so the caller must call add_user if it
12 // wants to use it. If it doesn't intend to use it after calling the constructor,
13 // it should not call add_user.
14 // Other users of the object must call add_user to increment the user count
15 // and remove_user to decriment the user count.
16 // The object is only deleted if a call to Garbage::delete_object is made and
17 // the user count is 0.
18 // A user who is using it and wants to delete it must first call
19 // remove_user and then call Garbage::delete_object.
22 // They are deleted by calling delete_object. They get deleted at a
23 // random point later on. The objects must not change anything in their
24 // destructors.
26 // Can't make graphics elements inherit because they must be deleted
27 // when the window is locked and they change their parent pointers.
29 // Elements of link lists must first be unlinked with remove_pointer and then
30 // passed to delete_object.
32 // ArrayList objects must be deleted one at a time with delete_object.
33 // Then the pointers must be deleted with remove_all.
34 class GarbageObject
36 public:
37 GarbageObject(char *title);
38 virtual ~GarbageObject();
40 // Called when user begins to use the object.
41 void add_user();
42 // Called when user is done with the object.
43 void remove_user();
45 int users;
46 int deleted;
47 char *title;
52 class Garbage
54 public:
55 Garbage();
56 ~Garbage();
58 // Called by GarbageObject constructor
59 void add_object(GarbageObject *ptr);
61 // Called by user to delete the object.
62 // Flags the object for deletion as soon as it has no users.
63 static void delete_object(GarbageObject *ptr);
66 // Called by remove_user and delete_object
67 static void remove_expired();
68 Mutex *lock;
69 ArrayList<GarbageObject*> objects;
71 // Global garbage collector
72 static Garbage *garbage;
77 #endif