gutils: use atomic pointers for g_prgname

The mutex is not necessary to guard a single pointer.
This commit is contained in:
Thomas Haller 2023-11-08 08:27:20 +01:00
parent 74502f51a6
commit 167deee94d

View File

@ -1128,7 +1128,6 @@ g_get_host_name (void)
return hostname; return hostname;
} }
G_LOCK_DEFINE_STATIC (g_prgname);
static const gchar *g_prgname = NULL; /* always a quark */ static const gchar *g_prgname = NULL; /* always a quark */
/** /**
@ -1150,13 +1149,7 @@ static const gchar *g_prgname = NULL; /* always a quark */
const gchar* const gchar*
g_get_prgname (void) g_get_prgname (void)
{ {
const gchar* retval; return g_atomic_pointer_get (&g_prgname);
G_LOCK (g_prgname);
retval = g_prgname;
G_UNLOCK (g_prgname);
return retval;
} }
/** /**
@ -1179,10 +1172,8 @@ g_get_prgname (void)
void void
g_set_prgname (const gchar *prgname) g_set_prgname (const gchar *prgname)
{ {
GQuark qprgname = g_quark_from_string (prgname); prgname = g_intern_string (prgname);
G_LOCK (g_prgname); g_atomic_pointer_set (&g_prgname, prgname);
g_prgname = g_quark_to_string (qprgname);
G_UNLOCK (g_prgname);
} }
G_LOCK_DEFINE_STATIC (g_application_name); G_LOCK_DEFINE_STATIC (g_application_name);