// Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd #ifndef UPB_MEM_INTERNAL_ARENA_H_ #define UPB_MEM_INTERNAL_ARENA_H_ #include "upb/mem/arena.h" // Must be last. #include "upb/port/def.inc" typedef struct _upb_MemBlock _upb_MemBlock; // LINT.IfChange(struct_definition) struct upb_Arena { _upb_ArenaHead head; // upb_alloc* together with a low bit which signals if there is an initial // block. uintptr_t block_alloc; // When multiple arenas are fused together, each arena points to a parent // arena (root points to itself). The root tracks how many live arenas // reference it. // The low bit is tagged: // 0: pointer to parent // 1: count, left shifted by one UPB_ATOMIC(uintptr_t) parent_or_count; // All nodes that are fused together are in a singly-linked list. UPB_ATOMIC(upb_Arena*) next; // NULL at end of list. // The last element of the linked list. This is present only as an // optimization, so that we do not have to iterate over all members for every // fuse. Only significant for an arena root. In other cases it is ignored. UPB_ATOMIC(upb_Arena*) tail; // == self when no other list members. // Linked list of blocks to free/cleanup. Atomic only for the benefit of // upb_Arena_SpaceAllocated(). UPB_ATOMIC(_upb_MemBlock*) blocks; }; // LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts) #include "upb/port/undef.inc" #endif /* UPB_MEM_INTERNAL_ARENA_H_ */