mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
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:
@ -2102,29 +2102,41 @@ _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);
|
||||
|
||||
if (!(ret = g_hash_table_lookup (self->tid_to_symbol, GINT_TO_POINTER (tid))))
|
||||
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)
|
||||
{
|
||||
char pidstr[32];
|
||||
char tidstr[32];
|
||||
g_rw_lock_writer_lock (&rwlock);
|
||||
|
||||
g_snprintf (pidstr, sizeof pidstr, "(%d)", pid);
|
||||
if (!(ret = g_hash_table_lookup (self->tid_to_symbol, GINT_TO_POINTER (tid))))
|
||||
{
|
||||
char pidstr[32];
|
||||
char tidstr[32];
|
||||
|
||||
if (tid == pid)
|
||||
g_snprintf (tidstr, sizeof tidstr, "Thread-%d (Main)", tid);
|
||||
else
|
||||
g_snprintf (tidstr, sizeof tidstr, "Thread-%d", tid);
|
||||
g_snprintf (pidstr, sizeof pidstr, "(%d)", pid);
|
||||
|
||||
ret = _sysprof_symbol_new (g_ref_string_new (tidstr),
|
||||
NULL,
|
||||
g_ref_string_new (pidstr),
|
||||
0, 0,
|
||||
SYSPROF_SYMBOL_KIND_THREAD);
|
||||
if (tid == pid)
|
||||
g_snprintf (tidstr, sizeof tidstr, "Thread-%d (Main)", tid);
|
||||
else
|
||||
g_snprintf (tidstr, sizeof tidstr, "Thread-%d", tid);
|
||||
|
||||
g_hash_table_insert (self->tid_to_symbol, GINT_TO_POINTER (tid), ret);
|
||||
ret = _sysprof_symbol_new (g_ref_string_new (tidstr),
|
||||
NULL,
|
||||
g_ref_string_new (pidstr),
|
||||
0, 0,
|
||||
SYSPROF_SYMBOL_KIND_THREAD);
|
||||
|
||||
g_hash_table_insert (self->tid_to_symbol, GINT_TO_POINTER (tid), ret);
|
||||
}
|
||||
|
||||
g_rw_lock_writer_unlock (&rwlock);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user