iPXE
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)
 FILE_SECBOOT (PERMITTED)
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()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ref_increment()

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 43 of file refcnt.c.

43 {
44
45 if ( refcnt ) {
46 refcnt->count++;
47 DBGC2 ( refcnt, "REFCNT %p incremented to %d\n",
49 }
50}
#define DBGC2(...)
Definition compiler.h:522
A reference counter.
Definition refcnt.h:27
int count
Current reference count.
Definition refcnt.h:33

References refcnt::count, and DBGC2.

◆ ref_decrement()

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 62 of file refcnt.c.

62 {
63
64 if ( ! refcnt )
65 return;
66
67 refcnt->count--;
68 DBGC2 ( refcnt, "REFCNT %p decremented to %d\n",
70
71 if ( refcnt->count >= 0 )
72 return;
73
74 if ( refcnt->count < -1 ) {
75 DBGC ( refcnt, "REFCNT %p decremented too far (%d)!\n",
77 /* Avoid multiple calls to free(), which typically
78 * result in memory corruption that is very hard to
79 * track down.
80 */
81 return;
82 }
83
84 if ( refcnt->free ) {
85 DBGC ( refcnt, "REFCNT %p being freed via method %p\n",
86 refcnt, refcnt->free );
87 refcnt->free ( refcnt );
88 } else {
89 DBGC ( refcnt, "REFCNT %p being freed\n", refcnt );
90 free ( refcnt );
91 }
92}
#define DBGC(...)
Definition compiler.h:505
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
void(* free)(struct refcnt *refcnt)
Free containing object.
Definition refcnt.h:44

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

◆ ref_no_free()

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 102 of file refcnt.c.

102 {
103 /* Do nothing */
104}

References __unused.

Referenced by certstore_init().