Squash  0.7.0
object.h
1 /* Copyright (c) 2013 The Squash Authors
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use, copy,
7  * modify, merge, publish, distribute, sublicense, and/or sell copies
8  * of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  * Evan Nemerson <evan@nemerson.com>
25  */
26 
27 #ifndef SQUASH_OBJECT_H
28 #define SQUASH_OBJECT_H
29 
30 #if !defined (SQUASH_H_INSIDE) && !defined (SQUASH_COMPILATION)
31 #error "Only <squash/squash.h> can be included directly."
32 #endif
33 
34 #include <stdbool.h>
35 
36 SQUASH_BEGIN_DECLS
37 
38 SQUASH_API void* squash_object_ref (void* obj);
39 SQUASH_API void* squash_object_unref (void* obj);
40 SQUASH_API unsigned int squash_object_get_ref_count (void* obj);
41 SQUASH_API void* squash_object_ref_sink (void* obj);
42 
43 typedef void (*SquashDestroyNotify) (void* data);
44 
45 struct _SquashObject {
46  volatile unsigned int ref_count;
47  volatile bool is_floating;
49 };
50 
51 SQUASH_API void squash_object_init (void* obj, bool is_floating, SquashDestroyNotify destroy_notify);
52 SQUASH_API void squash_object_destroy (void* obj);
53 
54 SQUASH_END_DECLS
55 
56 #endif /* SQUASH_OBJECT_H */
SquashDestroyNotify destroy_notify
Function to call when the reference count reaches 0.
Definition: object.h:48
void(* SquashDestroyNotify)(void *data)
Callback to be invoked when information data is no longer needed.
Definition: object.h:43
SQUASH_API void * squash_object_ref_sink(void *obj)
Sink a floating reference if one exists.
Definition: object.c:237
volatile bool is_floating
Whether or not the object has a floating reference.
Definition: object.h:47
SQUASH_API void * squash_object_unref(void *obj)
Decrement the reference count on an object.
Definition: object.c:255
volatile unsigned int ref_count
The reference count.
Definition: object.h:46
SQUASH_API unsigned int squash_object_get_ref_count(void *obj)
Get the current reference count of an object.
Definition: object.c:280
SQUASH_BEGIN_DECLS SQUASH_API void * squash_object_ref(void *obj)
Increment the reference count on an object.
Definition: object.c:206
Reference-counting base class for other types.
Definition: object.h:45
SQUASH_API void squash_object_destroy(void *obj)
Destroy an object.
Definition: object.c:325
SQUASH_API void squash_object_init(void *obj, bool is_floating, SquashDestroyNotify destroy_notify)
Initialize a new object.
Definition: object.c:302