gtask: Compress GTask struct using a bitfield

There are a lot of gbooleans in the private GTask struct, which seems a
bit wasteful. Use a bitfield to compress the struct a bit.

This reduces the size of the struct from 216 bytes to 168 bytes on my
64-bit machine.

One of the fields needs to remain separate, since it’s used from a
TRACE() macro which calls typeof() on it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2018-10-01 21:51:18 +01:00
parent f0cecba199
commit 290bb0dd1b

View File

@ -551,20 +551,26 @@ struct _GTask {
gint64 creation_time;
gint priority;
GCancellable *cancellable;
gboolean check_cancellable;
GAsyncReadyCallback callback;
gpointer callback_data;
gboolean completed;
GTaskThreadFunc task_func;
GMutex lock;
GCond cond;
gboolean return_on_cancel;
/* This cant be in the bit field because we access it from TRACE(). */
gboolean thread_cancelled;
gboolean synchronous;
gboolean thread_complete;
gboolean blocking_other_task;
gboolean check_cancellable : 1;
gboolean completed : 1;
gboolean return_on_cancel : 1;
gboolean synchronous : 1;
gboolean thread_complete : 1;
gboolean blocking_other_task : 1;
gboolean had_error : 1;
gboolean result_set : 1;
gboolean ever_returned : 1;
GError *error;
union {
@ -573,9 +579,6 @@ struct _GTask {
gboolean boolean;
} result;
GDestroyNotify result_destroy;
gboolean had_error;
gboolean result_set;
gboolean ever_returned;
};
#define G_TASK_IS_THREADED(task) ((task)->task_func != NULL)
@ -1635,7 +1638,7 @@ g_task_propagate_pointer (GTask *task,
if (g_task_propagate_error (task, error))
return NULL;
g_return_val_if_fail (task->result_set == TRUE, NULL);
g_return_val_if_fail (task->result_set, NULL);
task->result_destroy = NULL;
task->result_set = FALSE;
@ -1691,7 +1694,7 @@ g_task_propagate_int (GTask *task,
if (g_task_propagate_error (task, error))
return -1;
g_return_val_if_fail (task->result_set == TRUE, -1);
g_return_val_if_fail (task->result_set, -1);
task->result_set = FALSE;
return task->result.size;
@ -1746,7 +1749,7 @@ g_task_propagate_boolean (GTask *task,
if (g_task_propagate_error (task, error))
return FALSE;
g_return_val_if_fail (task->result_set == TRUE, FALSE);
g_return_val_if_fail (task->result_set, FALSE);
task->result_set = FALSE;
return task->result.boolean;