bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/4] libmachdev: Spawn a thread for server loop so main pathway c


From: Damien Zammit
Subject: [PATCH 2/4] libmachdev: Spawn a thread for server loop so main pathway can continue
Date: Tue, 2 Mar 2021 22:41:35 +1100

---
 libmachdev/trivfs_server.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libmachdev/trivfs_server.c b/libmachdev/trivfs_server.c
index 3ab15049..06756f82 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,9 @@ 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);
 }
+
-- 
2.30.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]