gdatetime: Fix incorrect alt-digits being used after changing locale
The alt-digits are loaded from nl_langinfo()
in a GOnce
section,
which means nl_langinfo()
is not re-queried after the process changes
locale (if that happens).
So, change the GOnce
to a mutex and store the locale of the alt-digits
alongside them. This will introduce contention when calling
format_number()
is called, but how often are multiple threads trying
to format dates at the same time?
If this does get highlighted as a performance problem, the other
approach I considered was a GPrivate
struct containing all the
locale-specific cached data. That comes at the cost of using a
GPrivate
slot (although that’s only particularly expensive on Windows,
and the locale code is quite different for Windows, so perhaps that
could be avoided entirely). It does mean that all locale printing could
be lock-free and still safely update cached data on a locale change.
Signed-off-by: Philip Withnall pwithnall@endlessos.org