hb-object-private.hh revision cf26510dbbd8d38486e6ba423800db6427ade332
1f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod/*
22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2007  Chris Wilson
32409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2009,2010  Red Hat, Inc.
42409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2011  Google, Inc.
5f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod *
6c755cb3e3ac55156d0d2ec05adea7a650b97cc41Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
7f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod *
8f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * Permission is hereby granted, without written agreement and without
9f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
10f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * software and its documentation for any purpose, provided that the
11f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
12f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * all copies of this software.
13f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod *
14f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * DAMAGE.
19f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod *
20f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
23f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod *
26f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * Contributor(s):
27f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod *	Chris Wilson <chris@chris-wilson.co.uk>
2835a7383c6138fd705560f0d4bb30659cbd1ab64cBehdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
292409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Google Author(s): Behdad Esfahbod
30f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod */
31f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod
32c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#ifndef HB_OBJECT_PRIVATE_HH
33c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#define HB_OBJECT_PRIVATE_HH
34f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod
35c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#include "hb-private.hh"
3623c86aa0009324433e78fcd0c47f2c0ff14b1949Behdad Esfahbod
3745bfa99034512e886d75b1d45a5a649647f4711fBehdad Esfahbod#include "hb-mutex-private.hh"
3845bfa99034512e886d75b1d45a5a649647f4711fBehdad Esfahbod
39799b3c375ad0e1293fd37a0e3a0d422a3166dcd8Behdad Esfahbod
40799b3c375ad0e1293fd37a0e3a0d422a3166dcd8Behdad Esfahbod
41863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod/* Debug */
42863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod
43863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod#ifndef HB_DEBUG_OBJECT
4411e3ec444a85fc72541823c2e98cc92c4ceb19afBehdad Esfahbod#define HB_DEBUG_OBJECT (HB_DEBUG+0)
45863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod#endif
46863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod
47863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod
4856eb5ad6f94c32189ad219438db9a18683ca6846Behdad Esfahbod/* atomic_int */
492000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
502000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod/* We need external help for these */
512000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
52bd7ff1dec5b92ee59fa060e793f88499adcd8c11Behdad Esfahbod#if !defined(HB_NO_MT) && defined(HAVE_GLIB)
532000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
542000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod#include <glib.h>
552000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbodtypedef volatile int hb_atomic_int_t;
56d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#if GLIB_CHECK_VERSION(2,29,5)
57d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#define hb_atomic_int_add(AI, V)	g_atomic_int_add (&(AI), V)
58d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#else
59d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#define hb_atomic_int_add(AI, V)	g_atomic_int_exchange_and_add (&(AI), V)
60d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#endif
61d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#define hb_atomic_int_get(AI)		g_atomic_int_get (&(AI))
622000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
632000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
64bd7ff1dec5b92ee59fa060e793f88499adcd8c11Behdad Esfahbod#elif !defined(HB_NO_MT) && defined(_MSC_VER) && _MSC_VER >= 1600
652000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
662000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod#include <intrin.h>
672000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbodtypedef long hb_atomic_int_t;
68d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#define hb_atomic_int_add(AI, V)	_InterlockedExchangeAdd (&(AI), V)
69d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#define hb_atomic_int_get(AI)		(_ReadBarrier (), (AI))
702000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
71a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod#elif !defined(HB_NO_MT) && defined(__APPLE__)
72a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod
73a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod#include <libkern/OSAtomic.h>
74a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbodtypedef int32_t hb_atomic_int_t;
75bc71ad4973842f25216b48842a46d6c9cbce6aa3Behdad Esfahbod#define hb_atomic_int_add(AI, V)	(OSAtomicAdd32Barrier((V), &(AI)), (AI) - (V))
76a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod#define hb_atomic_int_get(AI)		OSAtomicAdd32Barrier(0, &(AI))
772000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
782000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod#else
792000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
80bd7ff1dec5b92ee59fa060e793f88499adcd8c11Behdad Esfahbod#define HB_ATOMIC_INT_NIL 1
812000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
822000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbodtypedef volatile int hb_atomic_int_t;
83d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#define hb_atomic_int_add(AI, V)	((AI) += (V), (AI) - (V))
84d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod#define hb_atomic_int_get(AI)		(AI)
852000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
862000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod#endif
872000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
882000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
892000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
902000179487b49e0d504ec127450dc6fcb5568cecBehdad Esfahbod
91852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod/* reference_count */
9229c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
93852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbodtypedef struct {
94852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod  hb_atomic_int_t ref_count;
9529c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
96852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1)
97852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE}
9829c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
99852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod  inline void init (int v) { ref_count = v; /* non-atomic is fine */ }
100d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod  inline int inc (void) { return hb_atomic_int_add (ref_count,  1); }
101d5476a30a10da5e54783c8dbf04340225a9a00d7Behdad Esfahbod  inline int dec (void) { return hb_atomic_int_add (ref_count, -1); }
10229c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
103a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod  inline int get (void) { return hb_atomic_int_get (ref_count); }
104a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod  inline int get_unsafe (void) const { return ref_count; }
105a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod  inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; }
10629c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
107852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod} hb_reference_count_t;
10829c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
10929c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
110852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod/* user_data */
11129c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
11221d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbodstruct hb_user_data_array_t {
11329c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
11421d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod  struct hb_user_data_item_t {
11521d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod    hb_user_data_key_t *key;
11621d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod    void *data;
11721d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod    hb_destroy_func_t destroy;
118811482bd650fb5652a9835471ae8ecf0fb185611Behdad Esfahbod
11921d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod    inline bool operator == (hb_user_data_key_t *other_key) const { return key == other_key; }
12021d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod    inline bool operator == (hb_user_data_item_t &other) const { return key == other.key; }
12129c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
12221d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod    void finish (void) { if (destroy) destroy (data); }
12321d2c92fdf7307c7117f8948021f0dd7d5a5d2a3Behdad Esfahbod  };
12429c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
12545bfa99034512e886d75b1d45a5a649647f4711fBehdad Esfahbod  hb_lockable_set_t<hb_user_data_item_t, hb_static_mutex_t> items;
12629c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
127218e67b9eefa26e2e4fe43f99a84d082b185b1b0Behdad Esfahbod  HB_INTERNAL bool set (hb_user_data_key_t *key,
128218e67b9eefa26e2e4fe43f99a84d082b185b1b0Behdad Esfahbod			void *              data,
12933ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod			hb_destroy_func_t   destroy,
13033ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod			hb_bool_t           replace);
13129c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
132218e67b9eefa26e2e4fe43f99a84d082b185b1b0Behdad Esfahbod  HB_INTERNAL void *get (hb_user_data_key_t *key);
13329c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
13445bfa99034512e886d75b1d45a5a649647f4711fBehdad Esfahbod  HB_INTERNAL void finish (void);
13529c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod};
13629c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
13729c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
138852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod/* object_header */
13929c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
140fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbodtypedef struct _hb_object_header_t hb_object_header_t;
141863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod
142fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbodstruct _hb_object_header_t {
143fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  hb_reference_count_t ref_count;
14429c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod  hb_user_data_array_t user_data;
145863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod
146fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID}
147863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod
148fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  static inline void *create (unsigned int size) {
149fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod    hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size);
15035a7383c6138fd705560f0d4bb30659cbd1ab64cBehdad Esfahbod
151fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod    if (likely (obj))
152fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod      obj->init ();
153c62b503770325819f249885dfc9d4683a69c9efdBehdad Esfahbod
154fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod    return obj;
155fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  }
156ba8d94ce3360bfaf2c530d01f2af69237018a531Behdad Esfahbod
157fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  inline void init (void) {
158fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod    ref_count.init (1);
159fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  }
160fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod
16129c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod  inline bool is_inert (void) const {
16229c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod    return unlikely (ref_count.is_invalid ());
16329c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod  }
164fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod
165fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  inline void reference (void) {
166fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod    if (unlikely (!this || this->is_inert ()))
167fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod      return;
168fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod    ref_count.inc ();
169fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  }
170fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod
171fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  inline bool destroy (void) {
172fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod    if (unlikely (!this || this->is_inert ()))
173fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod      return false;
17429c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod    if (ref_count.dec () != 1)
17529c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod      return false;
17629c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
177df077fadd7828b609bdfe4dbcad52ef2448525c7Behdad Esfahbod    ref_count.init (HB_REFERENCE_COUNT_INVALID_VALUE);
178df077fadd7828b609bdfe4dbcad52ef2448525c7Behdad Esfahbod
17929c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod    user_data.finish ();
18029c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
18129c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod    return true;
18229c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod  }
18329c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
18429c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod  inline bool set_user_data (hb_user_data_key_t *key,
18529c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod			     void *              data,
18633ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod			     hb_destroy_func_t   destroy_func,
18733ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod			     hb_bool_t           replace) {
18829c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod    if (unlikely (!this || this->is_inert ()))
18929c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod      return false;
19029c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
19133ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod    return user_data.set (key, data, destroy_func, replace);
19229c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod  }
19329c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod
19429c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod  inline void *get_user_data (hb_user_data_key_t *key) {
19529c67d3f70b081766a6c01353980f457f38aeb12Behdad Esfahbod    return user_data.get (key);
196fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  }
197fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod
198fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  inline void trace (const char *function) const {
199cf26510dbbd8d38486e6ba423800db6427ade332Behdad Esfahbod    if (unlikely (!this)) return;
200cc06c243d8be3ebb1190281653d2dba504c16c0fBehdad Esfahbod    DEBUG_MSG (OBJECT, (void *) this,
201cc06c243d8be3ebb1190281653d2dba504c16c0fBehdad Esfahbod	       "refcount=%d %s",
202a1970d9afc15b2c6b7513b923019bb223bd95154Behdad Esfahbod	       this ? ref_count.get_unsafe () : 0,
203cc06c243d8be3ebb1190281653d2dba504c16c0fBehdad Esfahbod	       function);
204fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod  }
205fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod
206fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod};
207fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod
208fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod
209ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbod
210852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod
211852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod/* object */
212852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod
213ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbodtemplate <typename Type>
214ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbodstatic inline void hb_object_trace (const Type *obj, const char *function)
215ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod{
216ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  obj->header.trace (function);
217ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod}
218ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbodtemplate <typename Type>
2191cd5969f253528b1fc05a06c7a9f222baa29f68dBehdad Esfahbodstatic inline Type *hb_object_create (void)
220ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod{
221ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  Type *obj = (Type *) hb_object_header_t::create (sizeof (Type));
222ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  hb_object_trace (obj, HB_FUNC);
223ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  return obj;
224ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod}
225ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbodtemplate <typename Type>
226ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbodstatic inline bool hb_object_is_inert (const Type *obj)
227ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod{
2281cd5969f253528b1fc05a06c7a9f222baa29f68dBehdad Esfahbod  return unlikely (obj->header.is_inert ());
229ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod}
230ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbodtemplate <typename Type>
231ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbodstatic inline Type *hb_object_reference (Type *obj)
232ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod{
233ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  hb_object_trace (obj, HB_FUNC);
234ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  obj->header.reference ();
235ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  return obj;
236ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod}
237ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbodtemplate <typename Type>
238ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbodstatic inline bool hb_object_destroy (Type *obj)
239ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod{
240ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  hb_object_trace (obj, HB_FUNC);
241ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod  return obj->header.destroy ();
242ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod}
243852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbodtemplate <typename Type>
244852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbodstatic inline bool hb_object_set_user_data (Type               *obj,
245852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod					    hb_user_data_key_t *key,
246852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod					    void *              data,
24733ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod					    hb_destroy_func_t   destroy,
24833ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod					    hb_bool_t           replace)
249852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod{
25033ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod  return obj->header.set_user_data (key, data, destroy, replace);
251852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod}
252852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod
253852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbodtemplate <typename Type>
254852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbodstatic inline void *hb_object_get_user_data (Type               *obj,
255852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod					     hb_user_data_key_t *key)
256852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod{
257852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod  return obj->header.get_user_data (key);
258852e08ec8fbfbce1d50e571d0bb0b52ef4d4cc58Behdad Esfahbod}
259ae008b90cfc2028e878100f78b21d70f923a6044Behdad Esfahbod
260ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbod
261ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbod
262ec6f9c2fd03a49d1e91cbaefa5bdbbfb35dff92eBehdad Esfahbod
263863df68e894b7644dcd12da88aa22f73edf829dcBehdad Esfahbod
264c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#endif /* HB_OBJECT_PRIVATE_HH */
265