pex: Cleanup pipes?

This commit is contained in:
K. Lange 2021-09-12 14:04:11 +09:00
parent 5816937516
commit 0068e25073
2 changed files with 38 additions and 17 deletions

View File

@ -31,6 +31,8 @@
#include <kernel/spinlock.h>
#include <kernel/process.h>
extern void pipe_destroy(fs_node_t * node);
#include <sys/ioctl.h>
#define MAX_PACKET_SIZE 1024
@ -255,22 +257,21 @@ static void close_client(fs_node_t * node) {
pex_client_t * c = (pex_client_t *)node->inode;
pex_ex_t * p = c->parent;
debug_print(WARNING, "Closing packetfs client: %p:%p", (void*)p, (void*)c);
spin_lock(p->lock);
node_t * n = list_find(p->clients, c);
if (n && n->owner == p->clients) {
list_delete(p->clients, n);
free(n);
if (p) {
debug_print(WARNING, "Closing packetfs client: %p:%p", (void*)p, (void*)c);
spin_lock(p->lock);
node_t * n = list_find(p->clients, c);
if (n && n->owner == p->clients) {
list_delete(p->clients, n);
free(n);
}
spin_unlock(p->lock);
char tmp[1];
send_to_server(p, c, 0, tmp);
}
spin_unlock(p->lock);
char tmp[1];
send_to_server(p, c, 0, tmp);
pipe_destroy(c->pipe);
free(c->pipe);
free(c);
}
@ -309,15 +310,20 @@ static void close_server(fs_node_t * node) {
/* Tell all clients we have disconnected */
spin_lock(ex->lock);
foreach(f, ex->clients) {
while (ex->clients->length) {
node_t * f = list_pop(ex->clients);
pex_client_t * client = (pex_client_t*)f->value;
send_to_client(ex, client, 0, NULL);
client->parent = NULL;
free(f);
}
spin_unlock(ex->lock);
/* TODO Free resources */
free(ex->clients);
pipe_destroy(ex->server_pipe);
free(ex->server_pipe);
node->device = NULL;
free(ex);
spin_unlock(p->lock);

View File

@ -228,6 +228,21 @@ static int pipe_wait(fs_node_t * node, void * process) {
return 0;
}
void pipe_destroy(fs_node_t * node) {
pipe_device_t * pipe = (pipe_device_t *)node->device;
spin_lock(pipe->ptr_lock);
pipe->dead = 1;
pipe_alert_waiters(pipe);
wakeup_queue(pipe->wait_queue_writers);
wakeup_queue(pipe->wait_queue_readers);
free(pipe->alert_waiters);
free(pipe->wait_queue_writers);
free(pipe->wait_queue_readers);
free(pipe->buffer);
spin_unlock(pipe->ptr_lock);
free(pipe);
}
fs_node_t * make_pipe(size_t size) {
fs_node_t * fnode = malloc(sizeof(fs_node_t));
pipe_device_t * pipe = malloc(sizeof(pipe_device_t));