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. More...
 
void ref_decrement (struct refcnt *refcnt)
 Decrement reference count. More...
 
void ref_no_free (struct refcnt *refcnt __unused)
 Do not free reference-counted object. More...
 

Detailed Description

Reference counting.

Definition in file refcnt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

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

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

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

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

References refcnt::count, DBGC, DBGC2, refcnt::free, and 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 101 of file refcnt.c.

101  {
102  /* Do nothing */
103 }

Referenced by certstore_init().