From 11d6605f3ff664b59025313569a560d6d3bea784 Mon Sep 17 00:00:00 2001 From: manu Date: Sat, 13 Sep 2003 07:56:54 +0000 Subject: [PATCH] Sync between parent and child in iohdisystem thread so that the child has time to get its parmeteres before the parent throw them away --- sys/compat/darwin/darwin_iohidsystem.c | 34 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/sys/compat/darwin/darwin_iohidsystem.c b/sys/compat/darwin/darwin_iohidsystem.c index e2595ad18f14..755c94e5d370 100644 --- a/sys/compat/darwin/darwin_iohidsystem.c +++ b/sys/compat/darwin/darwin_iohidsystem.c @@ -1,4 +1,4 @@ -/* $NetBSD: darwin_iohidsystem.c,v 1.10 2003/09/11 23:16:19 manu Exp $ */ +/* $NetBSD: darwin_iohidsystem.c,v 1.11 2003/09/13 07:56:54 manu Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: darwin_iohidsystem.c,v 1.10 2003/09/11 23:16:19 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: darwin_iohidsystem.c,v 1.11 2003/09/13 07:56:54 manu Exp $"); #include "ioconf.h" #include "wsmux.h" @@ -86,7 +86,8 @@ static void mach_notify_iohidsystem(struct lwp *, struct mach_right *); struct darwin_iohidsystem_thread_args { vaddr_t dita_shmem; - struct proc **dita_p; + struct proc *dita_p; + int dita_done; }; #if 0 @@ -137,7 +138,6 @@ darwin_iohidsystem_connect_method_scalari_scalaro(args) case DARWIN_IOHIDCREATESHMEM: { /* Create the shared memory for HID events */ int version; - struct proc *newpp; int error; size_t memsize; vaddr_t kvaddr; @@ -175,10 +175,21 @@ darwin_iohidsystem_connect_method_scalari_scalaro(args) dita = malloc(sizeof(*dita), M_TEMP, M_WAITOK); dita->dita_shmem = kvaddr; - dita->dita_p = &newpp; + dita->dita_done = 0; kthread_create1(darwin_iohidsystem_thread, - (void *)dita, &newpp, "iohidsystem"); + (void *)dita, &dita->dita_p, "iohidsystem"); + + /* + * Make sure the thread got the informations + * before exitting and destroying dita. + */ + while (!dita->dita_done) + (void)tsleep(&dita->dita_done, + PZERO, "iohid_done", 0); + + free(dita, M_TEMP); + } rep->rep_outcount = 0; break; @@ -294,10 +305,16 @@ darwin_iohidsystem_thread(args) printf("darwin_iohidsystem_thread: start\n"); #endif dita = (struct darwin_iohidsystem_thread_args *)args; - shmem = (struct darwin_iohidsystem_shmem *)dita->dita_shmem; - p = *dita->dita_p; + shmem = (struct darwin_iohidsystem_shmem *)dita->dita_shmem; + p = dita->dita_p; l = proc_representative_lwp(p); + /* + * Allow the parent to get rid of dita. + */ + dita->dita_done = 1; + wakeup(&dita->dita_done); + evg = (struct darwin_iohidsystem_evglobals *)&shmem->dis_evglobals; /* Use the first wsmux available */ @@ -351,7 +368,6 @@ darwin_iohidsystem_thread(args) } exit: - free(dita, M_TEMP); kthread_exit(error); /* NOTREACHED */ };