[erlang-questions] driver_async() marks driver as permanent?

Paul Fisher <>
Sat Apr 5 03:29:04 CEST 2008


On Fri, 2008-04-04 at 09:41 -0500, Paul Fisher wrote:
> Does using driver_async() from within a linked-in driver mark the driver
> as permanent automatically?  I am seeing an {error, permanent} out of
> erl_ddll:unload_driver/1 even after all of the processes which called
> open_port/2 have exited, and therefore all of the port instances using
> the driver have stopped.
> 
> If this is done automatically, is there a way to "unmark" it, so that I
> can still unload the driver?

Answering my own question again...  I got some time this evening to look
into this, and apparently the answer is yes.  This little tidbit in
erts/emulator/beam/erl_async.c:async_add(), line 139 (R12B-1):

    /* XXX:PaN Is this still necessary when ports lock drivers? */
    if (is_internal_port(a->port)) {
	ERTS_LC_ASSERT(erts_drvportid2port(a->port));
	/* make sure the driver will stay around */
	driver_lock_driver(internal_port_index(a->port));
    }

which eventually winds its way down to this in erl_bif_ddll.c, line 1109

    dh->procs = NULL;
    erts_ddll_reference_driver(dh);
    dh->status = ERL_DE_PERMANENT;

and there is not any place that removes that status value, that I can
find on brief inspection. (Basically only initialization/reload code
sets this field.)

So is the comment in async_add() proper and this could be removed?  (I'd
appreciate some guidance on this as this is the first time i've mucked
around the runtime code and just don't have the background yet to make
informed decisions.)


--
paul




More information about the erlang-questions mailing list