circuits_gpio icon indicating copy to clipboard operation
circuits_gpio copied to clipboard

Look up registered names when sending notifications

Open fhunleth opened this issue 7 years ago • 3 comments

Currently, registered process names are supported, but the name-to-pid translation happens when interrupts are enabled. To handle the case where the registered process dies and comes back, the lookup really should happen on the send call. This involves changes to the NIF.

fhunleth avatar Nov 12 '18 21:11 fhunleth

You're right, but how much overhead does that add, calling the equivalent of whereis() inside the NIF (Is that even possible?) for every interrupt? I almost think we should not allow using registered names to set the interrupt in the first place.

It seems to me, the process that sets the original interrupt should perform the name-to-pid translation and set the interrupt again (with the new PID) if the receiver process dies and comes back. In other words, just leave `whereis()' out of circuits_gpio.

mdsebald avatar Nov 13 '18 00:11 mdsebald

I'd expect the overhead of this to be equivalent to any send in Elixir or Erlang. I would assume that specifying a pid would be the same performance as now and that destinations involving registry lookups would be slower.

The point I meant to make was that if a user can specify where to send messages, then any destination that Erlang or Elixir allows by default should be valid. http://erlang.org/doc/man/erlang.html#send-2.

While I could see us being opinionated and restricting the kinds of message passing that can be done, that makes me feel a little uneasy. At least I'm not sure that there's any intrinsically different about a GPIO library, then, say, any other library.

fhunleth avatar Nov 13 '18 00:11 fhunleth

OK. I see erl_nif has an enif_whereis_pid() function. So the only downside is adding logic to determine if that should be called, on each interrupt. Probably not a big deal.

mdsebald avatar Nov 13 '18 12:11 mdsebald