summaryrefslogtreecommitdiff
path: root/src/upb_msg.h
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-08-15 20:20:28 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-08-15 20:20:28 -0700
commit71d82d06d17f0205ccf5bb72ea11d3fd3e9eb363 (patch)
treef2f48d548ce83043abdb4048697c4d0d6ba18b1c /src/upb_msg.h
parent2282d2489bd8db3cd4ddbe0dd813732bffcf6452 (diff)
Add refcounting and thread-safety to message definitions.
Diffstat (limited to 'src/upb_msg.h')
-rw-r--r--src/upb_msg.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/upb_msg.h b/src/upb_msg.h
index e2b6903..2ae3f59 100644
--- a/src/upb_msg.h
+++ b/src/upb_msg.h
@@ -54,8 +54,10 @@
#include <stdint.h>
#include "upb.h"
-#include "upb_table.h"
+#include "upb_atomic.h"
+#include "upb_context.h"
#include "upb_parse.h"
+#include "upb_table.h"
#ifdef __cplusplus
extern "C" {
@@ -66,6 +68,8 @@ extern "C" {
struct upb_msg_fielddef;
/* Structure that describes a single .proto message type. */
struct upb_msgdef {
+ upb_atomic_refcount_t refcount;
+ struct upb_context *context;
struct google_protobuf_DescriptorProto *descriptor;
struct upb_string fqname; /* Fully qualified. */
size_t size;
@@ -92,6 +96,14 @@ struct upb_msg_fielddef {
upb_label_t label;
};
+INLINE void upb_msgdef_ref(struct upb_msgdef *m) {
+ if(upb_atomic_ref(&m->refcount)) upb_context_ref(m->context);
+}
+
+INLINE void upb_msgdef_unref(struct upb_msgdef *m) {
+ if(upb_atomic_unref(&m->refcount)) upb_context_unref(m->context);
+}
+
INLINE bool upb_issubmsg(struct upb_msg_fielddef *f) {
return upb_issubmsgtype(f->type);
}
@@ -379,7 +391,8 @@ void upb_msg_print(struct upb_msg *data, bool single_line, FILE *stream);
* header for this type that expects the given order. */
bool upb_msgdef_init(struct upb_msgdef *m,
struct google_protobuf_DescriptorProto *d,
- struct upb_string fqname, bool sort);
+ struct upb_string fqname, bool sort,
+ struct upb_context *c);
void upb_msgdef_free(struct upb_msgdef *m);
/* Sort the given field descriptors in-place, according to what we think is an
@@ -391,8 +404,8 @@ void upb_msgdef_sortfds(google_protobuf_FieldDescriptorProto **fds, size_t num);
* the "ref" field in the upb_msg_fielddef. Since messages can refer to each
* other in mutually-recursive ways, this step must be separated from
* initialization. */
-void upb_msgdef_ref(struct upb_msgdef *m, struct upb_msg_fielddef *f,
- union upb_symbol_ref ref);
+void upb_msgdef_setref(struct upb_msgdef *m, struct upb_msg_fielddef *f,
+ union upb_symbol_ref ref);
#ifdef __cplusplus
} /* extern "C" */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback