-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update the reader's tail to its position if no data is mapped #50
Conversation
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
We needed to update the reader's tail to the reader's position, not the writer's head.