iPXE
refcnt.h File Reference

Reference counting. More...

#include <stddef.h>
#include <assert.h>

Go to the source code of this file.

Data Structures

struct  refcnt
 A reference counter. More...

Macros

#define ref_init(refcnt, free)
 Initialise a reference counter.
#define REF_INIT(free_fn)
 Initialise a static reference counter.
#define ref_get(refcnt)
 Get additional reference to object.
#define ref_put(refcnt)
 Drop reference to object.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static __attribute__ ((always_inline)) void ref_init(struct refcnt *refcnt
 Initialise a reference counter.
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)

Variables

static void(* free )(struct refcnt *refcnt))

Detailed Description

Reference counting.

Definition in file refcnt.h.

Macro Definition Documentation

◆ ref_init

#define ref_init ( refcnt,
free )
Value:
do { \
if ( __builtin_constant_p ( (free) ) && ( (free) == NULL ) ) { \
/* Skip common case of no initialisation required */ \
} else { \
ref_init ( (refcnt), (free) ); \
} \
} while ( 0 )
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
A reference counter.
Definition refcnt.h:27

Initialise a reference counter.

Parameters
refcntReference counter
freeFree containing object

Definition at line 65 of file refcnt.h.

65#define ref_init( refcnt, free ) do { \
66 if ( __builtin_constant_p ( (free) ) && ( (free) == NULL ) ) { \
67 /* Skip common case of no initialisation required */ \
68 } else { \
69 ref_init ( (refcnt), (free) ); \
70 } \
71 } while ( 0 )

Referenced by add_tls(), alloc_image(), alloc_netdev(), alloc_pixbuf(), alloc_sandev(), aoecmd_create(), aoedev_open(), ata_open(), atadev_command(), autovivify_child_settings(), block_translate(), certstore_init(), cms_message(), create_downloader(), create_parameters(), create_pinger(), create_validator(), dhcppkt_init(), dhcpv6_register(), dns_resolv(), efi_file_open_image(), efi_local_open(), efi_pxe_install(), fc_els_create(), fc_ns_query(), fc_peer_create(), fc_port_open(), fc_ulp_create(), fc_xchg_create(), fcpdev_open(), fcpdev_scsi_command(), ftp_open(), http_connect(), http_open(), hw_open(), ib_cmrc_open(), ib_srp_open(), imux_probe(), ipair_create(), iscsi_open(), ndp_register_settings(), neighbour_create(), nfs_open(), numeric_resolv(), ocsp_check(), open(), parse_uri(), peerblk_open(), peerdisc_create(), peermux_filter(), ping_open(), privkey_init(), resolv(), resolv_setting(), scsi_open(), scsidev_command(), slam_open(), srp_open(), srpdev_scsi_command(), start_dhcp(), start_dhcpv6(), start_ipv6conf(), start_ntp(), start_pxebs(), tcp_open(), tftp_core_open(), tls_session(), udp_open_common(), uri_dup(), x509_alloc_chain(), x509_certificate(), xcm_create(), xfer_open_named_socket(), and xsigo_ib_probe().

◆ REF_INIT

#define REF_INIT ( free_fn)
Value:
{ \
.free = free_fn, \
}

Initialise a static reference counter.

Parameters
free_fnFree containing object

Definition at line 78 of file refcnt.h.

78#define REF_INIT( free_fn ) { \
79 .free = free_fn, \
80 }

Referenced by lkrn_exec().

◆ ref_get

#define ref_get ( refcnt)
Value:
( { \
if ( refcnt ) \
assert ( (refcnt)->count >= 0 ); \
ref_increment ( refcnt ); \
(refcnt); } )
static unsigned int count
Number of entries.
Definition dwmac.h:220

Get additional reference to object.

Parameters
refcntReference counter, or NULL
Return values
refcntReference counter

If refcnt is NULL, no action is taken.

Definition at line 93 of file refcnt.h.

93#define ref_get( refcnt ) ( { \
94 if ( refcnt ) \
95 assert ( (refcnt)->count >= 0 ); \
96 ref_increment ( refcnt ); \
97 (refcnt); } )

Referenced by __attribute__(), __attribute__(), __attribute__(), acpi_add(), aoecmd_get(), aoedev_get(), cms_get(), dhcppkt_get(), efi_file_open_fixed(), fc_peer_get(), fc_port_deliver(), fc_port_get(), fc_ulp_get(), fc_ulp_user_get(), fcpcmd_get(), fcpdev_get(), gpios_get(), ibdev_get(), image_get(), intf_get(), neighbour_tx_queue(), netdev_get(), ocsp_get(), peerdisc_open(), privkey_get(), process_add(), register_settings(), sandev_get(), scsicmd_get(), scsidev_get(), srpcmd_get(), srpdev_get(), start_timer_fixed(), step(), tls_session(), uri_get(), x509_chain_get(), x509_get(), x509_root_get(), and xcm_create().

◆ ref_put

#define ref_put ( refcnt)
Value:
do { \
if ( refcnt ) \
assert ( (refcnt)->count >= 0 ); \
ref_decrement ( refcnt ); \
} while ( 0 )

Drop reference to object.

Parameters
refcntReference counter, or NULL
Return values
refcntReference counter

If refcnt is NULL, no action is taken.

Definition at line 107 of file refcnt.h.

107#define ref_put( refcnt ) do { \
108 if ( refcnt ) \
109 assert ( (refcnt)->count >= 0 ); \
110 ref_decrement ( refcnt ); \
111 } while ( 0 )

Referenced by acpi_del(), add_tls(), aoecmd_put(), aoedev_open(), aoedev_put(), ata_open(), atadev_command(), autovivify_child_settings(), block_translate(), close(), cms_put(), create_downloader(), create_pinger(), create_validator(), dhcppkt_put(), dhcpv6_register(), dns_resolv(), efi_file_close(), efi_local_open(), efi_pxe_install(), efi_pxe_uninstall(), fc_els_request(), fc_els_respond(), fc_ns_query(), fc_peer_put(), fc_port_deliver(), fc_port_open(), fc_port_put(), fc_ulp_put(), fc_ulp_user_put(), fc_xchg_close(), fcpcmd_put(), fcpdev_open(), fcpdev_put(), fcpdev_scsi_command(), free_tls(), ftp_open(), gpios_put(), http_connect(), http_open(), hw_open(), ib_cmrc_open(), ib_cmrc_shutdown(), ib_srp_open(), ibdev_put(), image_put(), imux_probe(), imux_remove(), intf_put(), ipair_create(), ipv6conf_done(), iscsi_open(), ndp_register_settings(), neighbour_destroy(), neighbour_tx_queue(), netdev_put(), nfs_open(), numeric_resolv(), ocsp_put(), open(), peerblk_open(), peerdisc_close(), peerdisc_create(), peerdisc_destroy(), peermux_filter(), ping_close(), ping_open(), privkey_put(), process_del(), resolv(), resolv_setting(), sandev_put(), scsi_open(), scsicmd_put(), scsidev_command(), scsidev_put(), slam_open(), srp_open(), srpcmd_put(), srpdev_put(), start_dhcp(), start_dhcpv6(), start_ntp(), start_pxebs(), step(), stop_timer(), tcp_close(), tcp_open(), tftp_core_open(), timer_expired(), tls_session(), udp_close(), udp_open_common(), unregister_settings(), uri_put(), usbblk_probe(), usbblk_remove(), x509_chain_put(), x509_put(), x509_root_put(), xcm_destroy(), xcm_free(), xfer_open_named_socket(), and xsigo_ib_remove().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ __attribute__()

__attribute__ ( (always_inline) )
inlinestatic

Initialise a reference counter.

Parameters
refcntReference counter
freeFreeing function

◆ ref_increment()

void ref_increment ( struct refcnt * refcnt)
extern

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
int count
Current reference count.
Definition refcnt.h:33

References refcnt::count, and DBGC2.

◆ ref_decrement()

void ref_decrement ( struct refcnt * refcnt)
extern

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
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)
extern

Variable Documentation

◆ free

void(* free) (struct refcnt *refcnt)) ( struct refcnt * refcnt)

Definition at line 55 of file refcnt.h.

55 {
56 refcnt->free = free;
57}

Referenced by aes_unwrap(), aes_wrap(), alloc_usb_bus(), aoecmd_free(), aoedev_free(), apply_dns_search(), apply_dns_servers(), apply_peerdisc_settings(), apply_syslog_settings(), apply_syslogs_settings(), ar9300_eeprom_restore_internal(), arbel_alloc(), arbel_create_cq(), arbel_create_qp(), arbel_destroy_cq(), arbel_destroy_qp(), arbel_free(), asn1_grow(), asn1_okx(), atacmd_free(), ath5k_desc_free(), ath5k_eeprom_free_pcal_info(), ath5k_hw_attach(), ath5k_hw_detach(), ath5k_probe(), ath5k_remove(), ath9k_deinit_softc(), ath9k_init_softc(), ath_descdma_cleanup(), atl1e_free_ring_resources(), autovivified_settings_free(), bitmap_free(), certstore_apply_settings(), chap_finish(), cmdline_image_free(), cms_cipher_key(), cms_free(), copy_encap_settings(), cpio_okx(), cwuri_fetch_uri(), deflate_test_exec(), delwin(), destroy_dynui(), dhcp_create_request(), dhcp_free(), dhcpv6_free(), dhe_key(), downloader_free(), dt_probe_node(), dt_remove_node(), dwgpio_group_probe(), dwgpio_group_remove(), dwusb_probe(), dwusb_remove(), dynui_exec(), eap_rx_identity(), eap_rx_md5(), eap_rx_mschapv2_request(), eap_tx_response(), ecdsa_free(), echo_exec(), editstring_okx(), efi_aoe_path(), efi_block_describe(), efi_block_exec(), efi_block_hook(), efi_block_install(), efi_block_label(), efi_block_unhook(), efi_boot_path(), efi_cacert(), efi_cacert_all(), efi_cmdline_free(), efi_download_start(), efi_file_free(), efi_ifr_free(), efi_image_exec(), efi_init_application(), efi_iscsi_path(), efi_local_check_volume_name(), efi_local_free(), efi_local_len(), efi_local_open_path(), efi_locate_device(), efi_path_uri(), efi_pxe_free(), efi_shim_cmdline(), efi_snp_hii_fetch(), efi_snp_hii_install(), efi_snp_hii_process(), efi_snp_hii_store(), efi_snp_hii_uninstall(), efi_snp_probe(), efi_snp_remove(), efi_usb_free_all(), efi_usb_install(), efi_usb_probe(), efi_usb_remove(), efi_usb_uninstall(), efi_veto(), efidev_free(), efipci_start(), efipci_stop(), efisig_asn1(), efivars_fetch(), efivars_find(), ehci_endpoint_close(), ehci_endpoint_open(), ehci_probe(), ehci_remove(), ehci_ring_alloc(), ehci_ring_free(), eisabus_probe(), eisabus_remove(), empty_line_buffer(), eoib_discard(), eoib_flush_peers(), exanic_probe(), exanic_remove(), expand_settings(), expand_tokens(), fc_els_free(), fc_ns_query_free(), fc_ulp_free(), fc_ulp_logout(), fc_xchg_free(), fcpcmd_free(), fdt_insert(), fetch_next_server_and_filename(), fetch_root_path(), fetch_san_filename(), fetchf_setting(), fetchn_setting(), flexboot_nodnic_create_cq(), flexboot_nodnic_create_qp(), flexboot_nodnic_destroy_cq(), flexboot_nodnic_destroy_qp(), flexboot_nodnic_eth_open(), flexboot_nodnic_probe(), flexboot_nodnic_remove(), fragment_expired(), fragment_reassemble(), free_form(), free_image(), free_iob(), free_mlx_utils(), free_netdev(), free_parameters(), free_pixbuf(), free_tls(), free_tls_session(), free_tokens(), free_usb(), free_usb_bus(), free_usb_hub(), ftp_free(), generic_settings_clear(), generic_settings_store(), golan_create_cq(), golan_create_qp_aux(), golan_destroy_cq(), golan_destroy_qp(), golan_probe_normal(), golan_remove_normal(), guestinfo_fetch_type(), hermon_alloc(), hermon_create_cq(), hermon_create_qp(), hermon_destroy_cq(), hermon_destroy_qp(), hermon_free(), history_append(), history_cleanup(), history_free(), history_store(), http_conn_free(), http_format_ntlm_auth(), http_free(), http_open_uri(), http_parse_ntlm_auth(), hub_probe(), hub_remove(), hv_probe(), hv_remove(), hvm_map_xenstore(), hvm_probe(), hvm_remove(), ib_create_conn(), ib_create_cq(), ib_create_mi(), ib_create_path(), ib_create_qp(), ib_destroy_conn(), ib_destroy_cq(), ib_destroy_madx(), ib_destroy_mi(), ib_destroy_path(), ib_destroy_qp(), ib_mcast_attach(), ib_mcast_detach(), ib_srp_free(), ib_srp_parse_root_path(), ibft_install(), icert_cert(), icert_certs(), icert_encode(), image_set_cmdline(), image_set_name(), image_x509(), imgdownload(), imgsingle_exec(), init_mlx_utils(), int13_hook(), ipair_free(), ipair_rx_pubkey(), ipair_tx_pair(), ipoib_discard_remac(), ipoib_flush_remac(), ipv4_add_miniroutes(), ipv4_del_miniroute(), ipv6_del_miniroute(), ipv6_sock_aton(), ipv6conf_free(), ipxe(), isabus_probe(), isabus_remove(), isapnpbus_probe(), isapnpbus_remove(), iscsi_fetch_settings(), iscsi_free(), iscsi_handle_chap_c_value(), iscsi_handle_chap_r_value(), iscsi_handle_targetaddress_value(), iscsi_parse_root_path(), iscsi_rx_buffered_data_done(), iscsi_scsi_done(), item_exec(), jme_free_rx_resources(), jme_free_tx_resources(), keymap_apply(), linda_create_send_wq(), linda_destroy_send_wq(), linux_args_cleanup(), lldp_remove(), lldp_rx(), loopback_test(), mcabus_probe(), mcabus_remove(), memcpy_test_speed(), mlx_memory_free_priv(), neighbour_free(), net80211_autoassociate(), net80211_free(), net80211_free_wlan(), net80211_free_wlanlist(), net80211_mgmt_dequeue(), net80211_netdev_close(), net80211_prepare_assoc(), net80211_probe_finish_all(), net80211_probe_finish_best(), net80211_step_associate(), netboot(), netfront_read_mac(), nfs_deliver(), nfs_free(), nfs_open(), nfs_uri_free(), nfs_uri_init(), nfs_uri_next_mountpoint(), nfs_uri_symlink(), nii_map(), nii_pci_close(), nii_unmap(), ntlm_authenticate_okx(), ocsp_free(), ocsp_response(), ocsp_uri_string(), param_exec(), parse_settings_name(), pci_vpd_resize(), pcibridge_probe(), pcibridge_remove(), pcibus_probe(), pcibus_remove(), peerblk_decrypt(), peerblk_free(), peerblk_reset(), peerdisc_discovered(), peerdisc_free(), peerdisc_socket_tx(), peermux_free(), pem_asn1(), png_pixbuf(), posix_file_free(), privkey_apply_settings(), privkey_free(), process_script(), prompt_exec(), pubkey_okx(), pubkey_sign_okx(), pxe_menu_boot(), qib7322_destroy_send_bufs(), qib7322_destroy_send_wq(), qib7322_probe(), qib7322_remove(), rc80211_free(), read_value(), readline_history(), ref_decrement(), resolve_path(), resolve_uri(), rsa_free(), rtl818x_probe(), sandev_free(), sandev_parse_iso9660(), scsicmd_free(), sec80211_install(), select_setting_row(), set_core_exec(), shell(), show_exec(), sis190_free_phy(), skge_free(), skge_probe(), skge_remove(), sky2_free_rings(), sky2_probe(), sky2_remove(), slam_free(), slam_parse_multicast_address(), slirp_timer_free(), srpcmd_free(), storef_setting(), storen_setting(), string_test_exec(), system(), t509bus_probe(), t509bus_remove(), tftp_free(), tftp_uri(), tg3_free_consistent(), tls_clear_cipher(), tls_clear_handshake(), tls_new_finished(), tls_new_server_key_exchange(), tls_new_session_ticket(), tls_send_certificate_verify(), tls_send_client_key_exchange_dhe(), tls_send_client_key_exchange_pubkey(), txnic_bgx_probe(), txnic_bgx_remove(), txnic_pf_probe(), txnic_pf_remove(), ucode_exec(), uhci_dequeue(), uhci_endpoint_close(), uhci_endpoint_open(), uhci_enqueue(), uhci_probe(), uhci_remove(), undipci_probe(), undipci_remove(), undirom_probe(), uri_churi_okx(), uri_format_okx(), uri_free(), uri_resolve_okx(), uri_resolve_path_okx(), usb_autoconfigure(), usb_config_descriptor(), usb_get_string_descriptor(), usb_probe_all(), usb_remove_all(), usbio_config(), usbio_endpoint_close(), usbio_endpoint_open(), usbio_interfaces(), usbio_interrupt_close(), usbio_interrupt_open(), usbio_start(), usbio_stop(), usbkbd_probe(), usbkbd_remove(), validator_free(), validator_start_download(), vesafb_init(), virtnet_free_virtqueues(), vmbus_close(), vmbus_open(), vmbus_probe(), vmbus_probe_channels(), vmbus_remove(), vmbus_remove_channels(), vxge_hw_device_terminate(), wpa_stop(), x509_free(), x509_free_chain(), x509_truncate(), xcm_free(), xenbus_probe(), xenbus_probe_device(), xenbus_probe_type(), xenbus_remove_device(), xenstore_dump(), xenstore_message(), xenstore_read_num(), xenstore_response(), xfer_vprintf(), xhci_bus_close(), xhci_bus_open(), xhci_device_close(), xhci_device_open(), xhci_endpoint_close(), xhci_endpoint_open(), xhci_probe(), xhci_remove(), xhci_ring_alloc(), xhci_ring_free(), xsigo_free(), xve_create(), xve_destroy(), and zlib_deflate().