libostree: Rework OstreeAsyncProgress to use GVariants internally

OstreeAsyncProgress currently does some contortions to try and avoid
allocating space for guints and guint64s (on 64-bit platforms), but this
means it uses two GHashTables. A GHashTable allocates 8 buckets even
when empty. Given that the largest usage of OstreeAsyncProgress in
libostree puts 13 uints and 5 uint64s in it, this optimisation does not
save significant (if any) memory.

Instead, change OstreeAsyncProgress to store values internally as
GVariants, and expose this with some new API:
 • ostree_async_progress_get_variant()
 • ostree_async_progress_set_variant()
Each GVariant is allocated on the heap. As they are immutable, they are
thread-safe once returned by a getter.

The existing API continues to work as before, except in the case where a
key is set/got as both a uint and a uint64 — there will now be a
collision (and a GVariant type checking failure) whereas previously
there was no collision. Nothing in OSTree uses OstreeAsyncProgress this
way though.

The new API can be used to share more complex data via the progress API.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #819
Approved by: cgwalters
This commit is contained in:
Philip Withnall authored and Atomic Bot committed 2017-04-29 11:50:15 +00:00
1 parent e60b9bc049
commit f74e52a3a0
4 files changed
+81 -65

No files matched your search

+7
View File
@@ -59,6 +59,9 @@ guint ostree_async_progress_get_uint (OstreeAsyncProgress *self,
_OSTREE_PUBLIC
guint64 ostree_async_progress_get_uint64 (OstreeAsyncProgress *self,
const char *key);
_OSTREE_PUBLIC
GVariant *ostree_async_progress_get_variant (OstreeAsyncProgress *self,
const char *key);
_OSTREE_PUBLIC
void ostree_async_progress_set_status (OstreeAsyncProgress *self,
@@ -72,6 +75,10 @@ _OSTREE_PUBLIC
void ostree_async_progress_set_uint64 (OstreeAsyncProgress *self,
const char *key,
guint64 value);
_OSTREE_PUBLIC
void ostree_async_progress_set_variant (OstreeAsyncProgress *self,
const char *key,
GVariant *value);
_OSTREE_PUBLIC
void ostree_async_progress_finish (OstreeAsyncProgress *self);