Files
mop3/kernel/proc/stream.c
kamkow1 e5ebd7f3ba
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 2m21s
Build documentation / build-and-deploy (push) Successful in 54s
Use a big-lock for kernel sychronization instead of fine-grained locking
2026-04-27 18:06:02 +02:00

39 lines
959 B
C

#include <libk/list.h>
#include <libk/ringbuffer.h>
#include <libk/std.h>
#include <proc/proc.h>
#include <proc/reschedule.h>
#include <proc/resource.h>
#include <proc/stream.h>
#include <proc/suspension_q.h>
void proc_stream_write(struct proc_stream* stream, void* data, size_t data_size) {
for (size_t i = 0; i < data_size; i++)
ringbuffer_push(uint8_t, &stream->ringbuffer, ((uint8_t*)data)[i]);
}
size_t proc_stream_read(struct proc_stream* stream, void* out_data, size_t data_size) {
size_t bytes = 0;
uint8_t* p = (uint8_t*)out_data;
for (size_t i = 0; i < data_size; i++) {
if (stream->ringbuffer.count == 0) {
break;
}
ringbuffer_pop(uint8_t, &stream->ringbuffer, &p[i]);
bytes++;
}
return bytes;
}
void proc_cleanup_resource_stream(struct proc_resource* resource, struct reschedule_ctx* rctx) {
(void)rctx;
struct proc_stream* stream = &resource->u.stream;
ringbuffer_fini(&stream->ringbuffer);
}