Improve the RcBox and ArcBox documentation
[glib.git] / glib / grcbox.h
blob3f364d330a7cef69082ad6164d9942d5c3fbe1b8
1 /* grcbox.h: Reference counted data
3 * Copyright 2018 Emmanuele Bassi
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #pragma once
21 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
22 #error "Only <glib.h> can be included directly."
23 #endif
25 #include <glib/gmem.h>
27 G_BEGIN_DECLS
29 GLIB_AVAILABLE_IN_2_58
30 gpointer g_rc_box_alloc (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
31 GLIB_AVAILABLE_IN_2_58
32 gpointer g_rc_box_alloc0 (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
33 GLIB_AVAILABLE_IN_2_58
34 gpointer g_rc_box_dup (gsize block_size,
35 gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
36 GLIB_AVAILABLE_IN_2_58
37 gpointer g_rc_box_acquire (gpointer mem_block);
38 GLIB_AVAILABLE_IN_2_58
39 void g_rc_box_release (gpointer mem_block);
40 GLIB_AVAILABLE_IN_2_58
41 void g_rc_box_release_full (gpointer mem_block,
42 GDestroyNotify clear_func);
44 GLIB_AVAILABLE_IN_2_58
45 gpointer g_arc_box_alloc (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
46 GLIB_AVAILABLE_IN_2_58
47 gpointer g_arc_box_alloc0 (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
48 GLIB_AVAILABLE_IN_2_58
49 gpointer g_arc_box_dup (gsize block_size,
50 gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
51 GLIB_AVAILABLE_IN_2_58
52 gpointer g_arc_box_acquire (gpointer mem_block);
53 GLIB_AVAILABLE_IN_2_58
54 void g_arc_box_release (gpointer mem_block);
55 GLIB_AVAILABLE_IN_2_58
56 void g_arc_box_release_full (gpointer mem_block,
57 GDestroyNotify clear_func);
59 #define g_rc_box_new(type) \
60 ((type *) g_rc_box_alloc (sizeof (type)))
61 #define g_rc_box_new0(type) \
62 ((type *) g_rc_box_alloc0 (sizeof (type)))
63 #define g_arc_box_new(type) \
64 ((type *) g_arc_box_alloc (sizeof (type)))
65 #define g_arc_box_new0(type) \
66 ((type *) g_arc_box_alloc0 (sizeof (type)))
68 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(_cplusplus)
69 /* Type check to avoid assigning references to different types */
70 # define g_rc_box_acquire(mem_block) \
71 ((__typeof__(mem_block)) (g_rc_box_acquire) (mem_block))
72 # define g_arc_box_acquire(mem_block) \
73 ((__typeof__(mem_block)) (g_arc_box_acquire) (mem_block))
75 /* Type check to avoid duplicating data to different types */
76 # define g_rc_box_dup(block_size,mem_block) \
77 ((__typeof__(mem_block)) (g_rc_box_dup) (block_size,mem_block))
78 # define g_arc_box_dup(block_size,mem_block) \
79 ((__typeof__(mem_block)) (g_arc_box_dup) (block_size,mem_block))
80 #endif
82 G_END_DECLS