diff options
| author | Cedric Le Goater <clg@fr.ibm.com> | 2006-09-11 15:31:45 -0400 |
|---|---|---|
| committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-09-26 11:30:36 -0400 |
| commit | bc28287979592c015560f8837a98b63a3be8bbc1 (patch) | |
| tree | 8103d470146c201dfe811af5374984e13e17f8df | |
| parent | c93a5c34887426daa70f3caf05881fafb1cd687f (diff) | |
V4L/DVB (4624): Tvaudio: Replaced kernel_thread() with kthread_run()
Replaced kernel_thread() with kthread_run() since kernel_thread() is
deprecated in drivers/modules.
Removed the completion and the wait queue which are now useless with
kthread. Also removed the allow_signal() call as signals don't apply
to kernel threads.
Fixed a small race condition when thread is stopped.
Please check if the timer vs. thread still works fine without the wait
queue.
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
| -rw-r--r-- | drivers/media/video/tvaudio.c | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c index 936e3f746fba..fcaef4bf8289 100644 --- a/drivers/media/video/tvaudio.c +++ b/drivers/media/video/tvaudio.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #include <linux/i2c-algo-bit.h> | 28 | #include <linux/i2c-algo-bit.h> |
| 29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
| 30 | #include <linux/smp_lock.h> | 30 | #include <linux/smp_lock.h> |
| 31 | #include <linux/kthread.h> | ||
| 31 | 32 | ||
| 32 | #include <media/tvaudio.h> | 33 | #include <media/tvaudio.h> |
| 33 | #include <media/v4l2-common.h> | 34 | #include <media/v4l2-common.h> |
| @@ -124,11 +125,8 @@ struct CHIPSTATE { | |||
| 124 | int input; | 125 | int input; |
| 125 | 126 | ||
| 126 | /* thread */ | 127 | /* thread */ |
| 127 | pid_t tpid; | 128 | struct task_struct *thread; |
| 128 | struct completion texit; | ||
| 129 | wait_queue_head_t wq; | ||
| 130 | struct timer_list wt; | 129 | struct timer_list wt; |
| 131 | int done; | ||
| 132 | int watch_stereo; | 130 | int watch_stereo; |
| 133 | int audmode; | 131 | int audmode; |
| 134 | }; | 132 | }; |
| @@ -264,28 +262,23 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) | |||
| 264 | static void chip_thread_wake(unsigned long data) | 262 | static void chip_thread_wake(unsigned long data) |
| 265 | { | 263 | { |
| 266 | struct CHIPSTATE *chip = (struct CHIPSTATE*)data; | 264 | struct CHIPSTATE *chip = (struct CHIPSTATE*)data; |
| 267 | wake_up_interruptible(&chip->wq); | 265 | wake_up_process(chip->thread); |
| 268 | } | 266 | } |
| 269 | 267 | ||
| 270 | static int chip_thread(void *data) | 268 | static int chip_thread(void *data) |
| 271 | { | 269 | { |
| 272 | DECLARE_WAITQUEUE(wait, current); | ||
| 273 | struct CHIPSTATE *chip = data; | 270 | struct CHIPSTATE *chip = data; |
| 274 | struct CHIPDESC *desc = chiplist + chip->type; | 271 | struct CHIPDESC *desc = chiplist + chip->type; |
| 275 | 272 | ||
| 276 | daemonize("%s", chip->c.name); | ||
| 277 | allow_signal(SIGTERM); | ||
| 278 | v4l_dbg(1, debug, &chip->c, "%s: thread started\n", chip->c.name); | 273 | v4l_dbg(1, debug, &chip->c, "%s: thread started\n", chip->c.name); |
| 279 | 274 | ||
| 280 | for (;;) { | 275 | for (;;) { |
| 281 | add_wait_queue(&chip->wq, &wait); | 276 | set_current_state(TASK_INTERRUPTIBLE); |
| 282 | if (!chip->done) { | 277 | if (!kthread_should_stop()) |
| 283 | set_current_state(TASK_INTERRUPTIBLE); | ||
| 284 | schedule(); | 278 | schedule(); |
| 285 | } | 279 | set_current_state(TASK_RUNNING); |
| 286 | remove_wait_queue(&chip->wq, &wait); | ||
| 287 | try_to_freeze(); | 280 | try_to_freeze(); |
| 288 | if (chip->done || signal_pending(current)) | 281 | if (kthread_should_stop()) |
| 289 | break; | 282 | break; |
| 290 | v4l_dbg(1, debug, &chip->c, "%s: thread wakeup\n", chip->c.name); | 283 | v4l_dbg(1, debug, &chip->c, "%s: thread wakeup\n", chip->c.name); |
| 291 | 284 | ||
| @@ -301,7 +294,6 @@ static int chip_thread(void *data) | |||
| 301 | } | 294 | } |
| 302 | 295 | ||
| 303 | v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name); | 296 | v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name); |
| 304 | complete_and_exit(&chip->texit, 0); | ||
| 305 | return 0; | 297 | return 0; |
| 306 | } | 298 | } |
| 307 | 299 | ||
| @@ -1536,19 +1528,18 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind) | |||
| 1536 | chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble)); | 1528 | chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble)); |
| 1537 | } | 1529 | } |
| 1538 | 1530 | ||
| 1539 | chip->tpid = -1; | 1531 | chip->thread = NULL; |
| 1540 | if (desc->checkmode) { | 1532 | if (desc->checkmode) { |
| 1541 | /* start async thread */ | 1533 | /* start async thread */ |
| 1542 | init_timer(&chip->wt); | 1534 | init_timer(&chip->wt); |
| 1543 | chip->wt.function = chip_thread_wake; | 1535 | chip->wt.function = chip_thread_wake; |
| 1544 | chip->wt.data = (unsigned long)chip; | 1536 | chip->wt.data = (unsigned long)chip; |
| 1545 | init_waitqueue_head(&chip->wq); | 1537 | chip->thread = kthread_run(chip_thread, chip, chip->c.name); |
| 1546 | init_completion(&chip->texit); | 1538 | if (IS_ERR(chip->thread)) { |
| 1547 | chip->tpid = kernel_thread(chip_thread,(void *)chip,0); | 1539 | v4l_warn(&chip->c, "%s: failed to create kthread\n", |
| 1548 | if (chip->tpid < 0) | ||
| 1549 | v4l_warn(&chip->c, "%s: kernel_thread() failed\n", | ||
| 1550 | chip->c.name); | 1540 | chip->c.name); |
| 1551 | wake_up_interruptible(&chip->wq); | 1541 | chip->thread = NULL; |
| 1542 | } | ||
| 1552 | } | 1543 | } |
| 1553 | return 0; | 1544 | return 0; |
| 1554 | } | 1545 | } |
| @@ -1569,11 +1560,10 @@ static int chip_detach(struct i2c_client *client) | |||
| 1569 | struct CHIPSTATE *chip = i2c_get_clientdata(client); | 1560 | struct CHIPSTATE *chip = i2c_get_clientdata(client); |
| 1570 | 1561 | ||
| 1571 | del_timer_sync(&chip->wt); | 1562 | del_timer_sync(&chip->wt); |
| 1572 | if (chip->tpid >= 0) { | 1563 | if (chip->thread) { |
| 1573 | /* shutdown async thread */ | 1564 | /* shutdown async thread */ |
| 1574 | chip->done = 1; | 1565 | kthread_stop(chip->thread); |
| 1575 | wake_up_interruptible(&chip->wq); | 1566 | chip->thread = NULL; |
| 1576 | wait_for_completion(&chip->texit); | ||
| 1577 | } | 1567 | } |
| 1578 | 1568 | ||
| 1579 | i2c_detach_client(&chip->c); | 1569 | i2c_detach_client(&chip->c); |
