Skip to content

Commit 020f6fd

Browse files
authored
FreeBSD: Implement taskq_init_ent()
Previously taskq_init_ent() was an empty macro, while actual init was done by taskq_dispatch_ent(). It could be slightly faster in case taskq never enqueued. But without it taskq_empty_ent() relied on the structure being zeroed by somebody else, that is not good. As a side effect this allows the same task to be queued several times, that is normal on FreeBSD, that may or may not get useful here also one day. Reviewed-by: Brian Atkinson <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Closes #15455
1 parent 58398cb commit 020f6fd

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

include/os/freebsd/spl/sys/taskq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ typedef struct taskq_ent {
8282

8383
#define TASKQID_INVALID ((taskqid_t)0)
8484

85-
#define taskq_init_ent(x)
8685
extern taskq_t *system_taskq;
8786
/* Global dynamic task queue for long delay */
8887
extern taskq_t *system_delay_taskq;
@@ -93,6 +92,7 @@ extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *,
9392
extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
9493
taskq_ent_t *);
9594
extern int taskq_empty_ent(taskq_ent_t *);
95+
extern void taskq_init_ent(taskq_ent_t *);
9696
taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
9797
taskq_t *taskq_create_synced(const char *, int, pri_t, int, int, uint_t,
9898
kthread_t ***);

module/os/freebsd/spl/spl_taskq.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,21 +480,33 @@ void
480480
taskq_dispatch_ent(taskq_t *tq, task_func_t func, void *arg, uint32_t flags,
481481
taskq_ent_t *task)
482482
{
483-
int prio;
484-
485483
/*
486484
* If TQ_FRONT is given, we want higher priority for this task, so it
487485
* can go at the front of the queue.
488486
*/
489-
prio = !!(flags & TQ_FRONT);
490-
task->tqent_id = 0;
487+
task->tqent_task.ta_priority = !!(flags & TQ_FRONT);
491488
task->tqent_func = func;
492489
task->tqent_arg = arg;
493-
494-
TASK_INIT(&task->tqent_task, prio, taskq_run_ent, task);
495490
taskqueue_enqueue(tq->tq_queue, &task->tqent_task);
496491
}
497492

493+
void
494+
taskq_init_ent(taskq_ent_t *task)
495+
{
496+
TASK_INIT(&task->tqent_task, 0, taskq_run_ent, task);
497+
task->tqent_func = NULL;
498+
task->tqent_arg = NULL;
499+
task->tqent_id = 0;
500+
task->tqent_type = NORMAL_TASK;
501+
task->tqent_rc = 0;
502+
}
503+
504+
int
505+
taskq_empty_ent(taskq_ent_t *task)
506+
{
507+
return (task->tqent_task.ta_pending == 0);
508+
}
509+
498510
void
499511
taskq_wait(taskq_t *tq)
500512
{
@@ -521,9 +533,3 @@ taskq_wait_outstanding(taskq_t *tq, taskqid_t id __unused)
521533
{
522534
taskqueue_drain_all(tq->tq_queue);
523535
}
524-
525-
int
526-
taskq_empty_ent(taskq_ent_t *t)
527-
{
528-
return (t->tqent_task.ta_pending == 0);
529-
}

0 commit comments

Comments
 (0)