[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 3/4] docs: document use of automatic cleanup fun
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 3/4] docs: document use of automatic cleanup functions in glib |
Date: |
Fri, 23 Aug 2019 14:53:41 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 |
On 8/23/19 11:39 AM, Daniel P. Berrangé wrote:
> Document the use of g_autofree and g_autoptr in glib for automatic
> freeing of memory, or other resource cleanup (eg mutex unlocking).
>
> Signed-off-by: Daniel P. Berrangé <address@hidden>
> ---
> CODING_STYLE.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 101 insertions(+)
> +The cleanup functions are not restricted to simply free'ing memory. The
> +GMutexLocker class is a variant of GMutex that has automatic locking and
> +unlocking at start and end of the enclosing scope
> +
> +In the following example, the `lock` in `MyObj` will be held for the
> +precise duration of the `somefunc` function
> +
> + typedef struct {
> + GMutex lock;
> + } MyObj;
> +
> + char *somefunc(MyObj *obj) {
> + g_autofree GMutexLocker *locker = g_mutex_locker_new(&obj->lock)
Wrong example (you don't want to call g_free, and you missed ';'). This
should be
g_autoptr (GMutexLocker) locker = g_mutex_locker_new(&obj->lock);
With that fixed,
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
Re: [Qemu-devel] [PATCH 0/4] docs: add docs about use of automatic cleanup functions, Marc-André Lureau, 2019/08/23