-
Notifications
You must be signed in to change notification settings - Fork 6
Allow definition of a load
and unload
NIF callback
#16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It is sometimes necessary for a NIF to have some global initialization logic in its load callback, like we already have for atom and resource registration. This commit inlines the `fine::__private__::load` function in the `FINE_INIT` macro to delay template instantiation of a new `fine::__private__::OnLoad` struct that can be overriden by a user using the `FINE_LOAD(env)` macro to provide customized initialization logic, while still registering atoms and resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @brodeuralexis! I dropped a comment regarding the API :)
That said, I wonder if there is a logic that the user would put on load, which couldn't be a typical initialization. In the docs example, couldn't they could as well do this:
static ThreadPool s_pool = ThreadPool(std::thread::hardware_concurrency());
And if that's the case, I would probably hold off with extra APIs, until there is a use case.
load
NIF callbackload
and unload
NIF callback
I've also added code to support the unload callback, as I believe both should be provided at the same time.
I've reworked the example to accept the number of threads from
In libbpf, ring buffers must be polled in a separate thread. I do something akin to the following in a separate thread: while (!g_exiting) {
err = ring_buffer__poll(rb, 100 /* timeout */);
if (err < 0 && err != -EINTR) {
perror("ring_buffer__poll");
abort();
}
}
g_exited.set(); For the ERTS to exit successfully, I need to modify the For now, I hard-code 100ms as a timeout for polling, but in the future, this value could be injected from the config :bpf,
ring_buffer_polling_timeout: 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API looks great, I dropped one comment with alternative implementation :)
While using `fine::Registration` incurs some runtime-cost, there is no longer any constraints on the order of callback registration and `FINE_INIT`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comments and looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic, thank you! 🍵
It is sometimes necessary for a NIF to have some global initialization logic in its load callback, like we already have for atom and resource registration.
This commit inlines the
fine::__private__::load
function in theFINE_INIT
macro to delay template instantiation of a newfine::__private__::OnLoad
struct that can be overriden by a user using theFINE_LOAD(env)
macro to provide customized initialization logic, while still registering atoms and resources.