Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor clean-ups in runtime/io.c and runtime/caml/io.h #10136

Merged
merged 8 commits into from
Jan 24, 2021
4 changes: 1 addition & 3 deletions runtime/caml/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ struct channel {
char * max; /* Logical end of the buffer (for input) */
void * mutex; /* Placeholder for mutex (for systhreads) */
struct channel * next, * prev;/* Double chaining of channels (flush_all) */
int revealed; /* For Cash only */
int old_revealed; /* For Cash only */
int refcount; /* For flush_all and for Cash */
int refcount; /* For flush_all */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refcount can go too. It is only increased inside caml_alloc_channel to prevent a race with finalisation (#8191), but finalisation no longer happens during allocation from C.

Copy link
Contributor

@gadmm gadmm Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon closer inspection refcount needs to stay, but the comment /* prevent finalization during next alloc */ should be fixed to better match the purpose of the reference count :)

The test for refcount > 0 inside caml_close_channel is now pointless and can be changed into an assertion refcount == 0.

Copy link
Contributor

@gadmm gadmm Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would document

  int refcount;                 /* Number of custom blocks owning the struct */

and remove CHANNEL_FLAG_MANAGED_BY_GC.

int flags; /* Bitfield */
char buff[IO_BUFFER_SIZE]; /* The buffer itself */
char * name; /* Optional name (to report fd leaks) */
Expand Down
2 changes: 0 additions & 2 deletions runtime/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ CAMLexport struct channel * caml_open_descriptor_in(int fd)
channel->curr = channel->max = channel->buff;
channel->end = channel->buff + IO_BUFFER_SIZE;
channel->mutex = NULL;
channel->revealed = 0;
channel->old_revealed = 0;
channel->refcount = 0;
channel->flags = descriptor_is_in_binary_mode(fd) ? 0 : CHANNEL_TEXT_MODE;
channel->next = caml_all_opened_channels;
Expand Down