提交 9320874a 编写于 作者: C Christoph Hellwig 提交者: Mauro Carvalho Chehab

V4L/DVB (6279): en_50221: convert to kthread API

Here's an attempted update to the full kthread API + wake_up_process:
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
CC: Andrew de Quincey <adq_dvb@lidskialf.net>
Signed-off-by: NMauro Carvalho Chehab <mchehab@infradead.org>
上级 d00cd298
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/kthread.h>
#include "dvb_ca_en50221.h" #include "dvb_ca_en50221.h"
#include "dvb_ringbuffer.h" #include "dvb_ringbuffer.h"
...@@ -139,13 +140,7 @@ struct dvb_ca_private { ...@@ -139,13 +140,7 @@ struct dvb_ca_private {
wait_queue_head_t wait_queue; wait_queue_head_t wait_queue;
/* PID of the monitoring thread */ /* PID of the monitoring thread */
pid_t thread_pid; struct task_struct *thread;
/* Wait queue used when shutting thread down */
wait_queue_head_t thread_queue;
/* Flag indicating when thread should exit */
unsigned int exit:1;
/* Flag indicating if the CA device is open */ /* Flag indicating if the CA device is open */
unsigned int open:1; unsigned int open:1;
...@@ -901,27 +896,9 @@ static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca) ...@@ -901,27 +896,9 @@ static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca)
ca->wakeup = 1; ca->wakeup = 1;
mb(); mb();
wake_up_interruptible(&ca->thread_queue); wake_up_process(ca->thread);
} }
/**
* Used by the CA thread to determine if an early wakeup is necessary
*
* @param ca CA instance.
*/
static int dvb_ca_en50221_thread_should_wakeup(struct dvb_ca_private *ca)
{
if (ca->wakeup) {
ca->wakeup = 0;
return 1;
}
if (ca->exit)
return 1;
return 0;
}
/** /**
* Update the delay used by the thread. * Update the delay used by the thread.
* *
...@@ -981,7 +958,6 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca) ...@@ -981,7 +958,6 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca)
static int dvb_ca_en50221_thread(void *data) static int dvb_ca_en50221_thread(void *data)
{ {
struct dvb_ca_private *ca = data; struct dvb_ca_private *ca = data;
char name[15];
int slot; int slot;
int flags; int flags;
int status; int status;
...@@ -990,28 +966,17 @@ static int dvb_ca_en50221_thread(void *data) ...@@ -990,28 +966,17 @@ static int dvb_ca_en50221_thread(void *data)
dprintk("%s\n", __FUNCTION__); dprintk("%s\n", __FUNCTION__);
/* setup kernel thread */
snprintf(name, sizeof(name), "kdvb-ca-%i:%i", ca->dvbdev->adapter->num, ca->dvbdev->id);
lock_kernel();
daemonize(name);
sigfillset(&current->blocked);
unlock_kernel();
/* choose the correct initial delay */ /* choose the correct initial delay */
dvb_ca_en50221_thread_update_delay(ca); dvb_ca_en50221_thread_update_delay(ca);
/* main loop */ /* main loop */
while (!ca->exit) { while (!kthread_should_stop()) {
/* sleep for a bit */ /* sleep for a bit */
if (!ca->wakeup) { while (!ca->wakeup) {
flags = wait_event_interruptible_timeout(ca->thread_queue, set_current_state(TASK_INTERRUPTIBLE);
dvb_ca_en50221_thread_should_wakeup(ca), schedule_timeout(ca->delay);
ca->delay); if (kthread_should_stop())
if ((flags == -ERESTARTSYS) || ca->exit) { return 0;
/* got signal or quitting */
break;
}
} }
ca->wakeup = 0; ca->wakeup = 0;
...@@ -1180,10 +1145,6 @@ static int dvb_ca_en50221_thread(void *data) ...@@ -1180,10 +1145,6 @@ static int dvb_ca_en50221_thread(void *data)
} }
} }
/* completed */
ca->thread_pid = 0;
mb();
wake_up_interruptible(&ca->thread_queue);
return 0; return 0;
} }
...@@ -1683,9 +1644,6 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, ...@@ -1683,9 +1644,6 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
goto error; goto error;
} }
init_waitqueue_head(&ca->wait_queue); init_waitqueue_head(&ca->wait_queue);
ca->thread_pid = 0;
init_waitqueue_head(&ca->thread_queue);
ca->exit = 0;
ca->open = 0; ca->open = 0;
ca->wakeup = 0; ca->wakeup = 0;
ca->next_read_slot = 0; ca->next_read_slot = 0;
...@@ -1711,14 +1669,14 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, ...@@ -1711,14 +1669,14 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
mb(); mb();
/* create a kthread for monitoring this CA device */ /* create a kthread for monitoring this CA device */
ca->thread = kthread_run(dvb_ca_en50221_thread, ca, "kdvb-ca-%i:%i",
ret = kernel_thread(dvb_ca_en50221_thread, ca, 0); ca->dvbdev->adapter->num, ca->dvbdev->id);
if (IS_ERR(ca->thread)) {
if (ret < 0) { ret = PTR_ERR(ca->thread);
printk("dvb_ca_init: failed to start kernel_thread (%d)\n", ret); printk("dvb_ca_init: failed to start kernel_thread (%d)\n",
ret);
goto error; goto error;
} }
ca->thread_pid = ret;
return 0; return 0;
error: error:
...@@ -1749,17 +1707,7 @@ void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca) ...@@ -1749,17 +1707,7 @@ void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca)
dprintk("%s\n", __FUNCTION__); dprintk("%s\n", __FUNCTION__);
/* shutdown the thread if there was one */ /* shutdown the thread if there was one */
if (ca->thread_pid) { kthread_stop(ca->thread);
if (kill_proc(ca->thread_pid, 0, 1) == -ESRCH) {
printk("dvb_ca_release adapter %d: thread PID %d already died\n",
ca->dvbdev->adapter->num, ca->thread_pid);
} else {
ca->exit = 1;
mb();
dvb_ca_en50221_thread_wakeup(ca);
wait_event_interruptible(ca->thread_queue, ca->thread_pid == 0);
}
}
for (i = 0; i < ca->slot_count; i++) { for (i = 0; i < ca->slot_count; i++) {
dvb_ca_en50221_slot_shutdown(ca, i); dvb_ca_en50221_slot_shutdown(ca, i);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册