1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-07-04 22:35:36 +02:00

(cache_match): Remove locking comments.

(ia64_get_cached_proc_info): Rename from ia64_script_lookup() and modify it so
	it directly updates the proc-info if the necessary script is in the cache.
(script_new): Remove locking comments and adjust formatting.
(ia64_find_save_locs): If global caching is enabled, mask signal delivery and
	hold the cache lock while accessing the cache.
(ia64_script_cache_init): Initialize the cache lock.


(Logical change 1.59)
This commit is contained in:
mostang.com!davidm 2003-03-06 06:14:36 +00:00
parent a6e367131b
commit d3ec5e94aa

View file

@ -43,11 +43,8 @@ hash (unw_word_t ip)
static inline long static inline long
cache_match (struct ia64_script *script, unw_word_t ip, unw_word_t pr) cache_match (struct ia64_script *script, unw_word_t ip, unw_word_t pr)
{ {
/* XXX lock script cache */
if (ip == script->ip && ((pr ^ script->pr_val) & script->pr_mask) == 0) if (ip == script->ip && ((pr ^ script->pr_val) & script->pr_mask) == 0)
/* keep the lock... */
return 1; return 1;
/* XXX unlock script cache */
return 0; return 0;
} }
@ -111,13 +108,33 @@ script_lookup (struct ia64_script_cache *cache, struct cursor *c)
} }
} }
HIDDEN struct ia64_script * HIDDEN int
ia64_script_lookup (struct cursor *c) ia64_get_cached_proc_info (struct cursor *c)
{ {
return script_lookup (get_script_cache (c->as), c); int global_cache = (c->as->caching_policy == UNW_CACHE_GLOBAL);
struct ia64_script_cache *cache;
struct ia64_script *script;
sigset_t saved_sigmask;
cache = get_script_cache (c->as);
if (likely (global_cache))
{
sigprocmask (SIG_SETMASK, &unwi_full_sigmask, &saved_sigmask);
mutex_lock (&cache->lock);
} }
/* On returning, the lock for the SCRIPT is still being held. */ script = script_lookup (cache, c);
if (script)
c->pi = script->pi;
if (likely (global_cache))
{
mutex_unlock (&cache->lock);
sigprocmask (SIG_SETMASK, &saved_sigmask, NULL);
}
return script ? 0 : -UNW_ENOINFO;
}
static inline struct ia64_script * static inline struct ia64_script *
script_new (struct ia64_script_cache *cache, unw_word_t ip) script_new (struct ia64_script_cache *cache, unw_word_t ip)
@ -126,20 +143,10 @@ script_new (struct ia64_script_cache *cache, unw_word_t ip)
unw_hash_index_t index; unw_hash_index_t index;
unsigned short head; unsigned short head;
/* XXX lock hash table */
{
head = cache->lru_head; head = cache->lru_head;
script = cache->buckets + head; script = cache->buckets + head;
cache->lru_head = script->lru_chain; cache->lru_head = script->lru_chain;
}
/* XXX unlock hash table */
/* XXX We'll deadlock here if we interrupt a thread that is holding
the script->lock. */
/* XXX lock script */
/* XXX lock unwind data lock */
{
/* re-insert script at the tail of the LRU chain: */ /* re-insert script at the tail of the LRU chain: */
cache->buckets[cache->lru_tail].lru_chain = head; cache->buckets[cache->lru_tail].lru_chain = head;
cache->lru_tail = head; cache->lru_tail = head;
@ -174,10 +181,7 @@ script_new (struct ia64_script_cache *cache, unw_word_t ip)
script->coll_chain = cache->hash[index]; script->coll_chain = cache->hash[index];
cache->hash[index] = script - cache->buckets; cache->hash[index] = script - cache->buckets;
script->ip = ip; /* set new IP while we're holding the locks */ script->ip = ip;
}
/* XXX unlock unwind data lock */
script->hint = 0; script->hint = 0;
script->count = 0; script->count = 0;
return script; return script;
@ -474,9 +478,20 @@ run_script (struct ia64_script *script, struct cursor *c)
HIDDEN int HIDDEN int
ia64_find_save_locs (struct cursor *c) ia64_find_save_locs (struct cursor *c)
{ {
int global_cache = (c->as->caching_policy == UNW_CACHE_GLOBAL);
struct ia64_script_cache *cache = NULL;
struct ia64_script *script = NULL; struct ia64_script *script = NULL;
sigset_t saved_sigmask;
int ret = 0; int ret = 0;
cache = get_script_cache (c->as);
if (likely (global_cache))
{
sigprocmask (SIG_SETMASK, &unwi_full_sigmask, &saved_sigmask);
mutex_lock (&cache->lock);
}
if (c->as->caching_policy == UNW_CACHE_NONE) if (c->as->caching_policy == UNW_CACHE_NONE)
{ {
struct ia64_script tmp_script; struct ia64_script tmp_script;
@ -489,8 +504,6 @@ ia64_find_save_locs (struct cursor *c)
} }
else else
{ {
struct ia64_script_cache *cache = get_script_cache (c->as);
script = script_lookup (cache, c); script = script_lookup (cache, c);
if (!script) if (!script)
{ {
@ -498,7 +511,8 @@ ia64_find_save_locs (struct cursor *c)
if (!script) if (!script)
{ {
dprintf ("%s: failed to create unwind script\n", __FUNCTION__); dprintf ("%s: failed to create unwind script\n", __FUNCTION__);
return -UNW_EUNSPEC; ret = -UNW_EUNSPEC;
goto out;
} }
cache->buckets[c->prev_script].hint = script - cache->buckets; cache->buckets[c->prev_script].hint = script - cache->buckets;
@ -512,10 +526,18 @@ ia64_find_save_locs (struct cursor *c)
if (ret != UNW_ESTOPUNWIND) if (ret != UNW_ESTOPUNWIND)
dprintf ("%s: failed to locate/build unwind script for ip %lx\n", dprintf ("%s: failed to locate/build unwind script for ip %lx\n",
__FUNCTION__, (long) c->ip); __FUNCTION__, (long) c->ip);
return ret; goto out;
} }
run_script (script, c); run_script (script, c);
return 0;
out:
if (likely (global_cache))
{
mutex_unlock (&cache->lock);
sigprocmask (SIG_SETMASK, &saved_sigmask, NULL);
}
return ret;
} }
HIDDEN void HIDDEN void
@ -523,6 +545,7 @@ ia64_script_cache_init (struct ia64_script_cache *cache)
{ {
int i; int i;
mutex_init (&cache->lock);
cache->lru_head = IA64_UNW_CACHE_SIZE - 1; cache->lru_head = IA64_UNW_CACHE_SIZE - 1;
cache->lru_tail = 0; cache->lru_tail = 0;
@ -531,10 +554,6 @@ ia64_script_cache_init (struct ia64_script_cache *cache)
if (i > 0) if (i > 0)
cache->buckets[i].lru_chain = (i - 1); cache->buckets[i].lru_chain = (i - 1);
cache->buckets[i].coll_chain = -1; cache->buckets[i].coll_chain = -1;
#if 0
/* must be lock-free! */
unw.cache[i].lock = RW_LOCK_UNLOCKED;
#endif
} }
for (i = 0; i<IA64_UNW_HASH_SIZE; ++i) for (i = 0; i<IA64_UNW_HASH_SIZE; ++i)
cache->hash[i] = -1; cache->hash[i] = -1;