From c1b71d6c30041f01675dd54a77adc9c177afdf44 Mon Sep 17 00:00:00 2001 From: halcanary Date: Fri, 20 Feb 2015 12:45:50 -0800 Subject: [PATCH] PDF: remove unnecessary mutexes. We now force all SkPDFObjects to stay on one thread. TBR=mtklein@google.com Review URL: https://codereview.chromium.org/942153002 --- src/pdf/SkPDFFont.h | 1 - src/pdf/SkPDFGraphicState.h | 1 - src/pdf/SkPDFShader.cpp | 2 -- src/pdf/SkPDFStream.cpp | 1 - src/pdf/SkPDFStream.h | 6 +----- src/pdf/SkPDFTypes.cpp | 20 +++----------------- src/pdf/SkPDFTypes.h | 2 -- 7 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h index 105ae8d..6ff4c7b 100644 --- a/src/pdf/SkPDFFont.h +++ b/src/pdf/SkPDFFont.h @@ -14,7 +14,6 @@ #include "SkBitSet.h" #include "SkPDFTypes.h" #include "SkTDArray.h" -#include "SkThread.h" #include "SkTypeface.h" class SkPaint; diff --git a/src/pdf/SkPDFGraphicState.h b/src/pdf/SkPDFGraphicState.h index b26e4a0..2c9198c 100644 --- a/src/pdf/SkPDFGraphicState.h +++ b/src/pdf/SkPDFGraphicState.h @@ -13,7 +13,6 @@ #include "SkPaint.h" #include "SkPDFTypes.h" #include "SkTemplates.h" -#include "SkThread.h" class SkPDFFormXObject; diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 21d767d..d7605b3 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -20,7 +20,6 @@ #include "SkScalar.h" #include "SkStream.h" #include "SkTemplates.h" -#include "SkThread.h" #include "SkTSet.h" #include "SkTypes.h" @@ -583,7 +582,6 @@ SkPDFObject* SkPDFShader::GetPDFShader(SkPDFCanon* canon, const SkMatrix& matrix, const SkIRect& surfaceBBox, SkScalar rasterScale) { - // There is only one mutex becasue we don't know which one we'll need. SkAutoTDelete state( SkNEW_ARGS(State, (shader, matrix, surfaceBBox, rasterScale))); return get_pdf_shader_by_state(canon, dpi, &state); diff --git a/src/pdf/SkPDFStream.cpp b/src/pdf/SkPDFStream.cpp index 4aeb2db..ae3fe4a 100644 --- a/src/pdf/SkPDFStream.cpp +++ b/src/pdf/SkPDFStream.cpp @@ -41,7 +41,6 @@ SkPDFStream::SkPDFStream(const SkPDFStream& pdfStream) SkPDFStream::~SkPDFStream() {} void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { - SkAutoMutexAcquire lock(fMutex); // multiple threads could be calling emit if (!this->populate(catalog)) { return fSubstitute->emitObject(stream, catalog); } diff --git a/src/pdf/SkPDFStream.h b/src/pdf/SkPDFStream.h index cf9316f..90c6bca 100644 --- a/src/pdf/SkPDFStream.h +++ b/src/pdf/SkPDFStream.h @@ -39,8 +39,7 @@ public: virtual ~SkPDFStream(); - // The SkPDFObject interface. This two method uses a mutex to - // allow multiple threads to call at the same time. + // The SkPDFObject interface. virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) SK_OVERRIDE; protected: @@ -90,9 +89,6 @@ private: // Indicates what form (or if) the stream has been requested. State fState; - // Mutex guards fState, fDataStream, and fSubstitute in public interface. - SkMutex fMutex; - SkAutoTDelete fDataStream; SkAutoTUnref fSubstitute; diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp index 7902e59..43cd684 100644 --- a/src/pdf/SkPDFTypes.cpp +++ b/src/pdf/SkPDFTypes.cpp @@ -312,15 +312,10 @@ SkPDFDict::~SkPDFDict() { } int SkPDFDict::size() const { - SkAutoMutexAcquire lock(fMutex); return fValue.count(); } void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { - SkAutoMutexAcquire lock(fMutex); // If another thread triggers a - // resize while this thread is in - // the for-loop, we can be left - // with a bad fValue[i] reference. stream->writeText("<<"); for (int i = 0; i < fValue.count(); i++) { SkASSERT(fValue[i].key); @@ -348,9 +343,6 @@ void SkPDFDict::addResources(SkTSet* resourceSet, SkPDFObject* SkPDFDict::append(SkPDFName* key, SkPDFObject* value) { SkASSERT(key); SkASSERT(value); - SkAutoMutexAcquire lock(fMutex); // If the SkTDArray resizes while - // two threads access array, one - // is left with a bad pointer. *(fValue.append()) = Rec(key, value); return value; } @@ -376,7 +368,6 @@ void SkPDFDict::insertName(const char key[], const char name[]) { } void SkPDFDict::clear() { - SkAutoMutexAcquire lock(fMutex); for (int i = 0; i < fValue.count(); i++) { SkASSERT(fValue[i].key); SkASSERT(fValue[i].value); @@ -389,7 +380,6 @@ void SkPDFDict::clear() { void SkPDFDict::remove(const char key[]) { SkASSERT(key); SkPDFName name(key); - SkAutoMutexAcquire lock(fMutex); for (int i = 0; i < fValue.count(); i++) { SkASSERT(fValue[i].key); if (*(fValue[i].key) == name) { @@ -403,12 +393,8 @@ void SkPDFDict::remove(const char key[]) { } void SkPDFDict::mergeFrom(const SkPDFDict& other) { - SkAutoMutexAcquire lockOther(other.fMutex); - SkTDArray copy(other.fValue); - lockOther.release(); // Do not hold both mutexes at once. - - SkAutoMutexAcquire lock(fMutex); - for (int i = 0; i < copy.count(); i++) { - *(fValue.append()) = Rec(SkRef(copy[i].key), SkRef(copy[i].value)); + for (int i = 0; i < other.fValue.count(); i++) { + *(fValue.append()) = + Rec(SkRef(other.fValue[i].key), SkRef(other.fValue[i].value)); } } diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h index 54c59f2..7a72a38 100644 --- a/src/pdf/SkPDFTypes.h +++ b/src/pdf/SkPDFTypes.h @@ -10,7 +10,6 @@ #ifndef SkPDFTypes_DEFINED #define SkPDFTypes_DEFINED -#include "SkMutex.h" #include "SkRefCnt.h" #include "SkScalar.h" #include "SkString.h" @@ -384,7 +383,6 @@ private: static const int kMaxLen = 4095; - mutable SkMutex fMutex; // protects modifications to fValue SkTDArray fValue; SkPDFObject* append(SkPDFName* key, SkPDFObject* value); -- 2.7.4