refcnt.c File Reference

Reference counting. More...

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

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
struct refcntref_get (struct refcnt *refcnt)
 Increment reference count.
void ref_put (struct refcnt *refcnt)
 Decrement reference count.


Detailed Description

Reference counting.

Definition in file refcnt.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

struct refcnt* ref_get ( struct refcnt refcnt  )  [read]

Increment reference count.

Parameters:
refcnt Reference counter, or NULL
Return values:
refcnt Reference counter
If refcnt is NULL, no action is taken.

Definition at line 38 of file refcnt.c.

References DBGC2, and refcnt::refcnt.

Referenced by __attribute__(), aoe_attach(), dhcppkt_get(), ibdev_get(), image_get(), iscsi_attach(), netdev_get(), process_add(), register_settings(), and srp_attach().

00038                                                   {
00039 
00040         if ( refcnt ) {
00041                 refcnt->refcnt++;
00042                 DBGC2 ( refcnt, "REFCNT %p incremented to %d\n",
00043                         refcnt, refcnt->refcnt );
00044         }
00045         return refcnt;
00046 }

void ref_put ( struct refcnt refcnt  ) 

Decrement reference count.

Parameters:
refcnt Reference 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 58 of file refcnt.c.

References DBGC, DBGC2, free(), refcnt::free, and refcnt::refcnt.

Referenced by add_tls(), aoe_attach(), aoe_detach(), close(), create_downloader(), dhcppkt_put(), dns_resolv(), ftp_open(), http_open_filter(), hw_open(), ib_cmrc_open(), ib_cmrc_shutdown(), ibdev_put(), image_put(), iscsi_attach(), iscsi_detach(), netdev_put(), numeric_resolv(), open(), process_del(), resolv(), slam_open(), srp_attach(), srp_detach(), start_dhcp(), start_pxebs(), tcp_close(), tcp_open(), tftp_core_open(), udp_close(), udp_open_common(), unregister_settings(), and xfer_open_named_socket().

00058                                        {
00059 
00060         if ( ! refcnt )
00061                 return;
00062 
00063         refcnt->refcnt--;
00064         DBGC2 ( refcnt, "REFCNT %p decremented to %d\n",
00065                 refcnt, refcnt->refcnt );
00066 
00067         if ( refcnt->refcnt >= 0 )
00068                 return;
00069 
00070         if ( refcnt->free ) {
00071                 DBGC ( refcnt, "REFCNT %p being freed via method %p\n",
00072                        refcnt, refcnt->free );
00073                 refcnt->free ( refcnt );
00074         } else {
00075                 DBGC ( refcnt, "REFCNT %p being freed\n", refcnt );
00076                 free ( refcnt );
00077         }
00078 }


Generated on Tue Apr 6 20:01:14 2010 for gPXE by  doxygen 1.5.7.1