[FFmpeg-devel] [PATCH 02/42] avcodec/refstruct: Add simple API for refcounted objects

Nicolas George george at nsup.org
Fri Oct 6 23:37:31 EEST 2023


Andreas Rheinhardt (12023-10-06):
> Do you mean a template that generates functions like
> 
> HEVCVPS *ff_hevc_vps_ref(HEVCVPS *vps)
> {
>     return ff_refstruct_ref(vps);
> }
> 
> automatically?

Yes, but better, directly:

void ff_hevc_vps_unref(HEVCVPS *vps)
{
    if (atomic_fetch_sub_explicit(&(*vps)->AVRC_FIELD, 1, memory_order_acq_rel) == 1) {
        AVRC_FREE(*vps);
        *vps = NULL;
    }
}

Apart from the type safety, I see a significant benefit in having the
free function hard-coded in the unref function rather than having to
spare a pointer for it.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20231006/7ada92c3/attachment.sig>


More information about the ffmpeg-devel mailing list