iPXE
Data Structures | Defines | Functions | Variables
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...

Defines

#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)
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.


Define Documentation

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

Initialise a reference counter.

Parameters:
refcntReference counter
freeFree containing object

Definition at line 64 of file refcnt.h.

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_signature(), create_downloader(), create_parameters(), create_pinger(), create_validator(), dhcppkt_init(), dhcpv6_register(), dns_resolv(), efi_local_open(), efi_pxe_install(), fc_els_create(), fc_ns_query(), fc_peer_create(), fc_port_open(), fc_ulp_create(), fc_xchg_create(), fcoe_probe(), fcpdev_open(), fcpdev_scsi_command(), ftp_open(), http_connect(), http_open(), hw_open(), ib_cmrc_open(), ib_srp_open(), ipv6_register_settings(), iscsi_open(), ndp_register_settings(), neighbour_create(), nfs_open(), numeric_resolv(), ocsp_check(), open(), parse_uri(), peerblk_open(), peerdisc_create(), peermux_filter(), ping_open(), 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(), udp_open_common(), uri_dup(), x509_alloc_chain(), x509_certificate(), xcm_create(), xfer_open_named_socket(), and xsigo_ib_probe().

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

Initialise a static reference counter.

Parameters:
free_fnFree containing object

Definition at line 77 of file refcnt.h.

#define ref_get (   refcnt)
Value:
( {                                             \
        if ( refcnt )                                                   \
                assert ( (refcnt)->count >= 0 );                        \
        ref_increment ( refcnt );                                       \
        (refcnt); } )

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 92 of file refcnt.h.

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

#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 106 of file refcnt.h.

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_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(), fcoe_close(), fcpcmd_put(), fcpdev_open(), fcpdev_put(), fcpdev_scsi_command(), ftp_open(), http_connect(), http_open(), hw_open(), ib_cmrc_open(), ib_cmrc_shutdown(), ib_srp_open(), ibdev_put(), image_put(), intf_put(), ipv6_register_settings(), ipv6conf_done(), iscsi_open(), ndp_register_settings(), neighbour_destroy(), neighbour_discovered(), netdev_put(), nfs_open(), numeric_resolv(), ocsp_put(), open(), peerblk_open(), peerdisc_close(), peerdisc_destroy(), peermux_filter(), ping_close(), ping_open(), 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(), udp_close(), udp_open_common(), unregister_settings(), uri_put(), x509_chain_put(), x509_put(), xcm_destroy(), xcm_free(), xfer_open_named_socket(), and xsigo_ib_remove().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static __attribute__ ( (always_inline)  ) [inline, static]

Initialise a reference counter.

Parameters:
refcntReference counter
freeFreeing function
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)

Variable Documentation

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

Definition at line 54 of file refcnt.h.

Referenced by aes_unwrap(), aes_wrap(), alloc_usb_bus(), aoecmd_free(), aoedev_free(), apply_dns_search(), 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_free(), copy_encap_settings(), deflate_test_exec(), del_ipv4_miniroute(), delwin(), destroy_menu(), dhcp_create_request(), dhcp_free(), dhcpv6_free(), downloader_free(), echo_exec(), efi_block_boot_image(), efi_block_describe(), efi_block_install(), efi_download_start(), efi_driver_start(), efi_driver_stop(), efi_file_close(), efi_ifr_free(), efi_image_exec(), efi_local_check_volume_name(), efi_local_len(), efi_local_open_path(), efi_pxe_free(), 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_close(), efi_usb_install(), efi_usb_open(), efi_usb_probe(), efi_usb_remove(), efi_usb_uninstall(), efipci_start(), efipci_stop(), 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(), 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_image(), free_iob(), free_mlx_utils(), free_netdev(), free_parameters(), free_pixbuf(), free_tls(), 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(), guestinfo_net_probe(), guestinfo_net_remove(), 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_post_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(), ibft_install(), image_set_cmdline(), image_set_name(), image_x509(), imgdownload(), imgsingle_exec(), imgverify(), init_mlx_utils(), initrd_reshuffle(), int13_hook(), ipoib_discard_remac(), ipoib_flush_remac(), ipv6_del_miniroute(), ipv6_sock_aton(), ipv6conf_free(), ipxe(), isabus_probe(), isabus_remove(), isapnpbus_probe(), isapnpbus_remove(), iscsi_fetch_settings(), iscsi_free(), iscsi_handle_targetaddress_value(), iscsi_rx_buffered_data_done(), iscsi_scsi_done(), item_exec(), jme_free_rx_resources(), jme_free_tx_resources(), linda_create_send_wq(), linda_destroy_send_wq(), linux_args_cleanup(), loopback_test(), mcabus_probe(), mcabus_remove(), memcpy_test_speed(), menu_exec(), 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(), pci_vpd_resize(), pcibus_probe(), pcibus_remove(), peerblk_decrypt(), peerblk_free(), peerblk_reset(), peerdisc_free(), peerdisc_socket_tx(), peermux_free(), pem_asn1(), png_pixbuf(), posix_file_free(), privkey_apply_settings(), process_script(), prompt_exec(), pxe_menu_boot(), qib7322_destroy_send_bufs(), qib7322_destroy_send_wq(), qib7322_probe(), qib7322_remove(), rc80211_free(), read_value(), ref_decrement(), resolve_path(), resolve_uri(), rsa_free(), rtl818x_probe(), sandev_free(), sandev_parse_iso9660(), scsicmd_free(), sec80211_install(), set_core_exec(), shell(), show_exec(), sis190_free_phy(), skge_free(), skge_probe(), skge_remove(), sky2_free_rings(), sky2_probe(), sky2_remove(), slam_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_send_certificate(), tls_send_plaintext(), txnic_bgx_probe(), txnic_bgx_remove(), txnic_pf_probe(), txnic_pf_remove(), 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_path(), 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(), vp_free_vq(), vxge_hw_device_terminate(), wpa_stop(), x509_free_chain(), 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(), and xve_destroy().

                                                       {
        refcnt->free = free;
}