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

Update the reader's tail to its position if no data is mapped #50

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

aliddell
Copy link
Member

We needed to update the reader's tail to the reader's position, not the writer's head.

@aliddell aliddell requested a review from nclack August 19, 2024 21:09
size_t* const pos = self->holds.pos + reader->id - 1;
uint8_t* out = self->data + *pos;
size_t* const tail = self->holds.pos + reader->id - 1;
uint8_t* out = self->data + *tail;
Copy link
Member

Choose a reason for hiding this comment

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

this is a nit and I think you can judge best but I still like pos. It's probably worth noting in a comment that channel_reader holds the next reader tail.


if (reader->state == ChannelState_Mapped) {
reader->status = Channel_Expected_Unmapped_Reader;
goto AdvanceToWriterHead;
goto AdvanceTailToReaderPos;
Copy link
Member

Choose a reason for hiding this comment

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

still want AdvanceToWriterHead for this exception

@@ -198,7 +198,7 @@ channel_read_map(struct channel* self, struct channel_reader* reader)
// here. A call to channel_read_unmap() would return early and not advance
// the reader's bookmarks in that case, so we need to do it here.
if (!nbytes) {
goto AdvanceToWriterHead;
goto AdvanceTailToReaderPos;
Copy link
Member

Choose a reason for hiding this comment

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

As discussed, replace this w your fix

    out = 0;
    nbytes = 0;
    *pos = self->head;
    *tail = reader->pos;

and use an else to leave the reader->state Unmapped.

@@ -208,10 +208,10 @@ channel_read_map(struct channel* self, struct channel_reader* reader)
return (struct slice){ .beg = out, .end = out + nbytes };
Overflow:
reader->status = Channel_Error;
AdvanceToWriterHead:
AdvanceTailToReaderPos:
Copy link
Member

Choose a reason for hiding this comment

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

The old behavior is probably best for that mapping exception.

Copy link
Member

@nclack nclack left a comment

Choose a reason for hiding this comment

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

lgtm!

@nclack nclack merged commit 8e3e995 into acquire-project:main Aug 20, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants