Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsComponent: Centralize GOnce guard to fix an assertion failure #385

Merged
merged 2 commits into from Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -67,7 +67,6 @@ const gchar *as_component_get_architecture (AsComponent *cpt);
void as_component_set_architecture (AsComponent *cpt,
const gchar *arch);

void as_component_create_token_cache (AsComponent *cpt);
GPtrArray *as_component_generate_tokens_for (AsComponent *cpt,
AsSearchTokenMatch token_kind);

@@ -2861,13 +2861,13 @@ as_component_create_token_cache_target (AsComponent *cpt, AsComponent *donor, gu
*
* Internal API.
*/
void
static void
as_component_create_token_cache (AsComponent *cpt)
{
AsComponentPrivate *priv = GET_PRIVATE (cpt);
guint flags;

if (priv->token_cache_valid)
if (!g_once_init_enter (&priv->token_cache_valid))
return;

flags = AS_SEARCH_TOKEN_MATCH_MEDIATYPE |
@@ -2886,7 +2886,7 @@ as_component_create_token_cache (AsComponent *cpt)
as_component_create_token_cache_target (cpt, donor, flags, NULL);
}

priv->token_cache_valid = TRUE;
g_once_init_leave (&priv->token_cache_valid, TRUE);
}

/**
@@ -2937,10 +2937,7 @@ as_component_search_matches (AsComponent *cpt, const gchar *term)
return 0;

/* ensure the token cache is created */
if (g_once_init_enter (&priv->token_cache_valid)) {
as_component_create_token_cache (cpt);
g_once_init_leave (&priv->token_cache_valid, TRUE);
}
as_component_create_token_cache (cpt);

/* find the exact match (which is more awesome than a partial match) */
match_pval = g_hash_table_lookup (priv->token_cache, term);
@@ -3022,10 +3019,7 @@ as_component_get_search_tokens (AsComponent *cpt)
g_autoptr(GList) keys = NULL;

/* ensure the token cache is created */
if (g_once_init_enter (&priv->token_cache_valid)) {
as_component_create_token_cache (cpt);
g_once_init_leave (&priv->token_cache_valid, TRUE);
}
as_component_create_token_cache (cpt);

/* return all the token cache */
keys = g_hash_table_get_keys (priv->token_cache);