aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrNonAtomicRef.h
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-07-13 09:29:42 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-13 09:29:42 -0700
commit2419b360ead17231c555a9e01747b7ffbbfb70e4 (patch)
treebd1eaf84427ff075f6177ded4f1ca7dda434ebf7 /src/gpu/GrNonAtomicRef.h
parentb031fcf1c5d84605daecec6cf1f35a7529ef13e9 (diff)
Add GrNonAtomicRef
Diffstat (limited to 'src/gpu/GrNonAtomicRef.h')
-rw-r--r--src/gpu/GrNonAtomicRef.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/gpu/GrNonAtomicRef.h b/src/gpu/GrNonAtomicRef.h
new file mode 100644
index 0000000000..026e11d863
--- /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