Porting to GTask: pointer to self in context?
Dan Williams
dcbw at redhat.com
Thu Apr 6 19:04:09 UTC 2017
On Thu, 2017-04-06 at 20:09 +0200, Aleksander Morgado wrote:
> Hey Ben, Dan and everyone else,
>
> Related to the ports to GTask sent by Ben...
>
> When using the GSimpleAsyncResult logic, I usually always added a
> full
> reference to the "source object" of the async operation in the
> "Context" struct, so that I could use it directly, e.g. ctx->self.
> This was really not necessary, because the GSimpleAsyncResult hold
> itself a reference to the "source object", but it was handy because I
> could use the object right away without needing to call
> g_async_result_get_source_object(), which returns a full reference
> (and therefore then I would have needed to unref that one
> explicitly...)
>
> When using GTask, though, we have g_task_get_source_object(), which
> doesn't return a full reference. So, in the GTask implementations
> I've done I've tried to avoid having a full "self" reference in the
> Contexts set as GTask data, and instead I would just pass around the
> GTask in the different callbacks and then just create local variables
> whenever needed like this:
>
> Context *ctx;
> MMSomeObject *self;
>
> ctx = g_task_get_task_data (task);
> self = g_task_get_source_object (task);
>
> Question being, should we still keep the "self" pointer in the
> Context
> struct as we did with GSimpleAsyncResult, or default to just using
> g_task_get_source_object() when/where needed?
>
> What does everyone think?
I think in the ports I've done, I've tended towards
g_task_get_source_object(). Not everywhere, but most places.
I think ctx->self can be useful if we have a lot of ->self references,
so maybe we default to get_source_object() and then use ->self on a
case-by-case basis?
Dan
More information about the ModemManager-devel
mailing list