summaryrefslogtreecommitdiff
path: root/upb/refcounted.h
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2013-10-24 12:43:19 -0700
committerJosh Haberman <jhaberman@gmail.com>2013-10-24 12:43:19 -0700
commit26d98ca94f2f049e8767b4a9a33d185a3d7ea0fd (patch)
tree340bcf495f06ed05c9f3fb423f210caf4edce2b1 /upb/refcounted.h
parent61109fca1f967771c21dc7184aee35f3b439c577 (diff)
Merge from Google-internal development:
- rewritten decoder; interpreted decoder is bytecode-based, JIT decoder no longer falls back to the interpreter. - C++ improvements: C++11-compatible iterators, upb::reffed_ptr for RAII refcounting, better upcast/downcast support. - removed the gross upb_value abstraction from public upb.h.
Diffstat (limited to 'upb/refcounted.h')
-rw-r--r--upb/refcounted.h22
1 files changed, 17 insertions, 5 deletions
diff --git a/upb/refcounted.h b/upb/refcounted.h
index 19993ca..a0d535a 100644
--- a/upb/refcounted.h
+++ b/upb/refcounted.h
@@ -19,7 +19,7 @@
#ifndef UPB_REFCOUNTED_H_
#define UPB_REFCOUNTED_H_
-#include "upb/table.h"
+#include "upb/table.int.h"
// Reference tracking is designed to be used with a tool like Valgrind; when
// enabled, it will cause reference leaks to show up as actual memory leaks
@@ -86,6 +86,11 @@ struct upb_refcounted {
uint32_t individual_count;
bool is_frozen;
+
+#ifdef UPB_DEBUG_REFS
+ upb_inttable *refs; // Maps owner -> trackedref for incoming refs.
+ upb_inttable *ref2s; // Set of targets for outgoing ref2s.
+#endif
};
// Native C API.
@@ -137,8 +142,9 @@ void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from);
// Freezes all mutable object reachable by ref2() refs from the given roots.
// This will split refcounting groups into precise SCC groups, so that
// refcounting of frozen objects can be more aggressive. If memory allocation
-// fails or if more than 2**31 mutable objects are reachable from "roots",
-// false is returned and the objects are unchanged.
+// fails, or if more than 2**31 mutable objects are reachable from "roots", or
+// if the maximum depth of the graph exceeds "maxdepth", false is returned and
+// the objects are unchanged.
//
// After this operation succeeds, the objects are frozen/const, and may not be
// used through non-const pointers. In particular, they may not be passed as
@@ -147,12 +153,18 @@ void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from);
// at the precise moment that they become unreachable.
//
// Caller must own refs on each object in the "roots" list.
-bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s);
+bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s,
+ int maxdepth);
// Shared by all compiled-in refcounted objects.
extern uint32_t static_refcount;
-#define UPB_REFCOUNT_INIT {&static_refcount, NULL, NULL, 0, true}
+#ifdef UPB_DEBUG_REFS
+#define UPB_REFCOUNT_INIT(refs, ref2s) \
+ {&static_refcount, NULL, NULL, 0, true, refs, ref2s}
+#else
+#define UPB_REFCOUNT_INIT(refs, ref2s) {&static_refcount, NULL, NULL, 0, true}
+#endif
#ifdef __cplusplus
} /* extern "C" */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback