Linked-list-based mail packets
Some checks failed
Build documentation / build-and-deploy (push) Has been cancelled
Some checks failed
Build documentation / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include <libk/list.h>
|
||||
#include <libk/minmax.h>
|
||||
#include <libk/ringbuffer.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <mm/malloc.h>
|
||||
@@ -18,8 +17,6 @@ void proc_cleanup_resource_mail (struct proc_resource* resource, struct reschedu
|
||||
|
||||
spin_lock (&mail->resource->lock, &fr);
|
||||
|
||||
ringbuffer_fini (&mail->ringbuffer);
|
||||
|
||||
spin_lock (&mail->send_sq.lock, &fssq);
|
||||
|
||||
while (mail->send_sq.proc_list != NULL) {
|
||||
@@ -47,7 +44,7 @@ void proc_mail_send (struct proc* proc, struct proc_mail* mail, struct reschedul
|
||||
spin_lock (&mail->resource->lock, &fr);
|
||||
|
||||
/* mail full */
|
||||
if (mail->ringbuffer.count == mail->ringbuffer.capacity) {
|
||||
if (mail->packets_count == PROC_MAIL_MAX) {
|
||||
proc_sq_suspend (proc, &mail->send_sq, &mail->resource->lock, fr, rctx);
|
||||
return;
|
||||
}
|
||||
@@ -86,8 +83,19 @@ void proc_mail_send (struct proc* proc, struct proc_mail* mail, struct reschedul
|
||||
void* mesg = malloc (data_size);
|
||||
if (mesg != NULL) {
|
||||
memcpy (mesg, data, data_size);
|
||||
struct mail_packet packet = {.packet_buffer = mesg, .packet_size = data_size};
|
||||
ringbuffer_push (struct mail_packet, &mail->ringbuffer, packet);
|
||||
|
||||
struct mail_packet* packet = malloc (sizeof (*packet));
|
||||
|
||||
if (packet == NULL) {
|
||||
free (mesg);
|
||||
} else {
|
||||
memset (packet, 0, sizeof (*packet));
|
||||
packet->packet_buffer = mesg;
|
||||
packet->packet_size = data_size;
|
||||
|
||||
list_append (mail->packets, &packet->packets_link);
|
||||
mail->packets_count++;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock (&mail->resource->lock, fr);
|
||||
@@ -105,11 +113,14 @@ void proc_mail_receive (struct proc* proc, struct proc_mail* mail, struct resche
|
||||
spin_lock (&mail->resource->lock, &fr);
|
||||
|
||||
/* consume mesg if available */
|
||||
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);
|
||||
if (mail->packets_count > 0) {
|
||||
struct mail_packet* packet = list_entry (mail->packets, struct mail_packet, packets_link);
|
||||
list_remove (mail->packets, &packet->packets_link);
|
||||
mail->packets_count--;
|
||||
|
||||
memcpy (recv_buffer, packet->packet_buffer, min (recv_size, packet->packet_size));
|
||||
free (packet->packet_buffer);
|
||||
free (packet);
|
||||
|
||||
/* check for suspended sender */
|
||||
spin_lock (&mail->send_sq.lock, &fssq);
|
||||
|
||||
Reference in New Issue
Block a user