The function create_singlethread_workqueue()
will create a work queue. A work queue is just a queue to which you submit work. "work" here means any function that you would want to run at a given point in time. This work will be executed by a single worker thread which is also created when you call create_singlethread_workqueue()
.
struct workqueue_struct *create_singlethread_workqueue(const char *name);
Secondly, INIT_WORK
is a mechanism to initialize the work struct at run time. There is a way to do the initialization at compile time too.
INIT_WORK(struct work_struct *work, void (*function)(void *), void *data);
This means whenever we queue the work_struct *work
on to a workqueue
, the function pointed to by (*function)
will be called with argument void *data
. Let's see how we queue work:
int queue_work(struct workqueue_struct *queue, struct work_struct *work);
So here we have queued/submitted the work to a workqueue *queue
. This will ultimately execute function pointed to by (*function)
with argument void *data
specified in the INIT_WORK()
Note: OLD API.