Flutter Engine
The Flutter Engine
third_party
skia
src
gpu
ganesh
GrNonAtomicRef.h
Go to the documentation of this file.
1
/*
2
* Copyright 2015 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#ifndef GrNonAtomicRef_DEFINED
9
#define GrNonAtomicRef_DEFINED
10
11
#include "
include/core/SkRefCnt.h
"
12
#include "
include/private/base/SkNoncopyable.h
"
13
#include "
include/private/base/SkTArray.h
"
14
15
/**
16
* A simple non-atomic ref used in the GrBackendApi when we don't want to pay for the overhead of a
17
* threadsafe ref counted object
18
*/
19
template
<
typename
TSub
class
>
class
GrNonAtomicRef
:
public
SkNoncopyable
{
20
public
:
21
GrNonAtomicRef
() : fRefCnt(1) {}
22
23
#ifdef SK_DEBUG
24
~GrNonAtomicRef
() {
25
// fRefCnt can be one when a subclass is created statically
26
SkASSERT
((0 == fRefCnt || 1 == fRefCnt));
27
// Set to invalid values.
28
fRefCnt = -10;
29
}
30
#endif
31
32
bool
unique
()
const
{
return
1 == fRefCnt; }
33
34
// We allow this getter because this type is not thread-safe, meaning only one thread should
35
// have ownership and be manipulating the ref count or querying this.
36
int
refCnt
()
const
{
return
fRefCnt; }
37
38
void
ref
()
const
{
39
// Once the ref cnt reaches zero it should never be ref'ed again.
40
SkASSERT
(fRefCnt > 0);
41
++fRefCnt;
42
}
43
44
void
unref
()
const
{
45
SkASSERT
(fRefCnt > 0);
46
--fRefCnt;
47
if
(0 == fRefCnt) {
48
GrTDeleteNonAtomicRef
(
static_cast<
const
TSubclass*
>
(
this
));
49
return
;
50
}
51
}
52
53
private
:
54
mutable
int32_t fRefCnt;
55
56
using
INHERITED =
SkNoncopyable
;
57
};
58
59
template
<
typename
T>
inline
void
GrTDeleteNonAtomicRef
(
const
T
* ref) {
60
delete
ref;
61
}
62
63
#endif
GrTDeleteNonAtomicRef
void GrTDeleteNonAtomicRef(const T *ref)
Definition:
GrNonAtomicRef.h:59
SkASSERT
#define SkASSERT(cond)
Definition:
SkAssert.h:116
SkNoncopyable.h
SkRefCnt.h
SkTArray.h
GrNonAtomicRef
Definition:
GrNonAtomicRef.h:19
GrNonAtomicRef::ref
void ref() const
Definition:
GrNonAtomicRef.h:38
GrNonAtomicRef::refCnt
int refCnt() const
Definition:
GrNonAtomicRef.h:36
GrNonAtomicRef::unique
bool unique() const
Definition:
GrNonAtomicRef.h:32
GrNonAtomicRef::GrNonAtomicRef
GrNonAtomicRef()
Definition:
GrNonAtomicRef.h:21
GrNonAtomicRef::unref
void unref() const
Definition:
GrNonAtomicRef.h:44
SkNoncopyable
Definition:
SkNoncopyable.h:18
SkNoncopyable::SkNoncopyable
SkNoncopyable()=default
T
#define T
Definition:
precompiler.cc:65
Generated on Sun Jun 23 2024 21:56:20 for Flutter Engine by
1.9.4