From d7df8c415b6914886cfe6387615dbd9e75da35bf Mon Sep 17 00:00:00 2001 From: theraven Date: Mon, 14 Jan 2013 16:06:38 +0000 Subject: [PATCH] Move the selector table to being protected by a mutex for reads so that we can recover memory from the smaller ones. Selector lookups are not on the critical path for message sends, so the cost of the extra memory is likely to be larger than the cost of acquiring a lock in sel_getName(). --- hash_table.h | 1 + selector_table.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/hash_table.h b/hash_table.h index e064af1..951bd2d 100644 --- a/hash_table.h +++ b/hash_table.h @@ -199,6 +199,7 @@ static int PREFIX(_table_resize)(PREFIX(_table) *table) __sync_synchronize(); table->old = NULL; # if !defined(ENABLE_GC) && defined(MAP_TABLE_SINGLE_THREAD) + free(copy->table); free(copy); # endif return 1; diff --git a/selector_table.c b/selector_table.c index d75e1c4..c2629cf 100644 --- a/selector_table.c +++ b/selector_table.c @@ -211,6 +211,7 @@ static inline uint32_t hash_selector(const void *s) } #define MAP_TABLE_NAME selector +#define MAP_TABLE_SINGLE_THREAD #define MAP_TABLE_COMPARE_FUNCTION selector_identical #define MAP_TABLE_HASH_KEY hash_selector #define MAP_TABLE_HASH_VALUE hash_selector @@ -245,6 +246,7 @@ PRIVATE void init_selector_tables() static SEL selector_lookup(const char *name, const char *types) { struct objc_selector sel = {{name}, types}; + LOCK_FOR_SCOPE(&selector_table_lock); return selector_table_get(sel_table, &sel); } static inline void add_selector_to_table(SEL aSel, int32_t uid, uint32_t idx)