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

libsel4camkes/virtqueue: use const qualifier #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

axel-h
Copy link
Member

@axel-h axel-h commented May 24, 2023

Ensure const correctness is kept. Sending a buffer implies that the buffer is not modified.

Without this change, there is always a compiler warning if a buffer with a const qualifier is passed to these APIs. Casting away the const qualifier contradicts the intention of using const.

@axel-h
Copy link
Member Author

axel-h commented May 25, 2023

It seems the test failure happens due to a race condition, where the output from different thread overlaps. Instead of echo_int: 2 we get

echo_int: client Event received!
client Event received!
Sender Event received!
2

@@ -147,7 +147,7 @@ void *camkes_virtqueue_driver_offset_to_buffer(virtqueue_driver_t *virtqueue, ui
* @param size the size of the buffer
* @return 0 on success, -1 on fail
*/
int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, void *buffer, size_t size);
int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, const void *buffer, size_t size);
Copy link
Member

Choose a reason for hiding this comment

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

I think this function is also used for enqueuing buffers in the virtqueue to receive data on?

In this case send means that the buffer is being sent to the other end of the queue (the device side). If the queue is used for transmitting data then the data in the buffer would be read by the other end, but if the queue is being used for receiving data then the other side would modify the contents before sending it back.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point. Would it make sense to separate the APIs then for the different use cases to support proper semantics?

Copy link
Member

Choose a reason for hiding this comment

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

What if the semantics are just enqueuing into available hands a mutable reference over, and receiving from the other queue takes it back. Whether the buffers are written to by the other side is a higher level concern depending on the protocol using the buffers.

Ensure const correctness is kept. Sending a buffer implies that the
buffer is not modified.

Signed-off-by: Axel Heider <[email protected]>
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