[erlang-questions] Implementing enif_whereis

Ted Burghart ted.ml.erlang@REDACTED
Sat Apr 1 06:40:37 CEST 2017


Now available as a PR at https://github.com/erlang/otp/pull/1400

I've tested it fairly heavily, and all of the tests that are environment-neutral are included in the CT suites.

The PR comment *should* explain my rationale, but I'd be happy to field questions or comments.

– Ted

> On 30-Mar 2017, at 11:01 AM, Ted Burghart <ted.ml.erlang@REDACTED> wrote:
> 
> 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 <mailto: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
>> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

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


More information about the erlang-questions mailing list