hb-private.hh revision acdba3f90b232fc12fcb200dca2584481b339118
164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod/* 26c78683c042250a7b5a6fc6ebae4717b03fadf9eBehdad Esfahbod * Copyright (C) 2007,2008,2009 Red Hat, Inc. 364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * 4c755cb3e3ac55156d0d2ec05adea7a650b97cc41Behdad Esfahbod * This is part of HarfBuzz, a text shaping library. 564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * 664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * Permission is hereby granted, without written agreement and without 764aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 864aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * software and its documentation for any purpose, provided that the 964aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 1064aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * all copies of this software. 1164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * 1264aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1464aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * DAMAGE. 1764aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * 1864aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1964aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 2064aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 2164aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 2264aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 2364aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * 2464aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod 2564aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod */ 2664aef3a54999496fd1de4f5aa5b019e4c03b3836Behdad Esfahbod 278dd1c8b8d6797d899d0f5b0a8015886bf6520ca2Behdad Esfahbod#ifndef HB_PRIVATE_H 288dd1c8b8d6797d899d0f5b0a8015886bf6520ca2Behdad Esfahbod#define HB_PRIVATE_H 295b3f7702a64fe0513d08a67bdb72704e46fd7cd4Behdad Esfahbod 30df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if HAVE_CONFIG_H 31df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#include "config.h" 32df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif 33c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod 34bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#include "hb-common.h" 35b28815c1f6e46d38471cacbc31248ca6fda8c4d1Behdad Esfahbod 36c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#include <stdlib.h> 37f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#include <string.h> 38f0954d1e08ae288eda9904e17108fc73f48c0b98Behdad Esfahbod#include <assert.h> 391d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod 401d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod/* We only use these two for debug output. However, the debug code is 411d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod * always seen by the compiler (and optimized out in non-debug builds. 421d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod * If including these becomes a problem, we can start thinking about 431d52151a19ed8ec776276aac5cc6ce3769e0d947Behdad Esfahbod * someway around that. */ 447acb389569cf99c6bae9db31a8ed7c7007fbb566Behdad Esfahbod#include <stdio.h> 457acb389569cf99c6bae9db31a8ed7c7007fbb566Behdad Esfahbod#include <errno.h> 46c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod 47acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_BEGIN_DECLS 48acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 49bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 50bc200457430c083914a64bf4b056153506749610Behdad Esfahbod/* Essentials */ 51bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 52bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#ifndef NULL 53bc200457430c083914a64bf4b056153506749610Behdad Esfahbod# define NULL ((void *) 0) 54bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#endif 55bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 56bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#undef FALSE 57bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#define FALSE 0 58bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 59bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#undef TRUE 60bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#define TRUE 1 61df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 62a794ebf4be9896393f4badf02905a4007981a588Behdad Esfahbod 63c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod/* Basics */ 64c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod 65c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#undef MIN 66c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#define MIN(a,b) ((a) < (b) ? (a) : (b)) 677586089c6fa8185cad8387869d3703c637e5cbb1Behdad Esfahbod 688a3511ac6c795226699c2b36e03401ecdf88f5f8Behdad Esfahbod#undef MAX 698a3511ac6c795226699c2b36e03401ecdf88f5f8Behdad Esfahbod#define MAX(a,b) ((a) > (b) ? (a) : (b)) 708a3511ac6c795226699c2b36e03401ecdf88f5f8Behdad Esfahbod 714591753ad4b5ec0224e3f1befdfe4fc5f6075562Behdad Esfahbod#undef ARRAY_LENGTH 724591753ad4b5ec0224e3f1befdfe4fc5f6075562Behdad Esfahbod#define ARRAY_LENGTH(__array) ((signed int) (sizeof (__array) / sizeof (__array[0]))) 7312360f7c159826ae72271b34486dee59d96aa8caBehdad Esfahbod 7435a7383c6138fd705560f0d4bb30659cbd1ab64cBehdad Esfahbod#define HB_STMT_START do 7535a7383c6138fd705560f0d4bb30659cbd1ab64cBehdad Esfahbod#define HB_STMT_END while (0) 765b3f7702a64fe0513d08a67bdb72704e46fd7cd4Behdad Esfahbod 77303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] 78303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) 79303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) 80303fe62824d4e99df554b6bfaacba05d068522fbBehdad Esfahbod 81bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 82bc200457430c083914a64bf4b056153506749610Behdad Esfahbod/* Misc */ 83bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 84c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod 85df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 86494d28ad988e505c1c45cc35a7ec6b880cfec5fcBehdad Esfahbod#define _HB_BOOLEAN_EXPR(expr) ((expr) ? 1 : 0) 8764d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define likely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 1)) 8864d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define unlikely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 0)) 89df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#else 9064d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define likely(expr) (expr) 9164d3fc8d0dada673245cc8c0b1c12cd849b30997Behdad Esfahbod#define unlikely(expr) (expr) 92df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif 93df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 94df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#ifndef __GNUC__ 95df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#undef __attribute__ 96df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define __attribute__(x) 97df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif 98df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 99df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if __GNUC__ >= 3 10033d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_PURE_FUNC __attribute__((pure)) 10133d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_CONST_FUNC __attribute__((const)) 102df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#else 10333d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_PURE_FUNC 10433d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_CONST_FUNC 105df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif 106bc7830e4259755ce7549025c6f5bf750e78c2ff1Behdad Esfahbod#if __GNUC__ >= 4 10733d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_UNUSED __attribute__((unused)) 108bc7830e4259755ce7549025c6f5bf750e78c2ff1Behdad Esfahbod#else 10933d13fdda99acaeffa9600737e8870278d053ebeBehdad Esfahbod#define HB_UNUSED 110bc7830e4259755ce7549025c6f5bf750e78c2ff1Behdad Esfahbod#endif 111df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 112eee8598d75d3af692d9ececf7e8ac458e892ba9eBehdad Esfahbod#ifndef HB_INTERNAL 113357d0f29c431b842179ee4b56c21bcc402178ce7Behdad Esfahbod# define HB_INTERNAL __attribute__((__visibility__("hidden"))) 114eee8598d75d3af692d9ececf7e8ac458e892ba9eBehdad Esfahbod#endif 115eee8598d75d3af692d9ececf7e8ac458e892ba9eBehdad Esfahbod 116df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 117df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER) 118df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define snprintf _snprintf 119df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif 120df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 121df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#ifdef _MSC_VER 122df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#undef inline 123df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define inline __inline 124df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif 125df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 126df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#ifdef __STRICT_ANSI__ 127df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#undef inline 128df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#define inline __inline__ 129df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod#endif 130df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 131df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 1327d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#if __GNUC__ >= 3 1337d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#define HB_FUNC __PRETTY_FUNCTION__ 1347d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#elif defined(_MSC_VER) 1357d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#define HB_FUNC __FUNCSIG__ 1367d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#else 1377d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#define HB_FUNC __func__ 1387d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod#endif 1397d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod 1407d3a126334f8e6f6441561c1bb592bd3fa7a2c5cBehdad Esfahbod 1419b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod/* Return the number of 1 bits in mask. */ 14297e7f8f305c47caf2968a9da3b8407825547286dBehdad Esfahbodstatic inline HB_CONST_FUNC unsigned int 143c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod_hb_popcount32 (uint32_t mask) 144c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod{ 145c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 1469b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod return __builtin_popcount (mask); 147c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#else 1489b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod /* "HACKMEM 169" */ 1499b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod register uint32_t y; 1509b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod y = (mask >> 1) &033333333333; 1519b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod y = mask - y - ((y >>1) & 033333333333); 1529b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod return (((y + (y >> 3)) & 030707070707) % 077); 153c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod#endif 154c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod} 155c7d457aa3ae7138630f52ca7263f663a3ea284c0Behdad Esfahbod 1569b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod/* Returns the number of bits needed to store number */ 1579b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbodstatic inline HB_CONST_FUNC unsigned int 1589b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod_hb_bit_storage (unsigned int number) 1599b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod{ 1609b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) 161f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod return likely (number) ? (sizeof (unsigned int) * 8 - __builtin_clz (number)) : 0; 1629b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod#else 1639b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod register unsigned int n_bits = 0; 1649b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod while (number) { 1659b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod n_bits++; 1669b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod number >>= 1; 1679b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod } 1689b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod return n_bits; 1699b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod#endif 1709b6023338530a2dbb8214eb4391ef3e8372f3892Behdad Esfahbod} 171df66028781a7609a515980e64396e6f1044d764aBehdad Esfahbod 172f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod/* Returns the number of zero bits in the least significant side of number */ 173f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbodstatic inline HB_CONST_FUNC unsigned int 174f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod_hb_ctz (unsigned int number) 175f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod{ 176f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) 177f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod return likely (number) ? __builtin_ctz (number) : 0; 178f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod#else 179f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod register unsigned int n_bits = 0; 180f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod if (unlikely (!number)) return 0; 181f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod while (!(number & 1)) { 182f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod n_bits++; 183f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod number >>= 1; 184f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod } 185f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod return n_bits; 186f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod#endif 187f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod} 188f7acd8df5146155b51d6f50aeb04f54f3030c1c3Behdad Esfahbod 189f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod/* We need external help for these */ 190f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 191f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#ifdef HAVE_GLIB 192f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 193f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#include <glib.h> 194f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 195f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef int hb_atomic_int_t; 196f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V) 197f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI)) 198f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V) 199f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 200f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef GStaticMutex hb_mutex_t; 201f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT 202f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_init(M) g_static_mutex_init (&M) 203f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_lock(M) g_static_mutex_lock (&M) 204f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_trylock(M) g_static_mutex_trylock (&M) 205f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_mutex_unlock(M) g_static_mutex_unlock (&M) 206f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 207f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#else 208f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 209f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#ifdef _MSC_VER 210f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#pragma message(__LOC__"Could not find any system to define platform macros, library will NOT be thread-safe") 211f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#else 212f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#warning "Could not find any system to define platform macros, library will NOT be thread-safe" 213f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#endif 214f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 215f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef int hb_atomic_int_t; 216f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_fetch_and_add(AI, V) ((AI) += (V), (AI) - (V)) 217f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#define hb_atomic_int_get(AI) (AI) 218ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_atomic_int_set(AI, V) HB_STMT_START { (AI) = (V); } HB_STMT_END 219f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 220f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbodtypedef int hb_mutex_t; 221ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define HB_MUTEX_INIT 0 222ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_init(M) HB_STMT_START { (M) = 0; } HB_STMT_END 223ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_lock(M) HB_STMT_START { (M) = 1; } HB_STMT_END 224ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_trylock(M) ((M) = 1, 1) 225ffff7dc44cb2a35a60f92831165e9d3c3a61ce19Behdad Esfahbod#define hb_mutex_unlock(M) HB_STMT_START { (M) = 0; } HB_STMT_END 226f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 227f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod#endif 228f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 229f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 230f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod/* Big-endian handling */ 231f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 2327a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint16(v) ((uint16_t) ((((const uint8_t *)&(v))[0] << 8) + (((const uint8_t *)&(v))[1]))) 2337a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod 234e032ed9f75d4a0f365649a25706871bbb5ae6651Behdad Esfahbod#define hb_be_uint16_put(v,V) HB_STMT_START { v[0] = (V>>8); v[1] = (V); } HB_STMT_END 2357a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint16_get(v) (uint16_t) ((v[0] << 8) + v[1]) 2367a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint16_cmp(a,b) (a[0] == b[0] && a[1] == b[1]) 2377a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod 238e032ed9f75d4a0f365649a25706871bbb5ae6651Behdad Esfahbod#define hb_be_uint32_put(v,V) HB_STMT_START { v[0] = (V>>24); v[1] = (V>>16); v[2] = (V>>8); v[3] = (V); } HB_STMT_END 2397a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint32_get(v) (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2] << 8) + v[3]) 2407a52f281178867379adb6e6c6fb0022102f75d17Behdad Esfahbod#define hb_be_uint32_cmp(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3]) 241f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 242f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 243bc200457430c083914a64bf4b056153506749610Behdad Esfahbod/* Debug */ 244bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 245bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#ifndef HB_DEBUG 246bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#define HB_DEBUG 0 247bc200457430c083914a64bf4b056153506749610Behdad Esfahbod#endif 248bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 249eaf29edb8fa49390e5f48b78105dfd173aff445bJeff Muizelaarstatic inline hb_bool_t /* always returns TRUE */ 250bc200457430c083914a64bf4b056153506749610Behdad Esfahbod_hb_trace (const char *what, 251bc200457430c083914a64bf4b056153506749610Behdad Esfahbod const char *function, 252bc200457430c083914a64bf4b056153506749610Behdad Esfahbod const void *obj, 253bc200457430c083914a64bf4b056153506749610Behdad Esfahbod unsigned int depth, 254bc200457430c083914a64bf4b056153506749610Behdad Esfahbod unsigned int max_depth) 255bc200457430c083914a64bf4b056153506749610Behdad Esfahbod{ 256bc200457430c083914a64bf4b056153506749610Behdad Esfahbod if (depth < max_depth) 257bc200457430c083914a64bf4b056153506749610Behdad Esfahbod fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, depth, depth, function); 258bc200457430c083914a64bf4b056153506749610Behdad Esfahbod return TRUE; 259bc200457430c083914a64bf4b056153506749610Behdad Esfahbod} 260bc200457430c083914a64bf4b056153506749610Behdad Esfahbod 261f60f2166c48d07f556ff83f04e95181946eb03dfBehdad Esfahbod 262ba8d94ce3360bfaf2c530d01f2af69237018a531Behdad Esfahbod#include "hb-object-private.h" 263ba8d94ce3360bfaf2c530d01f2af69237018a531Behdad Esfahbod 264acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 265acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_END_DECLS 266acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 2678dd1c8b8d6797d899d0f5b0a8015886bf6520ca2Behdad Esfahbod#endif /* HB_PRIVATE_H */ 268