1 /* managed objects ... things like Imageinfo which are lifetime managed by
2  * both the GC and by pointers from C: we need to both mark/sweep and refcount
3  *
4  * abstract class: Managedgvalue, Imageinfo, etc. build off this
5  */
6 
7 /*
8 
9     Copyright (C) 1991-2003 The National Gallery
10 
11     This program is free software; you can redistribute it and/or modify
12     it under the terms of the GNU General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15 
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU General Public License for more details.
20 
21     You should have received a copy of the GNU General Public License along
22     with this program; if not, write to the Free Software Foundation, Inc.,
23     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 
25  */
26 
27 /*
28 
29     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
30 
31  */
32 
33 #define TYPE_MANAGED (managed_get_type())
34 #define MANAGED( obj ) \
35 	(G_TYPE_CHECK_INSTANCE_CAST( (obj), TYPE_MANAGED, Managed ))
36 #define MANAGED_CLASS( klass ) \
37 	(G_TYPE_CHECK_CLASS_CAST( (klass), TYPE_MANAGED, ManagedClass))
38 #define IS_MANAGED( obj ) \
39 	(G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_MANAGED ))
40 #define IS_MANAGED_CLASS( klass ) \
41 	(G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_MANAGED ))
42 #define MANAGED_GET_CLASS( obj ) \
43 	(G_TYPE_INSTANCE_GET_CLASS( (obj), TYPE_MANAGED, ManagedClass ))
44 
45 #define MANAGED_UNREF( X ) { \
46 	if( X ) { \
47 		managed_destroy_nonheap( MANAGED( X ) ); \
48 		X = NULL; \
49 	} \
50 }
51 #define MANAGED_REF( X ) managed_dup_nonheap( MANAGED( X ) )
52 
53 struct _Managed {
54 	iContainer parent_object;
55 
56 	/* Can't just set ->heap = NULL to mean unattached, our subclasses
57 	 * rely on ->heap being valid even during dispose.
58 	 */
59 
60 	Heap *heap;		/* Heap we are attached to */
61 	gboolean attached;	/* If we are attached to the heap */
62 
63 	gboolean marked;	/* For mark-sweep */
64 	int count;		/* Number of non-heap pointers to us */
65 	gboolean zombie;	/* Unreffed, but being kept alive */
66 	double time;		/* When we became a zombie */
67 
68 	/*
69 
70 	   	FIXME ... This should go with vips8: it does dependency
71 		tracking for us.
72 
73 	 */
74 	GSList *sub;		/* Sub-objects ... mark these if we mark this */
75 
76 	/* Set by subclasses as part of construction.
77 	 */
78 	guint hash;
79 };
80 
81 typedef struct _ManagedClass {
82 	iContainerClass parent_class;
83 
84 	/* How long after zombiefying before we unref.
85 	 */
86 	double keepalive;
87 } ManagedClass;
88 
89 void managed_check_all_destroyed( void );
90 
91 void managed_link_heap( Managed *managed, Heap *heap );
92 
93 void managed_destroy_heap( Managed *managed );
94 void *managed_destroy_nonheap( Managed *managed );
95 void managed_dup_nonheap( Managed *managed );
96 
97 void *managed_sub_remove( Managed *in, Managed *managed );
98 void managed_sub_add( Managed *managed, Managed *in );
99 void managed_sub_add_all( Managed *out, int nin, Managed **in );
100 
101 GType managed_get_type( void );
102 
103 void managed_clear( Heap *heap );
104 void managed_mark( Managed *managed );
105 gboolean managed_free_unused( Heap *heap );
106