From 47501a9a39d7835d4c80aa8ed7531c6c101101fb Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Tue, 2 Mar 2021 22:41:35 +1100 Subject: libmachdev: Spawn a thread for server loop so main pathway can continue Message-Id: <20210302114137.592230-3-damien@zamaudio.com> --- libmachdev/trivfs_server.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'libmachdev/trivfs_server.c') diff --git a/libmachdev/trivfs_server.c b/libmachdev/trivfs_server.c index 3ab15049..d1d3a71d 100644 --- a/libmachdev/trivfs_server.c +++ b/libmachdev/trivfs_server.c @@ -398,7 +398,8 @@ machdev_trivfs_init(mach_port_t bootstrap_resume_task, const char *name, const c if (path) devnode = strdup(path); resume_bootstrap_server(bootstrap_resume_task, name); - *bootstrap = MACH_PORT_NULL; + *bootstrap = ports_get_send_right (&control->pi); + /* We need to install as a translator later */ bootstrapped = TRUE; } @@ -479,13 +480,29 @@ trivfs_modify_stat (struct trivfs_protid *cred, io_statbuf_t *stat) { } +static void * +machdev_trivfs_loop(void *arg) +{ + struct trivfs_control *fsys = (struct trivfs_control *)arg; + + /* Launch. */ + do + { + ports_manage_port_operations_one_thread (port_bucket, demuxer, 0); + } while (trivfs_goaway (fsys, 0)); + + /* Never reached */ + return 0; +} + void machdev_trivfs_server(mach_port_t bootstrap) { struct trivfs_control *fsys = NULL; int err; + pthread_t t; - if (bootstrap != MACH_PORT_NULL) + if (bootstrapped == FALSE) { /* This path is executed when a parent exists */ err = trivfs_startup (bootstrap, 0, @@ -500,9 +517,8 @@ machdev_trivfs_server(mach_port_t bootstrap) fsys = control; } - /* Launch. */ - do - { - ports_manage_port_operations_one_thread (port_bucket, demuxer, 0); - } while (trivfs_goaway (fsys, 0)); + err = pthread_create (&t, NULL, machdev_trivfs_loop, (void *)fsys); + if (err) + error (1, err, "Creating machdev server thread"); + pthread_detach (t); } -- cgit v1.2.3