hb-object-private.hh revision f0954d1e08ae288eda9904e17108fc73f48c0b98
1f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod/* 2f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * Copyright © 2007 Chris Wilson 3f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * 4f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * This is part of HarfBuzz, an OpenType Layout engine library. 5f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * 6f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * Permission is hereby granted, without written agreement and without 7f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 8f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * software and its documentation for any purpose, provided that the 9f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 10f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * all copies of this software. 11f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * 12f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 13f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 14f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 15f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 16f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * DAMAGE. 17f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * 18f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 19f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 21f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 22f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 23f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * 24f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * Contributor(s): 25f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod * Chris Wilson <chris@chris-wilson.co.uk> 26f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod */ 27f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 28f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#ifndef HB_REFCOUNT_PRIVATE_H 29f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFCOUNT_PRIVATE_H 30f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 31f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbodtypedef int hb_atomic_int_t; 32f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 33f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod/* Encapsulate operations on the object's reference count */ 34f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbodtypedef struct { 35f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod hb_atomic_int_t ref_count; 36f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod} hb_reference_count_t; 37f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 38f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod/* XXX add real atomic ops */ 39f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define _hb_reference_count_inc(RC) ((RC).ref_count++) 40f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define _hb_reference_count_dec_and_test(RC) ((RC).ref_count-- == 1) 41f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 42f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFERENCE_COUNT_INIT(RC, VALUE) ((RC).ref_count = (VALUE)) 43f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 44f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFERENCE_COUNT_GET_VALUE(RC) ((RC).ref_count+0) 45f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFERENCE_COUNT_SET_VALUE(RC, VALUE) ((RC).ref_count = (VALUE), 0) 46f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 47f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1) 48f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE} 49f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 50f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFERENCE_COUNT_IS_INVALID(RC) (HB_REFERENCE_COUNT_GET_VALUE (RC) == HB_REFERENCE_COUNT_INVALID_VALUE) 51f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 52f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#define HB_REFERENCE_COUNT_HAS_REFERENCE(RC) (HB_REFERENCE_COUNT_GET_VALUE (RC) > 0) 53f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod 54f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#endif /* HB_REFCOUNT_PRIVATE_H */ 55