TASK_INITIALIZER()

John Baldwin jhb at FreeBSD.org
Mon Dec 19 17:09:18 UTC 2011


On 12/17/11 6:08 AM, Gary Jennejohn wrote:
> On Fri, 16 Dec 2011 15:59:36 -0500
> John Baldwin<jhb at freebsd.org>  wrote:
>
>> Any objection to adding a macro to make it easy to statically initialize task
>> structures (similar to the initializer macros in<sys/queue.h>)?  This allows
>> global tasks to be statically initalized without requiring a dedicated
>> SYSINIT() routine.
>>
>> Index: share/man/man9/Makefile
>> ===================================================================
>> --- share/man/man9/Makefile     (revision 228534)
>> +++ share/man/man9/Makefile     (working copy)
>> @@ -1250,6 +1250,7 @@
>>          sysctl_ctx_init.9 sysctl_ctx_free.9
>>   MLINKS+=SYSINIT.9 SYSUNINIT.9
>>   MLINKS+=taskqueue.9 TASK_INIT.9 \
>> +       taskqueue.9 TASK_INITIALIZER.9 \
>>          taskqueue.9 taskqueue_cancel.9 \
>>          taskqueue.9 taskqueue_create.9 \
>>          taskqueue.9 taskqueue_create_fast.9 \
>> Index: share/man/man9/taskqueue.9
>> ===================================================================
>> --- share/man/man9/taskqueue.9  (revision 228534)
>> +++ share/man/man9/taskqueue.9  (working copy)
>> @@ -80,6 +80,7 @@
>>   .Ft void
>>   .Fn taskqueue_run "struct taskqueue *queue"
>>   .Fn TASK_INIT "struct task *task" "int priority" "task_fn_t func" "void
>> *context"
>> +.Fn TASK_INITIALIZER "int priority" "task_fn_t func" "void *context"
>>   .Fn TASKQUEUE_DECLARE "name"
>>   .Fn TASKQUEUE_DEFINE "name" "taskqueue_enqueue_fn enqueue" "void *context"
>> "init"
>>   .Fn TASKQUEUE_FAST_DEFINE "name" "taskqueue_enqueue_fn enqueue" "void
>> *context" "init"
>> @@ -243,9 +244,14 @@
>>   is provided to initialise a
>>   .Va task
>>   structure.
>> +The
>> +.Fn TASK_INITIALIZER
>> +macro generates an initializer for a task structure.
>>   A macro
>>   .Fn TIMEOUT_TASK_INIT "queue" "timeout_task" "priority" "func" "context"
>> -initializes the timeout_task structure.
>> +initializes the
>> +.Va timeout_task
>> +structure.
>>   The values of
>>   .Va priority ,
>>   .Va func ,
>> Index: sys/sys/taskqueue.h
>> ===================================================================
>> --- sys/sys/taskqueue.h (revision 228534)
>> +++ sys/sys/taskqueue.h (working copy)
>> @@ -77,6 +77,12 @@
>>   void   taskqueue_unblock(struct taskqueue *queue);
>>   int    taskqueue_member(struct taskqueue *queue, struct thread *td);
>>
>> +#define TASK_INITIALIZER(priority, func, context)      \
>> +       { .ta_pending = 0,                              \
>> +         .ta_priority = (priority),                    \
>> +         .ta_func = (func),                            \
>> +         .ta_context = (context) }
>> +
>>   /*
>>    * Functions for dedicated thread taskqueues
>>    */
>>
>
> Seems like an excellent idea.  Are you also planning to replace the
> existing SYSINIT() entries?

I had not planned on doing so, no.  I can maybe look at that however.

-- 
John Baldwin


More information about the freebsd-arch mailing list