Coverage Report

Created: 2024-07-27 06:53

/src/LPM/external.protobuf/include/google/protobuf/arena_cleanup.h
Line
Count
Source (jump to first uncovered line)
1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2008 Google Inc.  All rights reserved.
3
//
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file or at
6
// https://developers.google.com/open-source/licenses/bsd
7
8
#ifndef GOOGLE_PROTOBUF_ARENA_CLEANUP_H__
9
#define GOOGLE_PROTOBUF_ARENA_CLEANUP_H__
10
11
#include <cstddef>
12
#include <cstring>
13
#include <vector>
14
15
#include "absl/base/attributes.h"
16
#include "absl/base/prefetch.h"
17
18
// Must be included last.
19
#include "google/protobuf/port_def.inc"
20
21
namespace google {
22
namespace protobuf {
23
namespace internal {
24
namespace cleanup {
25
26
// Helper function invoking the destructor of `object`
27
template <typename T>
28
0
void arena_destruct_object(void* object) {
29
0
  reinterpret_cast<T*>(object)->~T();
30
0
}
Unexecuted instantiation: void google::protobuf::internal::cleanup::arena_destruct_object<google::protobuf::internal::InternalMetadata::Container<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(void*)
Unexecuted instantiation: void google::protobuf::internal::cleanup::arena_destruct_object<google::protobuf::internal::ImplicitWeakMessage>(void*)
Unexecuted instantiation: void google::protobuf::internal::cleanup::arena_destruct_object<google::protobuf::internal::InternalMetadata::Container<google::protobuf::UnknownFieldSet> >(void*)
31
32
// CleanupNode contains the object (`elem`) that needs to be
33
// destroyed, and the function to destroy it (`destructor`)
34
// elem must be aligned at minimum on a 4 byte boundary.
35
struct CleanupNode {
36
  void* elem;
37
  void (*destructor)(void*);
38
};
39
40
0
inline ABSL_ATTRIBUTE_ALWAYS_INLINE CleanupNode* ToCleanup(void* pos) {
41
0
  return reinterpret_cast<CleanupNode*>(pos);
42
0
}
43
44
// Adds a cleanup entry at memory location `pos`.
45
inline ABSL_ATTRIBUTE_ALWAYS_INLINE void CreateNode(void* pos, void* elem,
46
0
                                                    void (*destructor)(void*)) {
47
0
  CleanupNode n = {elem, destructor};
48
0
  memcpy(pos, &n, sizeof(n));
49
0
}
50
51
// Optimization: performs a prefetch on the elem for the cleanup node at `pos`.
52
0
inline ABSL_ATTRIBUTE_ALWAYS_INLINE void PrefetchNode(void* pos) {
53
0
  // We explicitly use NTA prefetch here to avoid polluting remote caches: we
54
0
  // are destroying these instances, there is no purpose for these cache lines
55
0
  // to linger around in remote caches.
56
0
  absl::PrefetchToLocalCacheNta(ToCleanup(pos)->elem);
57
0
}
58
59
// Destroys the object referenced by the cleanup node.
60
0
inline ABSL_ATTRIBUTE_ALWAYS_INLINE void DestroyNode(void* pos) {
61
0
  CleanupNode* cleanup = ToCleanup(pos);
62
0
  cleanup->destructor(cleanup->elem);
63
0
}
64
65
// Append in `out` the pointer to the to-be-cleaned object in `pos`.
66
0
inline void PeekNode(void* pos, std::vector<void*>& out) {
67
0
  out.push_back(ToCleanup(pos)->elem);
68
0
}
69
70
// Returns the required size for a cleanup node.
71
0
constexpr ABSL_ATTRIBUTE_ALWAYS_INLINE size_t Size() {
72
0
  return sizeof(CleanupNode);
73
0
}
74
75
}  // namespace cleanup
76
}  // namespace internal
77
}  // namespace protobuf
78
}  // namespace google
79
80
#include "google/protobuf/port_undef.inc"
81
82
#endif  // GOOGLE_PROTOBUF_ARENA_CLEANUP_H__