Choose memset procs once.

TSAN shows us racing on the function pointers.  Might as well fix it.

WARNING: ThreadSanitizer: data race (pid=19995)
  Read of size 8 at 0x7f703affb048 by thread T12 (mutexes: write M2957):
    #0 SkBitmap::internalErase(SkIRect const&, unsigned int, unsigned int, unsigned int, unsigned int) const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:886 (tests+0x0000003511ca)
    #1 SkBitmap::eraseARGB(unsigned int, unsigned int, unsigned int, unsigned int) const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:919 (tests+0x0000003534bf)
    #2 (anonymous namespace)::DecodingImageGenerator::getPixels(SkImageInfo const&, void*, unsigned long) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/images/SkDecodingImageGenerator.cpp:195 (tests+0x00000051bee1)
    #3 SkDiscardablePixelRef::onNewLockPixels(SkPixelRef::LockRec*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/lazy/SkDiscardablePixelRef.cpp:63 (tests+0x00000039ad9c)
    #4 SkPixelRef::lockPixels(SkPixelRef::LockRec*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkPixelRef.cpp:179 (tests+0x0000003fec23)
    #5 SkBitmap::lockPixels() const /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/core/SkBitmap.cpp:414 (tests+0x00000034e41e)
    #6 SkAutoLockPixels /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/include/core/SkBitmap.h:819 (tests+0x0000002752f3)
    #7 ImageDecoderOptions(skiatest::Reporter*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/ImageDecodingTest.cpp:565 (tests+0x000000275d03)
    #8 skiatest::Test::run() /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/Test.cpp:107 (tests+0x0000002263e7)
    #9 SkTestRunnable::run() /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/tests/skia_test.cpp:108 (tests+0x0000001d8607)
    #10 SkThreadPoolPrivate::ThreadLocal<void>::run(SkTRunnable<void>*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/include/utils/SkThreadPool.h:108 (tests+0x0000001d817e)
    #11 thread_start(void*) /var/scratch/Release/../../../usr/local/google/home/mtklein/skia/src/utils/SkThreadUtils_pthread.cpp:66 (tests+0x000000604347)

  Previous write of size 8 at 0x7f703affb048 by thread T26:
    [failed to restore the stack]


BUG=skia:1792
R=bungeman@google.com, mtklein@google.com, reed@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/250503003

git-svn-id: http://skia.googlecode.com/svn/trunk@14548 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-02 20:28:56 +00:00
parent 1111b611b6
commit 608d63735f
2 changed files with 31 additions and 22 deletions

View File

@ -17,7 +17,7 @@
@param value The 16bit value to be copied into buffer
@param count The number of times value should be copied into the buffer.
*/
void sk_memset16_portable(uint16_t dst[], uint16_t value, int count);
void sk_memset16(uint16_t dst[], uint16_t value, int count);
typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count);
SkMemset16Proc SkMemset16GetPlatformProc();
@ -26,18 +26,10 @@ SkMemset16Proc SkMemset16GetPlatformProc();
@param value The 32bit value to be copied into buffer
@param count The number of times value should be copied into the buffer.
*/
void sk_memset32_portable(uint32_t dst[], uint32_t value, int count);
void sk_memset32(uint32_t dst[], uint32_t value, int count);
typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
SkMemset32Proc SkMemset32GetPlatformProc();
#ifndef sk_memset16
extern SkMemset16Proc sk_memset16;
#endif
#ifndef sk_memset32
extern SkMemset32Proc sk_memset32;
#endif
///////////////////////////////////////////////////////////////////////////////
#define kMaxBytesInUTF8Sequence 4

View File

@ -8,6 +8,7 @@
#include "SkUtils.h"
#include "SkOnce.h"
#if 0
#define assign_16_longs(dst, value) \
@ -37,7 +38,7 @@
///////////////////////////////////////////////////////////////////////////////
void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) {
static void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) {
SkASSERT(dst != NULL && count >= 0);
if (count <= 0) {
@ -90,7 +91,7 @@ void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) {
}
}
void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) {
static void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) {
SkASSERT(dst != NULL && count >= 0);
int sixteenlongs = count >> 4;
@ -108,21 +109,37 @@ void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) {
}
}
static void sk_memset16_stub(uint16_t dst[], uint16_t value, int count) {
SkMemset16Proc proc = SkMemset16GetPlatformProc();
sk_memset16 = proc ? proc : sk_memset16_portable;
sk_memset16(dst, value, count);
static void choose_memset16(SkMemset16Proc* proc) {
*proc = SkMemset16GetPlatformProc();
if (NULL == *proc) {
*proc = &sk_memset16_portable;
}
}
SkMemset16Proc sk_memset16 = sk_memset16_stub;
void sk_memset16(uint16_t dst[], uint16_t value, int count) {
SK_DECLARE_STATIC_ONCE(once);
static SkMemset16Proc proc = NULL;
SkOnce(&once, choose_memset16, &proc);
SkASSERT(proc != NULL);
static void sk_memset32_stub(uint32_t dst[], uint32_t value, int count) {
SkMemset32Proc proc = SkMemset32GetPlatformProc();
sk_memset32 = proc ? proc : sk_memset32_portable;
sk_memset32(dst, value, count);
return proc(dst, value, count);
}
SkMemset32Proc sk_memset32 = sk_memset32_stub;
static void choose_memset32(SkMemset32Proc* proc) {
*proc = SkMemset32GetPlatformProc();
if (NULL == *proc) {
*proc = &sk_memset32_portable;
}
}
void sk_memset32(uint32_t dst[], uint32_t value, int count) {
SK_DECLARE_STATIC_ONCE(once);
static SkMemset32Proc proc = NULL;
SkOnce(&once, choose_memset32, &proc);
SkASSERT(proc != NULL);
return proc(dst, value, count);
}
///////////////////////////////////////////////////////////////////////////////