Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-06 08:41:18

0001 /* grcbox.h: Reference counted data
0002  *
0003  * Copyright 2018  Emmanuele Bassi
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-or-later
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Lesser General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2.1 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #pragma once
0022 
0023 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
0024 #error "Only <glib.h> can be included directly."
0025 #endif
0026 
0027 #include <glib/gmem.h>
0028 #include <glib/glib-typeof.h>
0029 
0030 G_BEGIN_DECLS
0031 
0032 GLIB_AVAILABLE_IN_2_58
0033 gpointer        g_rc_box_alloc                  (gsize           block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
0034 GLIB_AVAILABLE_IN_2_58
0035 gpointer        g_rc_box_alloc0                 (gsize           block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
0036 GLIB_AVAILABLE_IN_2_58
0037 gpointer        g_rc_box_dup                    (gsize           block_size,
0038                                                  gconstpointer   mem_block) G_GNUC_ALLOC_SIZE(1);
0039 GLIB_AVAILABLE_IN_2_58
0040 gpointer        g_rc_box_acquire                (gpointer        mem_block);
0041 GLIB_AVAILABLE_IN_2_58
0042 void            g_rc_box_release                (gpointer        mem_block);
0043 GLIB_AVAILABLE_IN_2_58
0044 void            g_rc_box_release_full           (gpointer        mem_block,
0045                                                  GDestroyNotify  clear_func);
0046 
0047 GLIB_AVAILABLE_IN_2_58
0048 gsize           g_rc_box_get_size               (gpointer        mem_block);
0049 
0050 GLIB_AVAILABLE_IN_2_58
0051 gpointer        g_atomic_rc_box_alloc           (gsize           block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
0052 GLIB_AVAILABLE_IN_2_58
0053 gpointer        g_atomic_rc_box_alloc0          (gsize           block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
0054 GLIB_AVAILABLE_IN_2_58
0055 gpointer        g_atomic_rc_box_dup             (gsize           block_size,
0056                                                  gconstpointer   mem_block) G_GNUC_ALLOC_SIZE(1);
0057 GLIB_AVAILABLE_IN_2_58
0058 gpointer        g_atomic_rc_box_acquire         (gpointer        mem_block);
0059 GLIB_AVAILABLE_IN_2_58
0060 void            g_atomic_rc_box_release         (gpointer        mem_block);
0061 GLIB_AVAILABLE_IN_2_58
0062 void            g_atomic_rc_box_release_full    (gpointer        mem_block,
0063                                                  GDestroyNotify  clear_func);
0064 
0065 GLIB_AVAILABLE_IN_2_58
0066 gsize           g_atomic_rc_box_get_size        (gpointer        mem_block);
0067 
0068 #define g_rc_box_new(type) \
0069   ((type *) g_rc_box_alloc (sizeof (type)))
0070 #define g_rc_box_new0(type) \
0071   ((type *) g_rc_box_alloc0 (sizeof (type)))
0072 #define g_atomic_rc_box_new(type) \
0073   ((type *) g_atomic_rc_box_alloc (sizeof (type)))
0074 #define g_atomic_rc_box_new0(type) \
0075   ((type *) g_atomic_rc_box_alloc0 (sizeof (type)))
0076 
0077 #if defined(glib_typeof)
0078 /* Type check to avoid assigning references to different types */
0079 #define g_rc_box_acquire(mem_block) \
0080   ((glib_typeof (mem_block)) (g_rc_box_acquire) (mem_block))
0081 #define g_atomic_rc_box_acquire(mem_block) \
0082   ((glib_typeof (mem_block)) (g_atomic_rc_box_acquire) (mem_block))
0083 
0084 /* Type check to avoid duplicating data to different types */
0085 #define g_rc_box_dup(block_size, mem_block) \
0086   ((glib_typeof (mem_block)) (g_rc_box_dup) (block_size, mem_block))
0087 #define g_atomic_rc_box_dup(block_size, mem_block) \
0088   ((glib_typeof (mem_block)) (g_atomic_rc_box_dup) (block_size, mem_block))
0089 #endif
0090 
0091 G_END_DECLS