<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 11, 2014 at 4:38 PM, Vincent Siliakus <span dir="ltr"><<a href="mailto:zambal@gmail.com" target="_blank">zambal@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I'm experimenting a bit with the new dirty scheduler functionality for<br>

NIFs and have already some working code, but I was wondering what the<br>
purpose is of enif_schedule_dirty_nif_finalizer and<br>
enif_dirty_nif_finalizer.<br>
<br>
I know documentation about dirty schedulers should be coming when OTP<br>
17.0 is released, but maybe somebody can already give some pointers<br>
about how and why they should be used.</blockquote><div><br></div><div>Below find the descriptions that are in the 17.0 documentation sources on github master. If you have further questions, let me know. BTW both descriptions are accompanied by this note:</div>
<div><br></div><div><div>This function is available only when the emulator is configured with dirty schedulers enabled. This feature is currently disabled by default. To determine whether the dirty NIF API is available, native code can check to see if the C preprocessor macro ERL_NIF_DIRTY_SCHEDULER_SUPPORT is defined.</div>
</div><div><br></div><div>Oh, and all of this is subject to change, of course, as this is an experimental feature of 17.0.</div><div><br></div><div>--steve</div><div><br></div><div><br></div><div>ERL_NIF_TERM enif_schedule_dirty_nif_finalizer(ErlNifEnv* env, ERL_NIF_TERM result, ERL_NIF_TERM (*fp)(ErlNifEnv* env, ERL_NIF_TERM result))<br>
</div><div><div><br></div><div>When a dirty NIF finishes executing, it must schedule a finalizer function to return its result to the original NIF caller. The dirty NIF passes result as the value it wants the finalizer to use as the return value. The fp argument is a pointer to the finalizer function. The NIF API provides the enif_dirty_nif_finalizer function that can be used as a finalizer that simply returns its result argument. You are also free to write your own custom finalizer that uses result to derive a different return value, or ignores result entirely and returns a completely different value.</div>
<div><br></div><div>Without exception, all dirty NIFs must invoke enif_schedule_dirty_nif_finalizer to complete their execution.</div><div><br></div><div><div>ERL_NIF_TERM enif_dirty_nif_finalizer(ErlNifEnv* env, ERL_NIF_TERM result)</div>
<div><br></div><div>A convenience function that a dirty NIF can use as a finalizer that simply return its result argument as its return value. This function is provided for dirty NIFs with results that should be returned directly to the original caller.</div>
</div></div></div></div></div>