Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 295087
b: refs/heads/master
c: 847e876
h: refs/heads/master
i:
  295085: 680bd22
  295083: c63a5f7
  295079: 4c0e408
  295071: ac8293a
v: v3
  • Loading branch information
Akihiro Tsukada authored and Mauro Carvalho Chehab committed Mar 19, 2012
1 parent 78a3571 commit 6407d3c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2321acf2962514088c2230b6d54f7a56368576c5
refs/heads/master: 847e87659620890bfc80ce7bf682f2a5354543b2
73 changes: 50 additions & 23 deletions trunk/drivers/media/dvb/pt1/pt1.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ struct pt1 {
struct pt1_adapter *adaps[PT1_NR_ADAPS];
struct pt1_table *tables;
struct task_struct *kthread;
int table_index;
int buf_index;

struct mutex lock;
int power;
Expand Down Expand Up @@ -303,30 +305,25 @@ static int pt1_filter(struct pt1 *pt1, struct pt1_buffer_page *page)
static int pt1_thread(void *data)
{
struct pt1 *pt1;
int table_index;
int buf_index;
struct pt1_buffer_page *page;

pt1 = data;
set_freezable();

table_index = 0;
buf_index = 0;

while (!kthread_should_stop()) {
try_to_freeze();

page = pt1->tables[table_index].bufs[buf_index].page;
page = pt1->tables[pt1->table_index].bufs[pt1->buf_index].page;
if (!pt1_filter(pt1, page)) {
schedule_timeout_interruptible((HZ + 999) / 1000);
continue;
}

if (++buf_index >= PT1_NR_BUFS) {
if (++pt1->buf_index >= PT1_NR_BUFS) {
pt1_increment_table_count(pt1);
buf_index = 0;
if (++table_index >= pt1_nr_tables)
table_index = 0;
pt1->buf_index = 0;
if (++pt1->table_index >= pt1_nr_tables)
pt1->table_index = 0;
}
}

Expand Down Expand Up @@ -477,21 +474,60 @@ static int pt1_init_tables(struct pt1 *pt1)
return ret;
}

static int pt1_start_polling(struct pt1 *pt1)
{
int ret = 0;

mutex_lock(&pt1->lock);
if (!pt1->kthread) {
pt1->kthread = kthread_run(pt1_thread, pt1, "earth-pt1");
if (IS_ERR(pt1->kthread)) {
ret = PTR_ERR(pt1->kthread);
pt1->kthread = NULL;
}
}
mutex_unlock(&pt1->lock);
return ret;
}

static int pt1_start_feed(struct dvb_demux_feed *feed)
{
struct pt1_adapter *adap;
adap = container_of(feed->demux, struct pt1_adapter, demux);
if (!adap->users++)
if (!adap->users++) {
int ret;

ret = pt1_start_polling(adap->pt1);
if (ret)
return ret;
pt1_set_stream(adap->pt1, adap->index, 1);
}
return 0;
}

static void pt1_stop_polling(struct pt1 *pt1)
{
int i, count;

mutex_lock(&pt1->lock);
for (i = 0, count = 0; i < PT1_NR_ADAPS; i++)
count += pt1->adaps[i]->users;

if (count == 0 && pt1->kthread) {
kthread_stop(pt1->kthread);
pt1->kthread = NULL;
}
mutex_unlock(&pt1->lock);
}

static int pt1_stop_feed(struct dvb_demux_feed *feed)
{
struct pt1_adapter *adap;
adap = container_of(feed->demux, struct pt1_adapter, demux);
if (!--adap->users)
if (!--adap->users) {
pt1_set_stream(adap->pt1, adap->index, 0);
pt1_stop_polling(adap->pt1);
}
return 0;
}

Expand Down Expand Up @@ -1020,7 +1056,8 @@ static void __devexit pt1_remove(struct pci_dev *pdev)
pt1 = pci_get_drvdata(pdev);
regs = pt1->regs;

kthread_stop(pt1->kthread);
if (pt1->kthread)
kthread_stop(pt1->kthread);
pt1_cleanup_tables(pt1);
pt1_cleanup_frontends(pt1);
pt1_disable_ram(pt1);
Expand All @@ -1043,7 +1080,6 @@ pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
void __iomem *regs;
struct pt1 *pt1;
struct i2c_adapter *i2c_adap;
struct task_struct *kthread;

ret = pci_enable_device(pdev);
if (ret < 0)
Expand Down Expand Up @@ -1139,17 +1175,8 @@ pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
if (ret < 0)
goto err_pt1_cleanup_frontends;

kthread = kthread_run(pt1_thread, pt1, "pt1");
if (IS_ERR(kthread)) {
ret = PTR_ERR(kthread);
goto err_pt1_cleanup_tables;
}

pt1->kthread = kthread;
return 0;

err_pt1_cleanup_tables:
pt1_cleanup_tables(pt1);
err_pt1_cleanup_frontends:
pt1_cleanup_frontends(pt1);
err_pt1_disable_ram:
Expand Down

0 comments on commit 6407d3c

Please sign in to comment.