diff options
author | digit@google.com <digit@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-01-26 21:26:40 +0000 |
---|---|---|
committer | digit@google.com <digit@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-01-26 21:26:40 +0000 |
commit | 1771cbf43d9a1334e3d870c635b4215bb888dd98 (patch) | |
tree | b32203ccd81d3747e2cc36d5e71ee7cadcff03fa /include/pdf | |
parent | 72b55be3f3448287e8ff6fe83633edadfb60f59a (diff) |
posix: Avoid static initializers in static/global mutexes
This patch removes static initializers related to static and
global mutexes from the final library's machine code when
building on a pthread-capable system.
We use PTHREAD_MUTEX_INITIALIZER to perform POD-style
initialization. You need a line like the following to declare
a global mutex with it:
SkBaseMutex gMutex = { PTHREAD_MUTEX_INITIALIZER };
We introduce the SK_DECLARE_STATIC_MUTEX and SK_DECLARE_GLOBAL_MUTEX
macros to be able to declare static/global mutexes in the source tree
uniformly.
SkMutex is now defined as a sub-class of SkBaseMutex, with standard
construction/destruction semantics. This is useful if the mutex
object is a member of another C++ class, or allocated dynamically.
We also modify a few places to refer to SkBaseMutex instead of a
SkMutex, where it makes sense. Generally speaking, client code
should hold and use pointers to SkBaseMutex whenever they can
now.
We defined a new built-time macro named SK_USE_POSIX_THREADS
to indicate that we're using a pthread-based SkThread.h
interface. The macro will also be used in future patches
to implement other helper thread synchronization classes.
Finally, we inline the acquire() and release() functions in the
case of Posix to improve performance a bit.
Running: 'bench -repeat 10 -match mutex' on an Android device or
a 2.4GHz Xeon Linux desktop shows the following improvements:
Before After
Galaxy Nexus 1.64 1.45
Nexus S 1.47 1.16
Xoom 1.86 1.66
Xeon 0.36 0.31
This removes 5 static mutex initializers from the library
Review URL: https://codereview.appspot.com/5501066
git-svn-id: http://skia.googlecode.com/svn/trunk@3091 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/pdf')
-rw-r--r-- | include/pdf/SkPDFFont.h | 2 | ||||
-rw-r--r-- | include/pdf/SkPDFGraphicState.h | 2 | ||||
-rw-r--r-- | include/pdf/SkPDFShader.h | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/include/pdf/SkPDFFont.h b/include/pdf/SkPDFFont.h index b884017912..2ebdec73da 100644 --- a/include/pdf/SkPDFFont.h +++ b/include/pdf/SkPDFFont.h @@ -196,7 +196,7 @@ private: // This should be made a hash table if performance is a problem. static SkTDArray<FontRec>& CanonicalFonts(); - static SkMutex& CanonicalFontsMutex(); + static SkBaseMutex& CanonicalFontsMutex(); }; #endif diff --git a/include/pdf/SkPDFGraphicState.h b/include/pdf/SkPDFGraphicState.h index 9420405273..af01737276 100644 --- a/include/pdf/SkPDFGraphicState.h +++ b/include/pdf/SkPDFGraphicState.h @@ -86,7 +86,7 @@ private: // This should be made a hash table if performance is a problem. static SkTDArray<GSCanonicalEntry>& CanonicalPaints(); - static SkMutex& CanonicalPaintsMutex(); + static SkBaseMutex& CanonicalPaintsMutex(); SkPDFGraphicState(); explicit SkPDFGraphicState(const SkPaint& paint); diff --git a/include/pdf/SkPDFShader.h b/include/pdf/SkPDFShader.h index 6b6ae031b1..439d83bbd5 100644 --- a/include/pdf/SkPDFShader.h +++ b/include/pdf/SkPDFShader.h @@ -56,7 +56,7 @@ protected: }; // This should be made a hash table if performance is a problem. static SkTDArray<ShaderCanonicalEntry>& CanonicalShaders(); - static SkMutex& CanonicalShadersMutex(); + static SkBaseMutex& CanonicalShadersMutex(); static void RemoveShader(SkPDFObject* shader); SkPDFShader(); |