Imported Upstream version 2.74.3
[platform/upstream/glib.git] / glib / grcboxprivate.h
1 /* grcboxprivate.h: Reference counted data
2  *
3  * Copyright 2018  Emmanuele Bassi
4  *
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #pragma once
22
23 #include "gtypes.h"
24 #include "grcbox.h"
25
26 G_BEGIN_DECLS
27
28 typedef struct {
29   grefcount ref_count;
30
31   gsize mem_size;
32   gsize private_offset;
33
34 #ifndef G_DISABLE_ASSERT
35   /* A "magic" number, used to perform additional integrity
36    * checks on the allocated data
37    */
38   guint32 magic;
39 #endif
40 } GRcBox;
41
42 typedef struct {
43   gatomicrefcount ref_count;
44
45   gsize mem_size;
46   gsize private_offset;
47
48 #ifndef G_DISABLE_ASSERT
49   guint32 magic;
50 #endif
51 } GArcBox;
52
53 #define G_BOX_MAGIC             0x44ae2bf0
54
55 /* Keep the two refcounted boxes identical in size */
56 G_STATIC_ASSERT (sizeof (GRcBox) == sizeof (GArcBox));
57
58 /* This is the default alignment we use when allocating the
59  * refcounted memory blocks; it's similar to the alignment
60  * guaranteed by the malloc() in GNU's libc and by the GSlice
61  * allocator
62  */
63 #define STRUCT_ALIGNMENT (2 * sizeof (gsize))
64
65 #define G_RC_BOX_SIZE sizeof (GRcBox)
66 #define G_ARC_BOX_SIZE sizeof (GArcBox)
67
68 gpointer        g_rc_box_alloc_full     (gsize    block_size,
69                                          gsize    alignment,
70                                          gboolean atomic,
71                                          gboolean clear);
72
73 G_END_DECLS