refc_binary.c

Include dependency graph for refc_binary.c:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "4" [label="stdbool.h" tooltip="stdbool.h"]
    "27" [label="dictionary.h" tooltip="dictionary.h"]
    "19" [label="atom.h" tooltip="atom.h"]
    "30" [label="trace.h" tooltip="trace.h"]
    "9" [label="assert.h" tooltip="assert.h"]
    "23" [label="synclist.h" tooltip="synclist.h"]
    "12" [label="stdint.h" tooltip="stdint.h"]
    "2" [label="stdlib.h" tooltip="stdlib.h"]
    "17" [label="context.h" tooltip="context.h"]
    "14" [label="utils.h" tooltip="utils.h"]
    "20" [label="atom_table.h" tooltip="atom_table.h"]
    "8" [label="term_typedef.h" tooltip="term_typedef.h"]
    "15" [label="stddef.h" tooltip="stddef.h"]
    "10" [label="limits.h" tooltip="limits.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" fillcolor="#BFBFBF"]
    "3" [label="refc_binary.h" tooltip="refc_binary.h"]
    "25" [label="string.h" tooltip="string.h"]
    "21" [label="mailbox.h" tooltip="mailbox.h"]
    "24" [label="term.h" tooltip="term.h"]
    "7" [label="erl_nif.h" tooltip="erl_nif.h"]
    "6" [label="resources.h" tooltip="resources.h"]
    "22" [label="smp.h" tooltip="smp.h"]
    "28" [label="erl_nif_priv.h" tooltip="erl_nif_priv.h"]
    "29" [label="tempstack.h" tooltip="tempstack.h"]
    "18" [label="globalcontext.h" tooltip="globalcontext.h"]
    "13" [label="memory.h" tooltip="memory.h"]
    "16" [label="stdio.h" tooltip="stdio.h"]
    "26" [label="timer_list.h" tooltip="timer_list.h"]
    "11" [label="inttypes.h" tooltip="inttypes.h"]
    "5" [label="list.h" tooltip="list.h"]
    "27" -> "5" [dir=forward tooltip="include"]
    "27" -> "24" [dir=forward tooltip="include"]
    "19" -> "12" [dir=forward tooltip="include"]
    "19" -> "2" [dir=forward tooltip="include"]
    "23" -> "16" [dir=forward tooltip="include"]
    "23" -> "5" [dir=forward tooltip="include"]
    "23" -> "22" [dir=forward tooltip="include"]
    "17" -> "18" [dir=forward tooltip="include"]
    "17" -> "5" [dir=forward tooltip="include"]
    "17" -> "21" [dir=forward tooltip="include"]
    "17" -> "22" [dir=forward tooltip="include"]
    "17" -> "24" [dir=forward tooltip="include"]
    "17" -> "26" [dir=forward tooltip="include"]
    "14" -> "15" [dir=forward tooltip="include"]
    "14" -> "16" [dir=forward tooltip="include"]
    "14" -> "2" [dir=forward tooltip="include"]
    "20" -> "4" [dir=forward tooltip="include"]
    "20" -> "19" [dir=forward tooltip="include"]
    "8" -> "9" [dir=forward tooltip="include"]
    "8" -> "10" [dir=forward tooltip="include"]
    "8" -> "11" [dir=forward tooltip="include"]
    "8" -> "12" [dir=forward tooltip="include"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "17" [dir=forward tooltip="include"]
    "1" -> "27" [dir=forward tooltip="include"]
    "1" -> "28" [dir=forward tooltip="include"]
    "1" -> "13" [dir=forward tooltip="include"]
    "1" -> "29" [dir=forward tooltip="include"]
    "1" -> "14" [dir=forward tooltip="include"]
    "1" -> "30" [dir=forward tooltip="include"]
    "3" -> "4" [dir=forward tooltip="include"]
    "3" -> "2" [dir=forward tooltip="include"]
    "3" -> "5" [dir=forward tooltip="include"]
    "3" -> "6" [dir=forward tooltip="include"]
    "21" -> "4" [dir=forward tooltip="include"]
    "21" -> "5" [dir=forward tooltip="include"]
    "21" -> "8" [dir=forward tooltip="include"]
    "21" -> "14" [dir=forward tooltip="include"]
    "24" -> "4" [dir=forward tooltip="include"]
    "24" -> "12" [dir=forward tooltip="include"]
    "24" -> "16" [dir=forward tooltip="include"]
    "24" -> "2" [dir=forward tooltip="include"]
    "24" -> "25" [dir=forward tooltip="include"]
    "24" -> "13" [dir=forward tooltip="include"]
    "24" -> "3" [dir=forward tooltip="include"]
    "24" -> "14" [dir=forward tooltip="include"]
    "24" -> "8" [dir=forward tooltip="include"]
    "7" -> "8" [dir=forward tooltip="include"]
    "6" -> "2" [dir=forward tooltip="include"]
    "6" -> "7" [dir=forward tooltip="include"]
    "6" -> "5" [dir=forward tooltip="include"]
    "6" -> "13" [dir=forward tooltip="include"]
    "22" -> "4" [dir=forward tooltip="include"]
    "28" -> "17" [dir=forward tooltip="include"]
    "28" -> "13" [dir=forward tooltip="include"]
    "18" -> "12" [dir=forward tooltip="include"]
    "18" -> "19" [dir=forward tooltip="include"]
    "18" -> "20" [dir=forward tooltip="include"]
    "18" -> "7" [dir=forward tooltip="include"]
    "18" -> "5" [dir=forward tooltip="include"]
    "18" -> "21" [dir=forward tooltip="include"]
    "18" -> "22" [dir=forward tooltip="include"]
    "18" -> "23" [dir=forward tooltip="include"]
    "18" -> "24" [dir=forward tooltip="include"]
    "18" -> "26" [dir=forward tooltip="include"]
    "13" -> "12" [dir=forward tooltip="include"]
    "13" -> "2" [dir=forward tooltip="include"]
    "13" -> "7" [dir=forward tooltip="include"]
    "13" -> "8" [dir=forward tooltip="include"]
    "13" -> "14" [dir=forward tooltip="include"]
    "26" -> "4" [dir=forward tooltip="include"]
    "26" -> "12" [dir=forward tooltip="include"]
    "26" -> "5" [dir=forward tooltip="include"]
}

Functions

struct RefcBinary *refc_binary_create_resource(size_t size, struct ResourceType *resource_type)

Create a reference-counted resource object outside of the process heap.

This function will create a reference-counted resource object outside of the context heap. A blob will be allocated in the VM memory (e.g., via malloc). The allocated data will include an internal data structure that includes the data size and reference count.

Parameters:
  • size – the size of the data to create

  • resource_type – the resource type, NULL for regular refc binaries.

Returns:

a pointer to the out-of-context data.

const char *refc_binary_get_data(const struct RefcBinary *refc)

get the data of the off-context binary

Return the data of the off-context binary

Parameters:
  • ptr – Refc binary returned from memory_create_refc_binary

struct RefcBinary *refc_binary_from_data(void *ptr)

get the refc binary from its pointer

This must only be passed the result of refc_binary_get_data.

Parameters:
  • ptr – pointer obtained from refc_binary_get_data

void refc_binary_increment_refcount(struct RefcBinary *refc)

Increment the reference count on the refc binary.

Parameters:
  • ptr – the refc binary

bool refc_binary_decrement_refcount(struct RefcBinary *refc, struct GlobalContext *global)

Decrement the reference count on the refc binary.

This function will call refc_binary_destroy if the reference count reaches 0.

Parameters:
  • ptr – the refc binary

  • global – the global context

Returns:

true if the refc binary was free’d; false, otherwise

void refc_binary_destroy(struct RefcBinary *refc, struct GlobalContext *global)

Destroy a refc binary after its reference count reached 0.

This function will call the destructor if the refc binary is a resource and will free the refc binary.

Parameters:
  • refc – the binary to destroy

  • global – the global context

term refc_binary_create_binary_info(Context *ctx)

TODO consider implementing erlang:memory/0,1 instead

size_t refc_binary_total_size(Context *ctx)

Return the total size (in bytes) of all reference counted binaries.

Returns:

the total size (in bytes) of all reference counted binaries