Use a ring buffer for mail
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m30s

This commit is contained in:
2026-02-21 15:52:31 +01:00
parent 7601ea68e2
commit dc021c0469
3 changed files with 25 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
#include <libk/list.h>
#include <libk/minmax.h>
#include <libk/ringbuffer.h>
#include <libk/std.h>
#include <libk/string.h>
#include <mm/liballoc.h>
@@ -15,10 +16,7 @@ void proc_cleanup_resource_mail (struct proc_resource* resource, struct reschedu
spin_lock (&mail->resource->lock);
if (mail->pending_mesg != NULL)
free (mail->pending_mesg);
mail->pending_mesg_size = 0;
ringbuffer_fini (&mail->ringbuffer);
spin_lock (&mail->send_sq.lock);
@@ -45,7 +43,7 @@ void proc_mail_send (struct proc* proc, struct proc_mail* mail, struct reschedul
spin_lock (&mail->resource->lock);
/* mail full */
if (mail->pending_mesg != NULL) {
if (mail->ringbuffer.count == mail->ringbuffer.capacity) {
proc_sq_suspend (proc, &mail->send_sq, &mail->resource->lock, rctx);
return;
}
@@ -83,9 +81,9 @@ void proc_mail_send (struct proc* proc, struct proc_mail* mail, struct reschedul
/* mail is empty and nobody is waiting */
void* mesg = malloc (data_size);
if (mesg != NULL) {
mail->pending_mesg = mesg;
memcpy (mail->pending_mesg, data, data_size);
mail->pending_mesg_size = data_size;
memcpy (mesg, data, data_size);
struct mail_packet packet = {.packet_buffer = mesg, .packet_size = data_size};
ringbuffer_push (struct mail_packet, &mail->ringbuffer, packet);
}
spin_unlock (&mail->resource->lock);
@@ -101,11 +99,11 @@ void proc_mail_receive (struct proc* proc, struct proc_mail* mail, struct resche
spin_lock (&mail->resource->lock);
/* consume mesg if available */
if (mail->pending_mesg != NULL) {
memcpy (recv_buffer, mail->pending_mesg, min (recv_size, mail->pending_mesg_size));
free (mail->pending_mesg);
mail->pending_mesg = NULL;
mail->pending_mesg_size = 0;
if (mail->ringbuffer.count > 0) {
struct mail_packet packet;
ringbuffer_pop (struct mail_packet, &mail->ringbuffer, &packet);
memcpy (recv_buffer, packet.packet_buffer, min (recv_size, packet.packet_size));
free (packet.packet_buffer);
/* check for suspended sender */
spin_lock (&mail->send_sq.lock);