Go to the documentation of this file.
31 #include "absl/base/attributes.h"
33 #include "absl/base/internal/low_level_alloc.h"
34 #ifndef ABSL_LOW_LEVEL_ALLOC_MISSING
36 #include "absl/synchronization/internal/graphcycles.h"
41 #include "absl/base/internal/hide_ptr.h"
42 #include "absl/base/internal/raw_logging.h"
43 #include "absl/base/internal/spinlock.h"
49 namespace synchronization_internal {
59 static void InitArenaIfNecessary() {
61 if (
arena ==
nullptr) {
91 const T& back()
const {
return ptr_[
size_-1]; }
92 void pop_back() {
size_--; }
94 void push_back(
const T&
v) {
105 void fill(
const T& val) {
113 void MoveFrom(Vec<T>* src) {
114 if (src->ptr_ == src->space_) {
149 T*
copy =
static_cast<T*
>(
156 Vec(
const Vec&) =
delete;
157 Vec& operator=(
const Vec&) =
delete;
163 NodeSet() {
Init(); }
165 void clear() {
Init(); }
173 if (
table_[i] == kEmpty) {
194 #define HASH_FOR_EACH(elem, eset) \
195 for (int32_t elem, _cursor = 0; (eset).Next(&_cursor, &elem); )
220 int deleted_index = -1;
225 }
else if (e == kEmpty) {
227 return (deleted_index >= 0) ? deleted_index :
i;
228 }
else if (e == kDel && deleted_index < 0) {
250 for (
const auto& e :
copy) {
255 NodeSet(
const NodeSet&) =
delete;
256 NodeSet& operator=(
const NodeSet&) =
delete;
270 inline int32_t NodeIndex(GraphId
id) {
271 return static_cast<uint32_t>(
id.handle & 0xfffffffful);
274 inline uint32_t NodeVersion(GraphId
id) {
275 return static_cast<uint32_t>(
id.handle >> 32);
294 explicit PointerMap(
const Vec<Node*>* nodes) :
nodes_(nodes) {
302 if (
n->masked_ptr == masked)
return i;
310 (*nodes_)[
i]->next_hash = *head;
321 if (
n->masked_ptr == masked) {
322 *slot =
n->next_hash;
326 slot = &
n->next_hash;
336 std::array<int32_t, kHashTableSize>
table_;
361 Node*
n =
rep->nodes_[NodeIndex(
id)];
362 return (
n->version == NodeVersion(
id)) ?
n :
nullptr;
366 InitArenaIfNecessary();
385 void*
ptr = base_internal::UnhidePtr<void>(nx->masked_ptr);
392 if (!ranks.insert(nx->rank)) {
397 if (nx->rank >= ny->rank) {
422 return MakeId(
n->rank,
n->version);
433 return MakeId(
r,
n->version);
451 x->masked_ptr = base_internal::HidePtr<void>(
nullptr);
462 return n ==
nullptr ? nullptr
463 : base_internal::UnhidePtr<void>(
n->masked_ptr);
479 xn->out.erase(NodeIndex(
y));
480 yn->in.erase(NodeIndex(
x));
489 static void Sort(
const Vec<Node*>&, Vec<int32_t>* delta);
499 if (nx ==
nullptr || ny ==
nullptr)
return true;
501 if (nx == ny)
return false;
502 if (!nx->out.insert(
y)) {
509 if (nx->rank <= ny->rank) {
522 for (
const auto& d :
r->deltaf_) {
523 r->nodes_[d]->visited =
false;
537 r->stack_.push_back(
n);
538 while (!
r->stack_.empty()) {
539 n =
r->stack_.back();
540 r->stack_.pop_back();
542 if (nn->visited)
continue;
545 r->deltaf_.push_back(
n);
548 Node* nw =
r->nodes_[w];
549 if (nw->rank == upper_bound) {
552 if (!nw->visited && nw->rank < upper_bound) {
553 r->stack_.push_back(w);
563 r->stack_.push_back(
n);
564 while (!
r->stack_.empty()) {
565 n =
r->stack_.back();
566 r->stack_.pop_back();
568 if (nn->visited)
continue;
571 r->deltab_.push_back(
n);
574 Node* nw =
r->nodes_[w];
575 if (!nw->visited && lower_bound < nw->
rank) {
576 r->stack_.push_back(w);
583 Sort(
r->nodes_, &
r->deltab_);
584 Sort(
r->nodes_, &
r->deltaf_);
592 r->merged_.resize(
r->deltab_.size() +
r->deltaf_.size());
594 r->deltaf_.begin(),
r->deltaf_.end(),
599 r->nodes_[
r->list_[
i]]->rank =
r->merged_[
i];
603 static void Sort(
const Vec<Node*>& nodes, Vec<int32_t>* delta) {
605 const Vec<Node*>* nodes;
607 return (*nodes)[
a]->rank < (*nodes)[
b]->rank;
612 std::sort(delta->begin(), delta->end(),
cmp);
617 for (
auto&
v : *src) {
619 v =
r->nodes_[w]->rank;
620 r->nodes_[w]->visited =
false;
639 r->stack_.push_back(
x);
640 while (!
r->stack_.empty()) {
642 r->stack_.pop_back();
649 if (path_len < max_path_len) {
653 r->stack_.push_back(-1);
660 if (
seen.insert(w)) {
661 r->stack_.push_back(w);
674 int (*get_stack_trace)(
void**
stack,
int)) {
676 if (n ==
nullptr ||
n->priority >=
priority) {
698 #endif // ABSL_LOW_LEVEL_ALLOC_MISSING
bool InsertEdge(GraphId source_node, GraphId dest_node)
bool HasEdge(GraphId source_node, GraphId dest_node) const
void UpdateStackTrace(GraphId id, int priority, int(*get_stack_trace)(void **, int))
static void MoveToList(GraphCycles::Rep *r, Vec< int32_t > *src, Vec< int32_t > *dst)
static PyObject * Remove(PyObject *pself, PyObject *value)
bool CheckInvariants() const
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
bool HasNode(GraphId node)
static Arena * NewArena(int32_t flags)
static int Init(CMessage *self, PyObject *args, PyObject *kwargs)
bool IsReachable(GraphId source_node, GraphId dest_node) const
static PyObject * Add(PyObject *self, PyObject *file_descriptor_proto)
const Vec< Node * > * nodes_
#define ABSL_ARRAYSIZE(array)
#define ABSL_NAMESPACE_END
static void BackwardDFS(GraphCycles::Rep *r, int32_t n, int32_t lower_bound)
static AllocList * Next(int i, AllocList *prev, LowLevelAlloc::Arena *arena)
#define T(upbtypeconst, upbtype, ctype, default_value)
void RemoveNode(void *ptr)
grpc_core::ScopedArenaPtr arena
static Node * FindNode(GraphCycles::Rep *rep, GraphId id)
uintptr_t HidePtr(T *ptr)
#define ABSL_NAMESPACE_BEGIN
static void Free(void *s) ABSL_ATTRIBUTE_SECTION(malloc_hook)
void RemoveEdge(GraphId source_node, GraphId dest_node)
int GetStackTrace(GraphId id, void ***ptr)
unsigned __int64 uint64_t
_W64 unsigned int uintptr_t
static void Reorder(GraphCycles::Rep *r)
static void Sort(const Vec< Node * > &, Vec< int32_t > *delta)
static constexpr uint32_t kHashTableSize
static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, upb_value val, uint32_t hash, hashfunc_t *hashfunc, eqlfunc_t *eql)
constexpr size_t Find(Needle, Needle, Ts...)
static bool ForwardDFS(GraphCycles::Rep *r, int32_t n, int32_t upper_bound)
#define HASH_FOR_EACH(elem, eset)
Vec< int32_t > free_nodes_
static int contains(grpc_timer_heap *pq, grpc_timer *el)
def merge(callgrind_files, srcs)
#define ABSL_RAW_LOG(severity,...)
int FindPath(GraphId source, GraphId dest, int max_path_len, GraphId path[]) const
static void * AllocWithArena(size_t request, Arena *arena) ABSL_ATTRIBUTE_SECTION(malloc_hook)
absl::hash_internal::Hash< T > Hash
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:44