mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof: add rwlock for symbol cache
This is necessary so we can start looking at threading symbolizers.
This commit is contained in:
@ -42,6 +42,7 @@ struct _SysprofSymbolCacheNode
|
||||
struct _SysprofSymbolCache
|
||||
{
|
||||
GObject parent_instance;
|
||||
GRWLock rwlock;
|
||||
RB_HEAD(sysprof_symbol_cache, _SysprofSymbolCacheNode) head;
|
||||
};
|
||||
|
||||
@ -104,6 +105,8 @@ sysprof_symbol_cache_finalize (GObject *object)
|
||||
if (node != NULL)
|
||||
sysprof_symbol_cache_node_free (node);
|
||||
|
||||
g_rw_lock_clear (&self->rwlock);
|
||||
|
||||
G_OBJECT_CLASS (sysprof_symbol_cache_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
@ -118,6 +121,7 @@ sysprof_symbol_cache_class_init (SysprofSymbolCacheClass *klass)
|
||||
static void
|
||||
sysprof_symbol_cache_init (SysprofSymbolCache *self)
|
||||
{
|
||||
g_rw_lock_init (&self->rwlock);
|
||||
RB_INIT (&self->head);
|
||||
}
|
||||
|
||||
@ -154,11 +158,14 @@ sysprof_symbol_cache_take (SysprofSymbolCache *self,
|
||||
node->high = symbol->end_address-1;
|
||||
node->max = node->high;
|
||||
|
||||
g_rw_lock_writer_lock (&self->rwlock);
|
||||
|
||||
/* If there is a collision, then the node is returned. Otherwise
|
||||
* if the node was inserted, NULL is returned.
|
||||
*/
|
||||
if ((ret = RB_INSERT(sysprof_symbol_cache, &self->head, node)))
|
||||
{
|
||||
g_rw_lock_writer_unlock (&self->rwlock);
|
||||
sysprof_symbol_cache_node_free (node);
|
||||
return;
|
||||
}
|
||||
@ -172,6 +179,8 @@ sysprof_symbol_cache_take (SysprofSymbolCache *self,
|
||||
node = parent;
|
||||
parent = RB_PARENT(parent, link);
|
||||
}
|
||||
|
||||
g_rw_lock_writer_unlock (&self->rwlock);
|
||||
}
|
||||
|
||||
SysprofSymbol *
|
||||
@ -185,6 +194,8 @@ sysprof_symbol_cache_lookup (SysprofSymbolCache *self,
|
||||
if (address == 0)
|
||||
return NULL;
|
||||
|
||||
g_rw_lock_reader_lock (&self->rwlock);
|
||||
|
||||
node = RB_ROOT(&self->head);
|
||||
|
||||
/* The root node contains our calculated max as augmented in RBTree.
|
||||
@ -192,7 +203,10 @@ sysprof_symbol_cache_lookup (SysprofSymbolCache *self,
|
||||
* in O(1) without having to add a branch to the while loop below.
|
||||
*/
|
||||
if (node == NULL || node->max < address)
|
||||
return NULL;
|
||||
{
|
||||
g_rw_lock_reader_unlock (&self->rwlock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (node != NULL)
|
||||
{
|
||||
@ -202,7 +216,10 @@ sysprof_symbol_cache_lookup (SysprofSymbolCache *self,
|
||||
node->max >= RB_RIGHT(node, link)->max);
|
||||
|
||||
if (address >= node->low && address <= node->high)
|
||||
return node->symbol;
|
||||
{
|
||||
g_rw_lock_reader_unlock (&self->rwlock);
|
||||
return node->symbol;
|
||||
}
|
||||
|
||||
if (RB_LEFT(node, link) && RB_LEFT(node, link)->max >= address)
|
||||
node = RB_LEFT(node, link);
|
||||
@ -210,6 +227,8 @@ sysprof_symbol_cache_lookup (SysprofSymbolCache *self,
|
||||
node = RB_RIGHT(node, link);
|
||||
}
|
||||
|
||||
g_rw_lock_reader_unlock (&self->rwlock);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user