Commit 3e0e38e6 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Mauro Carvalho Chehab

V4L/DVB (5724): Saa7134-tvaudio: kthread conversion

Acked-by: default avatarHermann Pitton <hermann-pitton@arcor.de>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent b2083199
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <asm/div64.h> #include <asm/div64.h>
...@@ -341,10 +342,8 @@ static void tvaudio_setmode(struct saa7134_dev *dev, ...@@ -341,10 +342,8 @@ static void tvaudio_setmode(struct saa7134_dev *dev,
static int tvaudio_sleep(struct saa7134_dev *dev, int timeout) static int tvaudio_sleep(struct saa7134_dev *dev, int timeout)
{ {
DECLARE_WAITQUEUE(wait, current); if (dev->thread.scan1 == dev->thread.scan2 &&
!kthread_should_stop()) {
add_wait_queue(&dev->thread.wq, &wait);
if (dev->thread.scan1 == dev->thread.scan2 && !dev->thread.shutdown) {
if (timeout < 0) { if (timeout < 0) {
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
schedule(); schedule();
...@@ -353,7 +352,6 @@ static int tvaudio_sleep(struct saa7134_dev *dev, int timeout) ...@@ -353,7 +352,6 @@ static int tvaudio_sleep(struct saa7134_dev *dev, int timeout)
(msecs_to_jiffies(timeout)); (msecs_to_jiffies(timeout));
} }
} }
remove_wait_queue(&dev->thread.wq, &wait);
return dev->thread.scan1 != dev->thread.scan2; return dev->thread.scan1 != dev->thread.scan2;
} }
...@@ -505,11 +503,10 @@ static int tvaudio_thread(void *data) ...@@ -505,11 +503,10 @@ static int tvaudio_thread(void *data)
unsigned int i, audio, nscan; unsigned int i, audio, nscan;
int max1,max2,carrier,rx,mode,lastmode,default_carrier; int max1,max2,carrier,rx,mode,lastmode,default_carrier;
daemonize("%s", dev->name);
allow_signal(SIGTERM); allow_signal(SIGTERM);
for (;;) { for (;;) {
tvaudio_sleep(dev,-1); tvaudio_sleep(dev,-1);
if (dev->thread.shutdown || signal_pending(current)) if (kthread_should_stop() || signal_pending(current))
goto done; goto done;
restart: restart:
...@@ -618,7 +615,7 @@ static int tvaudio_thread(void *data) ...@@ -618,7 +615,7 @@ static int tvaudio_thread(void *data)
for (;;) { for (;;) {
if (tvaudio_sleep(dev,5000)) if (tvaudio_sleep(dev,5000))
goto restart; goto restart;
if (dev->thread.shutdown || signal_pending(current)) if (kthread_should_stop() || signal_pending(current))
break; break;
if (UNSET == dev->thread.mode) { if (UNSET == dev->thread.mode) {
rx = tvaudio_getstereo(dev,&tvaudio[i]); rx = tvaudio_getstereo(dev,&tvaudio[i]);
...@@ -634,7 +631,6 @@ static int tvaudio_thread(void *data) ...@@ -634,7 +631,6 @@ static int tvaudio_thread(void *data)
} }
done: done:
complete_and_exit(&dev->thread.exit, 0);
return 0; return 0;
} }
...@@ -782,7 +778,6 @@ static int tvaudio_thread_ddep(void *data) ...@@ -782,7 +778,6 @@ static int tvaudio_thread_ddep(void *data)
struct saa7134_dev *dev = data; struct saa7134_dev *dev = data;
u32 value, norms, clock; u32 value, norms, clock;
daemonize("%s", dev->name);
allow_signal(SIGTERM); allow_signal(SIGTERM);
clock = saa7134_boards[dev->board].audio_clock; clock = saa7134_boards[dev->board].audio_clock;
...@@ -796,7 +791,7 @@ static int tvaudio_thread_ddep(void *data) ...@@ -796,7 +791,7 @@ static int tvaudio_thread_ddep(void *data)
for (;;) { for (;;) {
tvaudio_sleep(dev,-1); tvaudio_sleep(dev,-1);
if (dev->thread.shutdown || signal_pending(current)) if (kthread_should_stop() || signal_pending(current))
goto done; goto done;
restart: restart:
...@@ -876,7 +871,6 @@ static int tvaudio_thread_ddep(void *data) ...@@ -876,7 +871,6 @@ static int tvaudio_thread_ddep(void *data)
} }
done: done:
complete_and_exit(&dev->thread.exit, 0);
return 0; return 0;
} }
...@@ -973,7 +967,6 @@ int saa7134_tvaudio_getstereo(struct saa7134_dev *dev) ...@@ -973,7 +967,6 @@ int saa7134_tvaudio_getstereo(struct saa7134_dev *dev)
int saa7134_tvaudio_init2(struct saa7134_dev *dev) int saa7134_tvaudio_init2(struct saa7134_dev *dev)
{ {
DECLARE_MUTEX_LOCKED(sem);
int (*my_thread)(void *data) = NULL; int (*my_thread)(void *data) = NULL;
switch (dev->pci->device) { switch (dev->pci->device) {
...@@ -986,15 +979,15 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev) ...@@ -986,15 +979,15 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev)
break; break;
} }
dev->thread.pid = -1; dev->thread.thread = NULL;
if (my_thread) { if (my_thread) {
/* start tvaudio thread */ /* start tvaudio thread */
init_waitqueue_head(&dev->thread.wq); dev->thread.thread = kthread_run(my_thread, dev, "%s", dev->name);
init_completion(&dev->thread.exit); if (IS_ERR(dev->thread.thread)) {
dev->thread.pid = kernel_thread(my_thread,dev,0);
if (dev->thread.pid < 0)
printk(KERN_WARNING "%s: kernel_thread() failed\n", printk(KERN_WARNING "%s: kernel_thread() failed\n",
dev->name); dev->name);
/* XXX: missing error handling here */
}
saa7134_tvaudio_do_scan(dev); saa7134_tvaudio_do_scan(dev);
} }
...@@ -1005,11 +998,9 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev) ...@@ -1005,11 +998,9 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev)
int saa7134_tvaudio_fini(struct saa7134_dev *dev) int saa7134_tvaudio_fini(struct saa7134_dev *dev)
{ {
/* shutdown tvaudio thread */ /* shutdown tvaudio thread */
if (dev->thread.pid > 0) { if (dev->thread.thread)
dev->thread.shutdown = 1; kthread_stop(dev->thread.thread);
wake_up_interruptible(&dev->thread.wq);
wait_for_completion(&dev->thread.exit);
}
saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x07, 0x00); /* LINE1 */ saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x07, 0x00); /* LINE1 */
return 0; return 0;
} }
...@@ -1020,10 +1011,10 @@ int saa7134_tvaudio_do_scan(struct saa7134_dev *dev) ...@@ -1020,10 +1011,10 @@ int saa7134_tvaudio_do_scan(struct saa7134_dev *dev)
dprintk("sound IF not in use, skipping scan\n"); dprintk("sound IF not in use, skipping scan\n");
dev->automute = 0; dev->automute = 0;
saa7134_tvaudio_setmute(dev); saa7134_tvaudio_setmute(dev);
} else if (dev->thread.pid >= 0) { } else if (dev->thread.thread) {
dev->thread.mode = UNSET; dev->thread.mode = UNSET;
dev->thread.scan2++; dev->thread.scan2++;
wake_up_interruptible(&dev->thread.wq); wake_up_process(dev->thread.thread);
} else { } else {
dev->automute = 0; dev->automute = 0;
saa7134_tvaudio_setmute(dev); saa7134_tvaudio_setmute(dev);
...@@ -1040,4 +1031,3 @@ EXPORT_SYMBOL(saa7134_tvaudio_setmute); ...@@ -1040,4 +1031,3 @@ EXPORT_SYMBOL(saa7134_tvaudio_setmute);
* c-basic-offset: 8 * c-basic-offset: 8
* End: * End:
*/ */
...@@ -328,10 +328,7 @@ struct saa7134_pgtable { ...@@ -328,10 +328,7 @@ struct saa7134_pgtable {
/* tvaudio thread status */ /* tvaudio thread status */
struct saa7134_thread { struct saa7134_thread {
pid_t pid; struct task_struct *thread;
struct completion exit;
wait_queue_head_t wq;
unsigned int shutdown;
unsigned int scan1; unsigned int scan1;
unsigned int scan2; unsigned int scan2;
unsigned int mode; unsigned int mode;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment