2013-04-26 13:01:23 +02:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <ddk.h>
|
|
|
|
|
2013-07-05 09:41:18 +02:00
|
|
|
extern int driver_wq_state;
|
|
|
|
|
2013-04-26 13:01:23 +02:00
|
|
|
struct workqueue_struct *alloc_workqueue(const char *fmt,
|
|
|
|
unsigned int flags,
|
|
|
|
int max_active)
|
|
|
|
{
|
|
|
|
struct workqueue_struct *wq;
|
|
|
|
|
|
|
|
wq = kzalloc(sizeof(*wq),0);
|
|
|
|
if (!wq)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&wq->worklist);
|
|
|
|
INIT_LIST_HEAD(&wq->delayed_worklist);
|
|
|
|
|
|
|
|
return wq;
|
|
|
|
err:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void run_workqueue(struct workqueue_struct *cwq)
|
|
|
|
{
|
|
|
|
unsigned long irqflags;
|
|
|
|
|
|
|
|
// dbgprintf("wq: %x head %x, next %x\n",
|
|
|
|
// cwq, &cwq->worklist, cwq->worklist.next);
|
|
|
|
|
2013-07-05 09:41:18 +02:00
|
|
|
while(driver_wq_state != 0)
|
2013-04-26 13:01:23 +02:00
|
|
|
{
|
|
|
|
spin_lock_irqsave(&cwq->lock, irqflags);
|
|
|
|
|
2013-07-05 09:41:18 +02:00
|
|
|
while (!list_empty(&cwq->worklist))
|
|
|
|
{
|
|
|
|
struct work_struct *work = list_entry(cwq->worklist.next,
|
|
|
|
struct work_struct, entry);
|
|
|
|
work_func_t f = work->func;
|
|
|
|
list_del_init(cwq->worklist.next);
|
|
|
|
// printf("work %p, func %p\n",
|
|
|
|
// work, f);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cwq->lock, irqflags);
|
|
|
|
f(work);
|
|
|
|
spin_lock_irqsave(&cwq->lock, irqflags);
|
|
|
|
}
|
2013-04-26 13:01:23 +02:00
|
|
|
|
2013-07-05 09:41:18 +02:00
|
|
|
spin_unlock_irqrestore(&cwq->lock, irqflags);
|
2013-04-26 13:01:23 +02:00
|
|
|
|
2013-07-05 09:41:18 +02:00
|
|
|
delay(1);
|
|
|
|
};
|
2013-04-26 13:01:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool queue_work(struct workqueue_struct *wq, struct work_struct *work)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if(!list_empty(&work->entry))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// dbgprintf("%s %p queue: %p\n", __FUNCTION__, work, wq);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&wq->lock, flags);
|
|
|
|
|
|
|
|
list_add_tail(&work->entry, &wq->worklist);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&wq->lock, flags);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void __stdcall delayed_work_timer_fn(unsigned long __data)
|
|
|
|
{
|
|
|
|
struct delayed_work *dwork = (struct delayed_work *)__data;
|
|
|
|
struct workqueue_struct *wq = dwork->work.data;
|
|
|
|
|
|
|
|
queue_work(wq, &dwork->work);
|
|
|
|
}
|
|
|
|
|
|
|
|
int queue_delayed_work(struct workqueue_struct *wq,
|
|
|
|
struct delayed_work *dwork, unsigned long delay)
|
|
|
|
{
|
|
|
|
struct work_struct *work = &dwork->work;
|
|
|
|
|
|
|
|
if (delay == 0)
|
|
|
|
return queue_work(wq, &dwork->work);
|
|
|
|
|
|
|
|
// dbgprintf("%s %p queue: %p\n", __FUNCTION__, &dwork->work, wq);
|
|
|
|
|
|
|
|
work->data = wq;
|
2013-10-29 08:49:21 +01:00
|
|
|
TimerHS(delay,0, delayed_work_timer_fn, dwork);
|
2013-04-26 13:01:23 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool schedule_delayed_work(struct delayed_work *dwork, unsigned long delay)
|
|
|
|
{
|
|
|
|
return queue_delayed_work(system_wq, dwork, delay);
|
|
|
|
}
|
|
|
|
|
2013-10-29 08:49:21 +01:00
|
|
|
int mod_timer(struct timer_list *timer, unsigned long expires)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
expires - GetTimerTicks();
|
|
|
|
|
|
|
|
if(timer->handle)
|
|
|
|
{
|
|
|
|
CancelTimerHS(timer->handle);
|
|
|
|
timer->handle = 0;
|
|
|
|
ret = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
timer->handle = TimerHS(expires, 0, timer->function, timer->data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|