[erlang-questions] Implementing enif_whereis

Ted Burghart ted.ml.erlang@REDACTED
Thu Mar 30 17:01:41 CEST 2017

My working code is at https://github.com/tburghart/otp/tree/trb/erts/enif_whereis <https://github.com/tburghart/otp/tree/trb/erts/enif_whereis>

I'm adding tests for behavior on dirty schedulers and background threads, which may result in checks in enif_whereis to bail out in contexts where it can't execute properly.

Comments are welcome!

> On 30-Mar 2017, at 7:41 AM, Ted Burghart <ted.ml.erlang@REDACTED> wrote:
> Hello,
> I've implemented an enif_whereis function on a branch of master (OTP-20), and I have a couple of questions.
> This turned out to be pretty simple, and I'm wondering if something this small needs to go through the full EEP process or if it can be PR'd in, and does it need a Jira issue?
> The current function implementation (in erl_nif.c) is as follows:
> int enif_whereis(ErlNifEnv *env, ERL_NIF_TERM name, ERL_NIF_TERM *out)
> {
>    if (is_atom(name)) {
>        Process* c_p;
>        Eterm res;
>        execution_state(env, &c_p, NULL);
>        res = erts_whereis_name_to_id(c_p, name);
>        if (is_not_atom(res)) {
>            *out = enif_make_copy(env, res);
>            return 1;
>        }
>    }
>    return 0;
> }
> This works fine for pids and ports, and one of my tests calls it from lots of parallel processes without any issues (both with and without lock checking enabled).
> It's got docs and tests, and I'm preparing the EEP Lite commit comment to be pushed shortly.
> So, anyone want to throw some darts at it?
> – Ted

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170330/bdd550a9/attachment.htm>

More information about the erlang-questions mailing list