[HB] Simplify refcounting functions
This commit is contained in:
parent
23af767a44
commit
35a7383c61
|
@ -40,14 +40,14 @@ struct _hb_blob_t {
|
||||||
void *user_data;
|
void *user_data;
|
||||||
};
|
};
|
||||||
static hb_blob_t _hb_blob_nil = {
|
static hb_blob_t _hb_blob_nil = {
|
||||||
HB_REFERENCE_COUNT_INVALID,
|
HB_REFERENCE_COUNT_INVALID, /* ref_count */
|
||||||
|
|
||||||
NULL,
|
NULL, /* data */
|
||||||
0,
|
0, /* len */
|
||||||
HB_MEMORY_MODE_READONLY,
|
HB_MEMORY_MODE_READONLY, /* mode */
|
||||||
|
|
||||||
NULL,
|
NULL, /* destroy */
|
||||||
NULL
|
NULL /* user_data */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -76,11 +76,12 @@ hb_blob_create (const char *data,
|
||||||
return &_hb_blob_nil;
|
return &_hb_blob_nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HB_REFERENCE_COUNT_DO_CREATE (blob);
|
||||||
|
|
||||||
blob->data = data;
|
blob->data = data;
|
||||||
blob->len = len;
|
blob->len = len;
|
||||||
blob->mode = mode;
|
blob->mode = mode;
|
||||||
|
|
||||||
HB_REFERENCE_COUNT_INIT (blob->ref_count, 1);
|
|
||||||
blob->destroy = destroy;
|
blob->destroy = destroy;
|
||||||
blob->user_data = user_data;
|
blob->user_data = user_data;
|
||||||
|
|
||||||
|
@ -95,26 +96,13 @@ hb_blob_create (const char *data,
|
||||||
hb_blob_t *
|
hb_blob_t *
|
||||||
hb_blob_reference (hb_blob_t *blob)
|
hb_blob_reference (hb_blob_t *blob)
|
||||||
{
|
{
|
||||||
if (blob == NULL || HB_REFERENCE_COUNT_IS_INVALID (blob->ref_count))
|
HB_REFERENCE_COUNT_DO_REFERENCE (blob);
|
||||||
return blob;
|
|
||||||
|
|
||||||
assert (HB_REFERENCE_COUNT_HAS_REFERENCE (blob->ref_count));
|
|
||||||
|
|
||||||
_hb_reference_count_inc (blob->ref_count);
|
|
||||||
|
|
||||||
return blob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hb_blob_destroy (hb_blob_t *blob)
|
hb_blob_destroy (hb_blob_t *blob)
|
||||||
{
|
{
|
||||||
if (blob == NULL || HB_REFERENCE_COUNT_IS_INVALID (blob->ref_count))
|
HB_REFERENCE_COUNT_DO_DESTROY (blob);
|
||||||
return;
|
|
||||||
|
|
||||||
assert (HB_REFERENCE_COUNT_HAS_REFERENCE (blob->ref_count));
|
|
||||||
|
|
||||||
if (!_hb_reference_count_dec_and_test (blob->ref_count))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_hb_blob_destroy_user_data (blob);
|
_hb_blob_destroy_user_data (blob);
|
||||||
|
|
||||||
|
|
|
@ -59,4 +59,6 @@ typedef struct _hb_unicode_callbacks_t hb_unicode_callbacks_t;
|
||||||
typedef struct _hb_face_t hb_face_t;
|
typedef struct _hb_face_t hb_face_t;
|
||||||
typedef struct _hb_font_t hb_font_t;
|
typedef struct _hb_font_t hb_font_t;
|
||||||
|
|
||||||
|
typedef hb_blob_t * (*hb_get_table_func_t) (hb_tag_t tag, void *user_data);
|
||||||
|
|
||||||
#endif /* HB_COMMON_H */
|
#endif /* HB_COMMON_H */
|
||||||
|
|
|
@ -73,6 +73,8 @@
|
||||||
# define TRUE 1
|
# define TRUE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define HB_STMT_START do
|
||||||
|
#define HB_STMT_END while (0)
|
||||||
|
|
||||||
#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
|
#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
|
||||||
#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
|
#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2007 Chris Wilson
|
* Copyright (C) 2007 Chris Wilson
|
||||||
|
* Copyright (C) 2009 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This is part of HarfBuzz, an OpenType Layout engine library.
|
* This is part of HarfBuzz, an OpenType Layout engine library.
|
||||||
*
|
*
|
||||||
|
@ -23,6 +24,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Chris Wilson <chris@chris-wilson.co.uk>
|
* Chris Wilson <chris@chris-wilson.co.uk>
|
||||||
|
* Red Hat Author(s): Behdad Esfahbod
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HB_REFCOUNT_PRIVATE_H
|
#ifndef HB_REFCOUNT_PRIVATE_H
|
||||||
|
@ -51,4 +53,31 @@ typedef struct {
|
||||||
|
|
||||||
#define HB_REFERENCE_COUNT_HAS_REFERENCE(RC) (HB_REFERENCE_COUNT_GET_VALUE (RC) > 0)
|
#define HB_REFERENCE_COUNT_HAS_REFERENCE(RC) (HB_REFERENCE_COUNT_GET_VALUE (RC) > 0)
|
||||||
|
|
||||||
|
|
||||||
|
/* Helper macros */
|
||||||
|
|
||||||
|
#define HB_REFERENCE_COUNT_DO_CREATE(obj) \
|
||||||
|
HB_STMT_START { \
|
||||||
|
HB_REFERENCE_COUNT_INIT (obj->ref_count, 1); \
|
||||||
|
} HB_STMT_END
|
||||||
|
|
||||||
|
#define HB_REFERENCE_COUNT_DO_REFERENCE(obj) \
|
||||||
|
HB_STMT_START { \
|
||||||
|
if (obj == NULL || HB_REFERENCE_COUNT_IS_INVALID (obj->ref_count)) \
|
||||||
|
return obj; \
|
||||||
|
assert (HB_REFERENCE_COUNT_HAS_REFERENCE (obj->ref_count)); \
|
||||||
|
_hb_reference_count_inc (obj->ref_count); \
|
||||||
|
return obj; \
|
||||||
|
} HB_STMT_END
|
||||||
|
|
||||||
|
#define HB_REFERENCE_COUNT_DO_DESTROY(obj) \
|
||||||
|
HB_STMT_START { \
|
||||||
|
if (obj == NULL || HB_REFERENCE_COUNT_IS_INVALID (obj->ref_count)) \
|
||||||
|
return; \
|
||||||
|
assert (HB_REFERENCE_COUNT_HAS_REFERENCE (obj->ref_count)); \
|
||||||
|
if (!_hb_reference_count_dec_and_test (obj->ref_count)) \
|
||||||
|
return; \
|
||||||
|
} HB_STMT_END
|
||||||
|
|
||||||
|
|
||||||
#endif /* HB_REFCOUNT_PRIVATE_H */
|
#endif /* HB_REFCOUNT_PRIVATE_H */
|
||||||
|
|
Loading…
Reference in New Issue