From: http://blog.csdn.net/sudolee/article/details/6885634
1> work_queue: <linux/workqueue. h> _ 3.0.4
2> description:
The lower part of the interrupt is executed in the context of the kernel thread.
It is the only implementation mechanism that can run in the lower half of the process context, and it can only sleep.
3> Create a push task:
[Html]View plaincopy
- DECLARE_WORK (const char * name, void (* func) (struct work_struct * work ));
- INIT_WORK (struct work_struct * work, void (* func) (struct work_struct * work ));
- Struct work_struct {
- Atomic_long_t data;
- Struct list_head entry;
- Work_func_t func;
- # Ifdef CONFIG_LOCKDEP
- Struct lockdep_map;
- # Endif
- };
- Typedef void (* work_func_t) (struct work_struct * work );
4> work queue processing functions:
[Html]View plaincopy
- /* Apart from being unable to access the user space, it is indeed much more convenient than Soft Interrupt and tasklet.
- * The user space memory is mapped only when the system call falls into the kernel.
- */
- Void * func (struct work_struct * work );
5> Scheduling (submit:
[Html]View plaincopy
- /* Submit the created job to the default worker thread (one for each cpu, event/cpuno .).
- * Sometimes this kind of work queue is also called a shared queue, because many drivers submit jobs that are pushed back to the default worker thread.
- */
- Int schedule_work (struct work_struct * work );
- Int schedule_delayed_work (struct delayed_work * work, unsigned long delay );
- Int schedule_on_each_cpu (work_func_t func );
6> refresh the working queue:
[Html]View plaincopy
- /* In fact, it only waits (sleep) until the work on the default Task Force column is executed.
- * Complete () implementation.
- */
- Void flush_scheduled_work (void );
- /* Wait for the specified job to be executed */
- Bool flush_work (struct work_struct * work );
- Bool flush_delayed_work (struct delayed_work * dwork );
7> cancel work:
[Cpp]View plaincopy
- Bool cancel_delayed_work (struct delayed_work * work );
- Bool cancel_work_sync (struct work_struct * work );
- Bool cancel_delayed_work_sync (struct delayed_work * dwork );
8> Create a New workqueue and corresponding worker thread (one for each cpu ).
[Cpp]View plaincopy
- /* If a task is processor-intensive and has strict performance requirements
- * You can create your own worker (worker) thread.
- * Of course, each processor has one.
- */
- Struct workqueue_struct * create_workqueue (const char * name );
- /* Struct workqueue_struct * alloc_workqueue (const char * name, unsigned int flags, int max_active );
- * The maximum number of execution contexts per cpu, up to 512.
- */
9> Scheduling (submit) queue
[Cpp]View plaincopy
- Int queue_work (struct workqueue_struct * wq, struct work_struct * work );
- Int queue_delayed_work (struct workqueue_struct * wq, struct delayed_work * work, unsigned long delay );
10> refresh a work queue:
[Cpp]View plaincopy
- /* Wait (sleep) until the job in the specified queue is executed.
- * In fact, it is no different from flush_scheduled_work () except for the specified work queue.
- */
- Void flush_workqueue (struct workqueue_struct * wq );
11> release a working queue:
[Cpp]View plaincopy
- Void destroy_workqueue (struct workqueue_struct * wq );