Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: src/gpu/GrNonAtomicRef.h

Issue 1238523002: Add GrNonAtomicRef (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/gpu.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrNonAtomicRef.h
diff --git a/src/gpu/GrNonAtomicRef.h b/src/gpu/GrNonAtomicRef.h
new file mode 100644
index 0000000000000000000000000000000000000000..026e11d8630a7376d13663bdde11915c1618af3f
--- /dev/null
+++ b/src/gpu/GrNonAtomicRef.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrNonAtomicRef_DEFINED
+#define GrNonAtomicRef_DEFINED
+
+#include "SkRefCnt.h"
+#include "SkTArray.h"
+
+/**
+ * A simple non-atomic ref used in the GrBackend when we don't want to pay for the overhead of a
+ * threadsafe ref counted object
+ */
+class GrNonAtomicRef : public SkNoncopyable {
+public:
+ GrNonAtomicRef() : fRefCnt(1) {}
+ virtual ~GrNonAtomicRef() {
+ // fRefCnt can be one when a subclass is created statically
+ SkASSERT((0 == fRefCnt || 1 == fRefCnt));
+ // Set to invalid values.
+ SkDEBUGCODE(fRefCnt = -10;)
+ }
+
+ void ref() const {
+ // Once the ref cnt reaches zero it should never be ref'ed again.
+ SkASSERT(fRefCnt > 0);
+ ++fRefCnt;
+ }
+
+ void unref() const {
+ SkASSERT(fRefCnt > 0);
+ --fRefCnt;
+ if (0 == fRefCnt) {
+ SkDELETE(this);
+ return;
+ }
+ }
+
+private:
+ mutable int32_t fRefCnt;
+
+ typedef SkNoncopyable INHERITED;
+};
+
+#endif
« no previous file with comments | « gyp/gpu.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698