From 1e82f0ebd6ae0de251ec6c3cac0544d96d973f1b Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 15 Aug 2009 22:10:07 -0700 Subject: A few more thread-safety fixes. --- src/upb_context.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/upb_context.c') diff --git a/src/upb_context.c b/src/upb_context.c index 0001a98..931a6fb 100644 --- a/src/upb_context.c +++ b/src/upb_context.c @@ -82,13 +82,24 @@ void upb_context_unref(struct upb_context *c) upb_rwlock_destroy(&c->lock); } -struct upb_symtab_entry *upb_context_lookup(struct upb_context *c, - struct upb_string *symbol) +bool upb_context_lookup(struct upb_context *c, struct upb_string *symbol, + struct upb_symtab_entry *out_entry) { upb_rwlock_rdlock(&c->lock); struct upb_symtab_entry *e = upb_strtable_lookup(&c->symtab, symbol); + if(e) *out_entry = *e; + upb_rwlock_unlock(&c->lock); + return e != NULL; +} + +void upb_context_enumerate(struct upb_context *c, upb_context_enumerator_t cb, + void *udata) +{ + upb_rwlock_rdlock(&c->lock); + struct upb_symtab_entry *e = upb_strtable_begin(&c->symtab); + for(; e; e = upb_strtable_next(&c->symtab, &e->e)) + cb(udata, e); upb_rwlock_unlock(&c->lock); - return e; } /* Given a symbol and the base symbol inside which it is defined, find the @@ -139,13 +150,14 @@ union upb_symbol_ref resolve2(struct upb_strtable *t1, struct upb_strtable *t2, } -struct upb_symtab_entry *upb_context_resolve(struct upb_context *c, - struct upb_string *base, - struct upb_string *symbol) { +bool upb_context_resolve(struct upb_context *c, struct upb_string *base, + struct upb_string *symbol, + struct upb_symtab_entry *out_entry) { upb_rwlock_rdlock(&c->lock); struct upb_symtab_entry *e = resolve(&c->symtab, base, symbol); + if(e) *out_entry = *e; upb_rwlock_unlock(&c->lock); - return e; + return e != NULL; } /* Joins strings together, for example: -- cgit v1.2.3