libsysprof: synchronize access to tid symbols hashtable

This can get mutated after the document is loaded, so we need to
synchronize access to it.
This commit is contained in:
Christian Hergert
2023-08-06 02:18:43 -07:00
parent 9cbfc21363
commit fe4995cf1f

View File

@ -2102,10 +2102,19 @@ _sysprof_document_thread_symbol (SysprofDocument *self,
int pid,
int tid)
{
static GRWLock rwlock;
SysprofSymbol *ret;
g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL);
g_rw_lock_reader_lock (&rwlock);
ret = g_hash_table_lookup (self->tid_to_symbol, GINT_TO_POINTER (tid));
g_rw_lock_reader_unlock (&rwlock);
if (ret == NULL)
{
g_rw_lock_writer_lock (&rwlock);
if (!(ret = g_hash_table_lookup (self->tid_to_symbol, GINT_TO_POINTER (tid))))
{
char pidstr[32];
@ -2127,6 +2136,9 @@ _sysprof_document_thread_symbol (SysprofDocument *self,
g_hash_table_insert (self->tid_to_symbol, GINT_TO_POINTER (tid), ret);
}
g_rw_lock_writer_unlock (&rwlock);
}
return ret;
}