From: Arne R. <arn...@xi...> - 2006-07-04 14:45:51
|
Use a completion instead of waiting an arbitrary amount of time (1s) to make sure the threads are really gone. Only mildly tested, but I didn't run into any troubles. Mostly because the threads usually exited quite early, i.e. the while(atomic_read()) loop wasn't even entered. Any feedback is welcome. Signed-off-by: Arne Redlich <arn...@xi...> Index: src/dev_handlers/scst_fileio.c =================================================================== RCS file: /cvsroot/scst/src/dev_handlers/scst_fileio.c,v retrieving revision 1.29 diff -a -u -p -r1.29 scst_fileio.c --- src/dev_handlers/scst_fileio.c 10 Jun 2006 16:05:28 -0000 1.29 +++ src/dev_handlers/scst_fileio.c 2 Jul 2006 18:58:54 -0000 @@ -110,6 +110,7 @@ struct scst_fileio_tgt_dev { atomic_t threads_count; struct semaphore shutdown_mutex; struct list_head ftgt_list_entry; + struct completion done; }; static int fileio_attach(struct scst_device *dev); @@ -582,6 +583,7 @@ static int fileio_cmd_thread(void *arg) up(&ftgt_dev->shutdown_mutex); } + complete(&ftgt_dev->done); TRACE_EXIT(); return 0; } @@ -610,6 +612,7 @@ static int fileio_attach_tgt(struct scst init_waitqueue_head(&ftgt_dev->fdev_waitQ); atomic_set(&ftgt_dev->threads_count, 0); init_MUTEX_LOCKED(&ftgt_dev->shutdown_mutex); + init_completion(&ftgt_dev->done); ftgt_dev->fd = fileio_open(virt_dev); if (IS_ERR(ftgt_dev->fd)) { @@ -668,6 +671,9 @@ static void fileio_detach_tgt(struct scs wake_up_all(&ftgt_dev->fdev_waitQ); down(&ftgt_dev->shutdown_mutex); + while (atomic_read(&ftgt_dev->threads_count)) + wait_for_completion(&ftgt_dev->done); + filp_close(ftgt_dev->fd, NULL); if (ftgt_dev->iv != NULL) { @@ -3007,17 +3013,6 @@ static void __exit exit_scst_fileio_driv { exit_scst_fileio(&disk_devtype_fileio, &disk_fileio_dev_list); exit_scst_fileio(&cdrom_devtype_fileio, &cdrom_fileio_dev_list); - - /* - * Wait for one sec. to allow the thread(s) actually exit, - * otherwise we can get Oops. Any better way? - */ - { - unsigned long t = jiffies; - TRACE_DBG("%s", "Waiting 1 sec..."); - while ((jiffies - t) < HZ) - schedule(); - } } module_init(init_scst_fileio_driver); |