erts_port_control() and binp

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

erts_port_control() and binp

Salikhov Dinislam
Hello!

I'm looking through VM sources now.
In erts/emulator/beam/erl_port.h there is a 'struct
ErtsProc2PortSigData_' with a union as the last field.
One of the values of this union is 'struct control'.
I'm interesting in the field binp of the struct control.

I grepped through the sources and found that the struct is used only in
a few places in erts/emulator/beam/io.c
Except the places where the field is set, it's used only as an argument
of cleanup_scheduled_control() in the same file.
So what's the meaning of the field binp? What is it needed for?

Salikhov Dinislam
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: erts_port_control() and binp

Salikhov Dinislam
Finally, I've figured it out:
bufp either contains a copy of data passed to port as binary or points
to the data inside the passed binary.
In the latter case refcount of the binary is incremented and the pointer
to binary is kept in binp field, so the buffer in use wouldn't be
garbage collected.

Salikhov Dinislam

On 12/09/2016 04:19 PM, Salikhov Dinislam wrote:

> Hello!
>
> I'm looking through VM sources now.
> In erts/emulator/beam/erl_port.h there is a 'struct
> ErtsProc2PortSigData_' with a union as the last field.
> One of the values of this union is 'struct control'.
> I'm interesting in the field binp of the struct control.
>
> I grepped through the sources and found that the struct is used only
> in a few places in erts/emulator/beam/io.c
> Except the places where the field is set, it's used only as an
> argument of cleanup_scheduled_control() in the same file.
> So what's the meaning of the field binp? What is it needed for?
>
> Salikhov Dinislam

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: erts_port_control() and binp

Salikhov Dinislam
See ./erts/emulator/beam/io.c
erts_port_control() calls erts_refc_inc() if original binary should be used.
Then the pointer to binary is kept in sigdp->u.control.binp.
When the data is not needed any more, cleanup_scheduled_control() is called. It calls erts_refc_dectest() if original binary is used.

On 12/09/2016 06:02 PM, Frank Muller wrote:
Which code is responsible of incr/decr binary refcount?


Le ven. 9 déc. 2016 à 16:01, Salikhov Dinislam <[hidden email]> a écrit :
Finally, I've figured it out:

bufp either contains a copy of data passed to port as binary or points

to the data inside the passed binary.

In the latter case refcount of the binary is incremented and the pointer

to binary is kept in binp field, so the buffer in use wouldn't be

garbage collected.



Salikhov Dinislam



On 12/09/2016 04:19 PM, Salikhov Dinislam wrote:

> Hello!

>

> I'm looking through VM sources now.

> In erts/emulator/beam/erl_port.h there is a 'struct

> ErtsProc2PortSigData_' with a union as the last field.

> One of the values of this union is 'struct control'.

> I'm interesting in the field binp of the struct control.

>

> I grepped through the sources and found that the struct is used only

> in a few places in erts/emulator/beam/io.c

> Except the places where the field is set, it's used only as an

> argument of cleanup_scheduled_control() in the same file.

> So what's the meaning of the field binp? What is it needed for?

>

> Salikhov Dinislam



_______________________________________________

erlang-questions mailing list

[hidden email]

http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions