Commit 65385d32 authored by Matthias Klumpp's avatar Matthias Klumpp
Browse files

Make some operations in AsContext atomic

This doesn *not* make access to the class threadsafe though! All
retrieved pointers may still be able to change. This is a bit dangerous,
so ideally any AsContext class should be initialized once and then never
be modified again.
In future, in case people really use this in a multithreaded
environment, it may be useful to add a sealing mechanism to this class.
parent b13dc5a5
...@@ -101,7 +101,7 @@ AsFormatVersion ...@@ -101,7 +101,7 @@ AsFormatVersion
as_context_get_format_version (AsContext *ctx) as_context_get_format_version (AsContext *ctx)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
return priv->format_version; return g_atomic_int_get (&priv->format_version);
} }
/** /**
...@@ -115,7 +115,7 @@ void ...@@ -115,7 +115,7 @@ void
as_context_set_format_version (AsContext *ctx, AsFormatVersion ver) as_context_set_format_version (AsContext *ctx, AsFormatVersion ver)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
priv->format_version = ver; g_atomic_int_set (&priv->format_version, ver);
} }
/** /**
...@@ -128,7 +128,7 @@ AsFormatStyle ...@@ -128,7 +128,7 @@ AsFormatStyle
as_context_get_style (AsContext *ctx) as_context_get_style (AsContext *ctx)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
return priv->style; return g_atomic_int_get (&priv->style);
} }
/** /**
...@@ -142,7 +142,7 @@ void ...@@ -142,7 +142,7 @@ void
as_context_set_style (AsContext *ctx, AsFormatStyle style) as_context_set_style (AsContext *ctx, AsFormatStyle style)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
priv->style = style; g_atomic_int_set (&priv->style, style);
} }
/** /**
...@@ -155,7 +155,7 @@ gint ...@@ -155,7 +155,7 @@ gint
as_context_get_priority (AsContext *ctx) as_context_get_priority (AsContext *ctx)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
return priv->priority; return g_atomic_int_get (&priv->priority);
} }
/** /**
...@@ -169,7 +169,7 @@ void ...@@ -169,7 +169,7 @@ void
as_context_set_priority (AsContext *ctx, gint priority) as_context_set_priority (AsContext *ctx, gint priority)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
priv->priority = priority; g_atomic_int_set (&priv->priority, priority);
} }
/** /**
...@@ -226,9 +226,9 @@ as_context_set_locale (AsContext *ctx, const gchar *value) ...@@ -226,9 +226,9 @@ as_context_set_locale (AsContext *ctx, const gchar *value)
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
g_free (priv->locale); g_free (priv->locale);
priv->all_locale = FALSE; g_atomic_int_set (&priv->all_locale, FALSE);
if (g_strcmp0 (value, "ALL") == 0) { if (g_strcmp0 (value, "ALL") == 0) {
priv->all_locale = TRUE; g_atomic_int_set (&priv->all_locale, TRUE);
priv->locale = as_get_current_locale (); priv->locale = as_get_current_locale ();
} else { } else {
priv->locale = g_strdup (value); priv->locale = g_strdup (value);
...@@ -236,16 +236,16 @@ as_context_set_locale (AsContext *ctx, const gchar *value) ...@@ -236,16 +236,16 @@ as_context_set_locale (AsContext *ctx, const gchar *value)
} }
/** /**
* as_context_get_all_locale_enabled: * as_context_get_locale_all_enabled:
* @ctx: a #AsContext instance. * @ctx: a #AsContext instance.
* *
* Returns: %TRUE if all locale should be parsed. * Returns: %TRUE if all locale should be parsed.
**/ **/
gboolean gboolean
as_context_get_all_locale_enabled (AsContext *ctx) as_context_get_locale_all_enabled (AsContext *ctx)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
return priv->all_locale; return g_atomic_int_get (&priv->all_locale);
} }
/** /**
...@@ -355,7 +355,7 @@ gboolean ...@@ -355,7 +355,7 @@ gboolean
as_context_get_internal_mode (AsContext *ctx) as_context_get_internal_mode (AsContext *ctx)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
return priv->internal_mode; return g_atomic_int_get (&priv->internal_mode);
} }
/** /**
...@@ -371,7 +371,7 @@ void ...@@ -371,7 +371,7 @@ void
as_context_set_internal_mode (AsContext *ctx, gboolean enabled) as_context_set_internal_mode (AsContext *ctx, gboolean enabled)
{ {
AsContextPrivate *priv = GET_PRIVATE (ctx); AsContextPrivate *priv = GET_PRIVATE (ctx);
priv->internal_mode = enabled; g_atomic_int_set (&priv->internal_mode, enabled);
} }
/** /**
......
...@@ -72,7 +72,7 @@ const gchar *as_context_get_media_baseurl (AsContext *ctx); ...@@ -72,7 +72,7 @@ const gchar *as_context_get_media_baseurl (AsContext *ctx);
void as_context_set_media_baseurl (AsContext *ctx, void as_context_set_media_baseurl (AsContext *ctx,
const gchar *value); const gchar *value);
gboolean as_context_get_all_locale_enabled (AsContext *ctx); gboolean as_context_get_locale_all_enabled (AsContext *ctx);
const gchar *as_context_get_filename (AsContext *ctx); const gchar *as_context_get_filename (AsContext *ctx);
void as_context_set_filename (AsContext *ctx, void as_context_set_filename (AsContext *ctx,
......
...@@ -63,7 +63,7 @@ as_xml_get_node_locale_match (AsContext *ctx, xmlNode *node) ...@@ -63,7 +63,7 @@ as_xml_get_node_locale_match (AsContext *ctx, xmlNode *node)
goto out; goto out;
} }
if (as_context_get_all_locale_enabled (ctx)) { if (as_context_get_locale_all_enabled (ctx)) {
/* we should read all languages */ /* we should read all languages */
goto out; goto out;
} }
......
...@@ -456,7 +456,7 @@ as_yaml_get_node_locale (AsContext *ctx, GNode *node) ...@@ -456,7 +456,7 @@ as_yaml_get_node_locale (AsContext *ctx, GNode *node)
{ {
const gchar *key = as_yaml_node_get_key (node); const gchar *key = as_yaml_node_get_key (node);
if (as_context_get_all_locale_enabled (ctx)) { if (as_context_get_locale_all_enabled (ctx)) {
/* we should read all languages */ /* we should read all languages */
return key; return key;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment