Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
y
z
Enumerations
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
z
Classes
Class List
Class Hierarchy
Class Members
All
:
[
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
[
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
y
Enumerations
a
b
c
d
e
f
h
i
k
l
m
n
o
p
r
s
t
u
v
w
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
Properties
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Related Functions
:
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
z
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
grpc
src
core
lib
slice
slice_refcount_base.h
Go to the documentation of this file.
1
// Copyright 2021 gRPC authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef GRPC_CORE_LIB_SLICE_SLICE_REFCOUNT_BASE_H
16
#define GRPC_CORE_LIB_SLICE_SLICE_REFCOUNT_BASE_H
17
18
#include <
grpc/support/port_platform.h
>
19
20
#include <stddef.h>
21
22
#include <atomic>
23
24
// grpc_slice_refcount : A reference count for grpc_slice.
25
struct
grpc_slice_refcount
{
26
public
:
27
typedef
void (*
DestroyerFn
)(
grpc_slice_refcount
*);
28
29
static
grpc_slice_refcount
*
NoopRefcount
() {
30
return
reinterpret_cast<
grpc_slice_refcount
*
>
(1);
31
}
32
33
grpc_slice_refcount
() =
default
;
34
35
// Regular constructor for grpc_slice_refcount.
36
//
37
// Parameters:
38
// 1. DestroyerFn destroyer_fn
39
// Called when the refcount goes to 0, with 'this' as parameter.
40
explicit
grpc_slice_refcount
(
DestroyerFn
destroyer_fn)
41
:
destroyer_fn_
(destroyer_fn) {}
42
43
void
Ref
() {
ref_
.fetch_add(1, std::memory_order_relaxed); }
44
void
Unref
() {
45
if
(
ref_
.fetch_sub(1, std::memory_order_acq_rel) == 1) {
46
destroyer_fn_
(
this
);
47
}
48
}
49
50
// Is this the only instance?
51
// For this to be useful the caller needs to ensure that if this is the only
52
// instance, no other instance could be created during this call.
53
bool
IsUnique
()
const
{
return
ref_
.load(std::memory_order_relaxed) == 1; }
54
55
private
:
56
std::atomic<size_t>
ref_
{1};
57
DestroyerFn
destroyer_fn_
=
nullptr
;
58
};
59
60
#endif // GRPC_CORE_LIB_SLICE_SLICE_REFCOUNT_BASE_H
grpc_slice_refcount::ref_
std::atomic< size_t > ref_
Definition:
slice_refcount_base.h:56
grpc_slice_refcount::Ref
void Ref()
Definition:
slice_refcount_base.h:43
grpc_slice_refcount::IsUnique
bool IsUnique() const
Definition:
slice_refcount_base.h:53
grpc_slice_refcount::NoopRefcount
static grpc_slice_refcount * NoopRefcount()
Definition:
slice_refcount_base.h:29
grpc_slice_refcount::DestroyerFn
void(* DestroyerFn)(grpc_slice_refcount *)
Definition:
slice_refcount_base.h:27
grpc_slice_refcount
Definition:
slice_refcount_base.h:25
grpc_slice_refcount::Unref
void Unref()
Definition:
slice_refcount_base.h:44
grpc_slice_refcount::grpc_slice_refcount
grpc_slice_refcount()=default
grpc_slice_refcount::grpc_slice_refcount
grpc_slice_refcount(DestroyerFn destroyer_fn)
Definition:
slice_refcount_base.h:40
grpc_slice_refcount::destroyer_fn_
DestroyerFn destroyer_fn_
Definition:
slice_refcount_base.h:57
port_platform.h
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:19