resources.h
Include dependency graph for resources.h:
This graph shows which files directly or indirectly include resources.h:
Private data structures for nif object resources.
Defines
-
SELECT_EVENT_NOTIFICATION_SIZE (TUPLE_SIZE(4) + REF_SIZE + TERM_BOXED_RESOURCE_SIZE)
Functions
-
static inline void resource_type_destroy(struct ResourceType *resource_type)
-
bool select_event_notify(ErlNifEvent event, bool is_read, bool is_write, GlobalContext *global)
Send a notification that an event was selected.
This function is called from sys_poll_events platform function if a select event was selected and the read or write flag was set. It modifies the select_event object so the notification is only sent once.
The function can also be called from a select task loop if
AVM_SELECT_IN_TASKis defined.It is not an error to call this function with an event that is not in the list.
This function calls
sys_unregister_select_event.- Parameters:
event – the event to notify
is_read – if the event was selected for reading
is_write – if the event was selected for writing
global – the global context
- Returns:
true if the event was found
-
void select_event_count_and_destroy_closed(struct ListHead *select_events, size_t *read, size_t *write, size_t *either, GlobalContext *global)
Count events available for reading and/or writing and destroy the events marked for close.
Convenience function that can be called by
sys_poll_eventsand iterates on events to be closed and count them.The function can also be called from a select task loop if
AVM_SELECT_IN_TASKis defined.- Parameters:
select_events – list of events, with a write lock
read – on output number of events with read = 1, can be NULL
write – on output number of events with write = 1, can be NULL
either – on output number of events with either read = 1 or write = 1, can be NULL
global – the global context
-
void destroy_resource_monitors(struct RefcBinary *resource, GlobalContext *global)
Destroy monitors associated with a resource.
- Parameters:
resource – resource to destroy monitors for
global – the global context
-
term select_event_make_notification(void *rsrc_obj, uint64_t ref_ticks, bool is_write, Heap *heap)
Build a select event notification.
- Parameters:
rsrc_obj – the resource to build the notification for
ref_ticks – the reference or 0 if it’s undefined
is_write – if the notification is for a write or a read
heap – the heap to create the notification in, should have enough memory available (see SELECT_EVENT_NOTIFICATION_SIZE)
-
void resource_type_fire_monitor(struct ResourceType *resource_type, ErlNifEnv *env, int32_t process_id, uint64_t ref_ticks)
Call down handler for a given resource and remove monitor from list.
handler is called while holding lock on the list of monitors and if monitor is still in the list of resource monitors, thus ensuring that the resource still exists.
- Parameters:
resource_type – type holding the list of monitors
env – environment for calling the down handler
process_id – id of the process monitored
ref_ticks – reference of the monitor
-
term resource_monitor_to_resource(struct ResourceType *resource_type, uint64_t ref_ticks, Heap *heap)
Get a resource from a resource monitor.
verifies using resource monitors that the resource still exists and increases the refcount by creating a term for it in the provided heap
- Parameters:
resource_type – type holding the list of monitors
ref_ticks – reference of the monitor
heap – heap to create the resource term into
- Returns:
a resource term or invalid if the resource is gone
-
struct ResourceType
- #include <resources.h>
Collaboration diagram for ResourceType:
A resource type.
we need a reference to the global context as
enif_release_resourceneeds to access the synchronized list of refc_binaries
-
struct ResourceMonitor
- #include <resources.h>
Collaboration diagram for ResourceMonitor:
A resource monitor.
-
struct SelectEvent
- #include <resources.h>
Collaboration diagram for SelectEvent:
A selectable event.