From: Behdad Esfahbod Date: Wed, 4 May 2011 23:27:37 +0000 (-0400) Subject: Move code around X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=56eb5ad6f94c32189ad219438db9a18683ca6846;p=platform%2Fupstream%2FlibHarfBuzzSharp.git Move code around Mutex (and Windows.h by extension) are fairly isolated now. --- diff --git a/src/Makefile.am b/src/Makefile.am index 558e697..0a7edb3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,20 +12,20 @@ HBCFLAGS = HBLIBS = HBSOURCES = \ hb-blob.cc \ - hb-blob-private.hh \ - hb-buffer.cc \ hb-buffer-private.hh \ + hb-buffer.cc \ hb-common.cc \ - hb-font.cc \ hb-font-private.hh \ + hb-font.cc \ + hb-mutex-private.hh \ hb-object-private.hh \ hb-open-file-private.hh \ hb-open-type-private.hh \ hb-ot-head-private.hh \ hb-private.hh \ hb-shape.cc \ - hb-unicode.cc \ hb-unicode-private.hh \ + hb-unicode.cc \ $(NULL) HBHEADERS = \ hb.h \ diff --git a/src/hb-blob-private.hh b/src/hb-blob-private.hh deleted file mode 100644 index 5f81e5a..0000000 --- a/src/hb-blob-private.hh +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2010 Red Hat, Inc. - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Red Hat Author(s): Behdad Esfahbod - */ - -#ifndef HB_BLOB_PRIVATE_HH -#define HB_BLOB_PRIVATE_HH - -#include "hb-private.hh" - -#include "hb-blob.h" -#include "hb-object-private.hh" - -HB_BEGIN_DECLS - - -struct _hb_blob_t { - hb_object_header_t header; - - unsigned int length; - - hb_mutex_t lock; - /* the rest are protected by lock */ - - unsigned int lock_count; - hb_memory_mode_t mode; - - const char *data; - - void *user_data; - hb_destroy_func_t destroy; -}; - -extern HB_INTERNAL hb_blob_t _hb_blob_nil; - - -HB_END_DECLS - -#endif /* HB_BLOB_PRIVATE_HH */ diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 8d6d746..ed2f871 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -26,7 +26,9 @@ #include "hb-private.hh" -#include "hb-blob-private.hh" +#include "hb-blob.h" +#include "hb-object-private.hh" +#include "hb-mutex-private.hh" #ifdef HAVE_SYS_MMAN_H #ifdef HAVE_UNISTD_H @@ -45,7 +47,25 @@ HB_BEGIN_DECLS #define HB_DEBUG_BLOB (HB_DEBUG+0) #endif -hb_blob_t _hb_blob_nil = { + +struct _hb_blob_t { + hb_object_header_t header; + + unsigned int length; + + hb_mutex_t lock; + /* the rest are protected by lock */ + + unsigned int lock_count; + hb_memory_mode_t mode; + + const char *data; + + void *user_data; + hb_destroy_func_t destroy; +}; + +static hb_blob_t _hb_blob_nil = { HB_OBJECT_HEADER_STATIC, 0, /* length */ diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 9e1ee51..683eab5 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -55,8 +55,6 @@ struct _hb_font_funcs_t { } v; }; -extern HB_INTERNAL hb_font_funcs_t _hb_font_funcs_nil; - /* * hb_face_t @@ -70,7 +68,6 @@ struct _hb_face_t { hb_destroy_func_t destroy; hb_blob_t *head_blob; - const struct head *head_table; struct hb_ot_layout_t *ot_layout; }; diff --git a/src/hb-font.cc b/src/hb-font.cc index 0a58377..e41ceec 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -29,7 +29,7 @@ #include "hb-ot-layout-private.hh" #include "hb-font-private.hh" -#include "hb-blob-private.hh" +#include "hb-blob.h" #include "hb-open-file-private.hh" #include @@ -79,7 +79,8 @@ hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED, hb_codepoint_t second_glyph HB_UNUSED) { return 0; } -hb_font_funcs_t _hb_font_funcs_nil = { + +static hb_font_funcs_t _hb_font_funcs_nil = { HB_OBJECT_HEADER_STATIC, TRUE, /* immutable */ @@ -92,6 +93,7 @@ hb_font_funcs_t _hb_font_funcs_nil = { } }; + hb_font_funcs_t * hb_font_funcs_create (void) { @@ -368,7 +370,7 @@ hb_face_t * hb_face_create_for_data (hb_blob_t *blob, unsigned int index) { - if (unlikely (!blob || hb_object_is_inert (blob))) + if (unlikely (!blob || !hb_blob_get_length (blob))) return &_hb_face_nil; hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (Sanitizer::sanitize (hb_blob_reference (blob)), index); @@ -425,11 +427,11 @@ hb_face_reference_table (hb_face_t *face, hb_blob_t *blob; if (unlikely (!face || !face->get_table)) - return &_hb_blob_nil; + return hb_blob_get_empty (); blob = face->get_table (tag, face->user_data); if (unlikely (!blob)) - blob = hb_blob_get_empty(); + return hb_blob_get_empty (); return blob; } diff --git a/src/hb-mutex-private.hh b/src/hb-mutex-private.hh new file mode 100644 index 0000000..a81d362 --- /dev/null +++ b/src/hb-mutex-private.hh @@ -0,0 +1,105 @@ +/* + * Copyright © 2007 Chris Wilson + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Contributor(s): + * Chris Wilson + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_MUTEX_PRIVATE_HH +#define HB_MUTEX_PRIVATE_HH + +#include "hb-private.hh" + +HB_BEGIN_DECLS + + +/* mutex */ + +/* We need external help for these */ + +#ifdef HAVE_GLIB + +#include + +typedef volatile int hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V) +#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI)) +#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V) + +typedef GStaticMutex hb_mutex_t; +#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT +#define hb_mutex_init(M) g_static_mutex_init (&(M)) +#define hb_mutex_lock(M) g_static_mutex_lock (&(M)) +#define hb_mutex_trylock(M) g_static_mutex_trylock (&(M)) +#define hb_mutex_unlock(M) g_static_mutex_unlock (&(M)) +#define hb_mutex_free(M) g_static_mutex_free (&(M)) + + +#elif defined(_MSC_VER) + +#include + +typedef long hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) _InterlockedExchangeAdd (&(AI), V) +#define hb_atomic_int_get(AI) (_ReadBarrier (), (AI)) +#define hb_atomic_int_set(AI, V) ((void) _InterlockedExchange (&(AI), (V))) + +#include + +typedef CRITICAL_SECTION hb_mutex_t; +#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 } +#define hb_mutex_init(M) InitializeCriticalSection (&(M)) +#define hb_mutex_lock(M) EnterCriticalSection (&(M)) +#define hb_mutex_trylock(M) TryEnterCriticalSection (&(M)) +#define hb_mutex_unlock(M) LeaveCriticalSection (&(M)) +#define hb_mutex_free(M) DeleteCriticalSection (&(M)) + + +#else + +#warning "Could not find any system to define platform macros, library will NOT be thread-safe" + +typedef volatile int hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) ((AI) += (V), (AI) - (V)) +#define hb_atomic_int_get(AI) (AI) +#define hb_atomic_int_set(AI, V) ((void) ((AI) = (V))) + +typedef volatile int hb_mutex_t; +#define HB_MUTEX_INIT 0 +#define hb_mutex_init(M) ((void) ((M) = 0)) +#define hb_mutex_lock(M) ((void) ((M) = 1)) +#define hb_mutex_trylock(M) ((M) = 1, 1) +#define hb_mutex_unlock(M) ((void) ((M) = 0)) +#define hb_mutex_free(M) ((void) ((M) = 2)) + + +#endif + + +HB_END_DECLS + +#endif /* HB_MUTEX_PRIVATE_HH */ diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index d77b6a5..1f49885 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -44,7 +44,7 @@ HB_BEGIN_DECLS #endif -/* atomic_int and mutex */ +/* atomic_int */ /* We need external help for these */ @@ -57,17 +57,8 @@ typedef volatile int hb_atomic_int_t; #define hb_atomic_int_get(AI) g_atomic_int_get (&(AI)) #define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V) -typedef GStaticMutex hb_mutex_t; -#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT -#define hb_mutex_init(M) g_static_mutex_init (&(M)) -#define hb_mutex_lock(M) g_static_mutex_lock (&(M)) -#define hb_mutex_trylock(M) g_static_mutex_trylock (&(M)) -#define hb_mutex_unlock(M) g_static_mutex_unlock (&(M)) -#define hb_mutex_free(M) g_static_mutex_free (&(M)) -#else - -#ifdef _MSC_VER +#elif defined(_MSC_VER) #include @@ -76,34 +67,16 @@ typedef long hb_atomic_int_t; #define hb_atomic_int_get(AI) (_ReadBarrier (), (AI)) #define hb_atomic_int_set(AI, V) ((void) _InterlockedExchange (&(AI), (V))) -#include - -typedef CRITICAL_SECTION hb_mutex_t; -#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 } -#define hb_mutex_init(M) InitializeCriticalSection (&(M)) -#define hb_mutex_lock(M) EnterCriticalSection (&(M)) -#define hb_mutex_trylock(M) TryEnterCriticalSection (&(M)) -#define hb_mutex_unlock(M) LeaveCriticalSection (&(M)) -#define hb_mutex_free(M) DeleteCriticalSection (&(M)) #else -#warning "Could not find any system to define platform macros, library will NOT be thread-safe" +#warning "Could not find any system to define atomic_int macros, library will NOT be thread-safe" typedef volatile int hb_atomic_int_t; #define hb_atomic_int_fetch_and_add(AI, V) ((AI) += (V), (AI) - (V)) #define hb_atomic_int_get(AI) (AI) #define hb_atomic_int_set(AI, V) ((void) ((AI) = (V))) -typedef volatile int hb_mutex_t; -#define HB_MUTEX_INIT 0 -#define hb_mutex_init(M) ((void) ((M) = 0)) -#define hb_mutex_lock(M) ((void) ((M) = 1)) -#define hb_mutex_trylock(M) ((M) = 1, 1) -#define hb_mutex_unlock(M) ((void) ((M) = 0)) -#define hb_mutex_free(M) ((void) ((M) = 2)) - -#endif #endif diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc index e8eb553..62cbcdc 100644 --- a/src/hb-unicode.cc +++ b/src/hb-unicode.cc @@ -80,7 +80,6 @@ hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, } -extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil; hb_unicode_funcs_t _hb_unicode_funcs_nil = { HB_OBJECT_HEADER_STATIC,