iPXE
Functions
refcnt.c File Reference

Reference counting. More...

#include <stdlib.h>
#include <ipxe/refcnt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void ref_increment (struct refcnt *refcnt)
 Increment reference count.
void ref_decrement (struct refcnt *refcnt)
 Decrement reference count.
void ref_no_free (struct refcnt *refcnt __unused)
 Do not free reference-counted object.

Detailed Description

Reference counting.

Definition in file refcnt.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void ref_increment ( struct refcnt refcnt)

Increment reference count.

Parameters:
refcntReference counter, or NULL

If refcnt is NULL, no action is taken.

Definition at line 42 of file refcnt.c.

References refcnt::count, and DBGC2.

                                             {

        if ( refcnt ) {
                refcnt->count++;
                DBGC2 ( refcnt, "REFCNT %p incremented to %d\n",
                        refcnt, refcnt->count );
        }
}
void ref_decrement ( struct refcnt refcnt)

Decrement reference count.

Parameters:
refcntReference counter, or NULL

If the reference count decreases below zero, the object's free() method will be called.

If refcnt is NULL, no action is taken.

Definition at line 61 of file refcnt.c.

References refcnt::count, DBGC, DBGC2, refcnt::free, and free.

                                             {

        if ( ! refcnt )
                return;

        refcnt->count--;
        DBGC2 ( refcnt, "REFCNT %p decremented to %d\n",
                refcnt, refcnt->count );

        if ( refcnt->count >= 0 )
                return;

        if ( refcnt->count < -1 ) {
                DBGC ( refcnt, "REFCNT %p decremented too far (%d)!\n",
                       refcnt, refcnt->count );
                /* Avoid multiple calls to free(), which typically
                 * result in memory corruption that is very hard to
                 * track down.
                 */
                return;
        }

        if ( refcnt->free ) {
                DBGC ( refcnt, "REFCNT %p being freed via method %p\n",
                       refcnt, refcnt->free );
                refcnt->free ( refcnt );
        } else {
                DBGC ( refcnt, "REFCNT %p being freed\n", refcnt );
                free ( refcnt );
        }
}
void ref_no_free ( struct refcnt *refcnt  __unused)

Do not free reference-counted object.

Parameters:
refcntReference counter

This is meant for initializing a reference counter structure in a statically allocated object.

Definition at line 101 of file refcnt.c.

Referenced by certstore_init().

                                                    {
        /* Do nothing */
}