aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkRWBuffer.h
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2016-04-22 06:59:01 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-22 06:59:01 -0700
commit635164028594b4af0086ec85b5e4570dd11091da (patch)
tree4f1d3a0a5f6c11ace269cf6c99f9a8062e38b4e5 /include/core/SkRWBuffer.h
parent488165e689baf0f215d5798c87d0031b58e4bc8d (diff)
Fixes for SkRWBuffer
Do not call SkBufferHead::validate in SkROBuffer's destructor, which may be called in a separate thread from SkRWBuffer::append. validate() reads SkBufferBlock::fUsed, and append() writes to it, resulting in a data race. Update some comments to be more clear about how it is safe to use these classes across threads. Test the readers in separate threads. In addition, make sure it is safe to create a reader even when no data has been appended. Add tests for this case. Mark a parameter to SkBufferHead::validate() as const, reflecting its use. BUG=chromium:601578 BUG=chromium:605479 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1871953002 Review URL: https://codereview.chromium.org/1871953002
Diffstat (limited to 'include/core/SkRWBuffer.h')
-rw-r--r--include/core/SkRWBuffer.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/include/core/SkRWBuffer.h b/include/core/SkRWBuffer.h
index d054e0a5fd..9626d28df9 100644
--- a/include/core/SkRWBuffer.h
+++ b/include/core/SkRWBuffer.h
@@ -53,22 +53,25 @@ public:
private:
const SkBufferBlock* fBlock;
size_t fRemaining;
+ const SkROBuffer* fBuffer;
};
private:
- SkROBuffer(const SkBufferHead* head, size_t available);
+ SkROBuffer(const SkBufferHead* head, size_t available, const SkBufferBlock* fTail);
virtual ~SkROBuffer();
- const SkBufferHead* fHead;
- const size_t fAvailable;
+ const SkBufferHead* fHead;
+ const size_t fAvailable;
+ const SkBufferBlock* fTail;
friend class SkRWBuffer;
};
/**
* Accumulates bytes of memory that are "appended" to it, growing internal storage as needed.
- * The growth is done such that at any time, a RBuffer or StreamAsset can be snapped off, which
- * can see the previously stored bytes, but which will be unaware of any future writes.
+ * The growth is done such that at any time in the writer's thread, an RBuffer or StreamAsset
+ * can be snapped off (and safely passed to another thread). The RBuffer/StreamAsset snapshot
+ * can see the previously stored bytes, but will be unaware of any future writes.
*/
class SK_API SkRWBuffer {
public: