Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 208156
b: refs/heads/master
c: 0d2cb1d
h: refs/heads/master
v: v3
  • Loading branch information
Maxim Levitsky authored and Mauro Carvalho Chehab committed Aug 9, 2010
1 parent 6057cc8 commit 22377fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 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: 45a568fa6f6bf8e5b9c32e52292f297e8473a985
refs/heads/master: 0d2cb1de8e81ffc06df67853be5ead3556d3a6b5
2 changes: 1 addition & 1 deletion trunk/drivers/media/IR/ir-core-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ir_raw_handler {

struct ir_raw_event_ctrl {
struct list_head list; /* to keep track of raw clients */
struct work_struct rx_work; /* for the rx decoding workqueue */
struct task_struct *thread;
struct kfifo kfifo; /* fifo for the pulse/space durations */
ktime_t last_event; /* when last event occurred */
enum raw_event_type last_type; /* last event type */
Expand Down
42 changes: 31 additions & 11 deletions trunk/drivers/media/IR/ir-raw-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
* GNU General Public License for more details.
*/

#include <linux/workqueue.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/freezer.h>
#include "ir-core-priv.h"

/* Define the max number of pulse/space transitions to buffer */
Expand All @@ -33,20 +34,30 @@ static u64 available_protocols;
static struct work_struct wq_load;
#endif

static void ir_raw_event_work(struct work_struct *work)
static int ir_raw_event_thread(void *data)
{
struct ir_raw_event ev;
struct ir_raw_handler *handler;
struct ir_raw_event_ctrl *raw =
container_of(work, struct ir_raw_event_ctrl, rx_work);
struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;

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

while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
mutex_lock(&ir_raw_handler_lock);
list_for_each_entry(handler, &ir_raw_handler_list, list)
handler->decode(raw->input_dev, ev);

while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
list_for_each_entry(handler, &ir_raw_handler_list, list)
handler->decode(raw->input_dev, ev);
raw->prev_ev = ev;
}

mutex_unlock(&ir_raw_handler_lock);
raw->prev_ev = ev;

set_current_state(TASK_INTERRUPTIBLE);
schedule();
}

return 0;
}

/**
Expand Down Expand Up @@ -141,7 +152,7 @@ void ir_raw_event_handle(struct input_dev *input_dev)
if (!ir->raw)
return;

schedule_work(&ir->raw->rx_work);
wake_up_process(ir->raw->thread);
}
EXPORT_SYMBOL_GPL(ir_raw_event_handle);

Expand Down Expand Up @@ -170,7 +181,7 @@ int ir_raw_event_register(struct input_dev *input_dev)
return -ENOMEM;

ir->raw->input_dev = input_dev;
INIT_WORK(&ir->raw->rx_work, ir_raw_event_work);

ir->raw->enabled_protocols = ~0;
rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE,
GFP_KERNEL);
Expand All @@ -180,6 +191,15 @@ int ir_raw_event_register(struct input_dev *input_dev)
return rc;
}

ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw,
"rc%u", (unsigned int)ir->devno);

if (IS_ERR(ir->raw->thread)) {
kfree(ir->raw);
ir->raw = NULL;
return PTR_ERR(ir->raw->thread);
}

mutex_lock(&ir_raw_handler_lock);
list_add_tail(&ir->raw->list, &ir_raw_client_list);
list_for_each_entry(handler, &ir_raw_handler_list, list)
Expand All @@ -198,7 +218,7 @@ void ir_raw_event_unregister(struct input_dev *input_dev)
if (!ir->raw)
return;

cancel_work_sync(&ir->raw->rx_work);
kthread_stop(ir->raw->thread);

mutex_lock(&ir_raw_handler_lock);
list_del(&ir->raw->list);
Expand Down

0 comments on commit 22377fd

Please sign in to comment.