summaryrefslogtreecommitdiff
path: root/sys/kern/kern_work.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-11 04:45:50 -0400
committerIan Moffett <ian@osmora.org>2025-08-11 04:47:02 -0400
commitfe74ae7b9b1f7c4ca203deabab4cdd17ff44d12d (patch)
treebf4cdaeacd46a879732e6aa280ec37d198e77fd8 /sys/kern/kern_work.c
parent0e16a67599051063cf78b9849a35ecd37e239095 (diff)
kernel: workqueue: Fixup passing of 'func' in wq
This commit includes several changes: - Improves documentation in sys/workqueue.h - Removes useless 'func' field in workqueue structure - Duplicate strings and introduce work_destroy() Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern/kern_work.c')
-rw-r--r--sys/kern/kern_work.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/sys/kern/kern_work.c b/sys/kern/kern_work.c
index f0eb68c..918af89 100644
--- a/sys/kern/kern_work.c
+++ b/sys/kern/kern_work.c
@@ -107,7 +107,6 @@ workqueue_worker(void)
* to hold queued up tasks.
*
* @name: Name to give the workqueue
- * @func: Function for work thread of this queue
* @max_work: Maximum number of jobs to be added
* @ipl: IPL that the work must operate in
*
@@ -115,7 +114,7 @@ workqueue_worker(void)
* otherwise a value of NULL is returned.
*/
struct workqueue *
-workqueue_new(const char *name, workfunc_t func, size_t max_work, int ipl)
+workqueue_new(const char *name, size_t max_work, int ipl)
{
struct workqueue *wqp;
struct proc *td;
@@ -138,7 +137,6 @@ workqueue_new(const char *name, workfunc_t func, size_t max_work, int ipl)
wqp->nwork = 0;
wqp->cookie = WQ_COOKIE;
wqp->lock = mutex_new(wqp->name);
- wqp->func = func;
/*
* We need to spawn the work thread which
@@ -162,23 +160,29 @@ workqueue_new(const char *name, workfunc_t func, size_t max_work, int ipl)
* workqueue.
*
* @wqp: Pointer to specific workqueue
+ * @name: Name to set for work unit
* @wp: Pointer to work that should be enqueued
*
* Returns zero on success, otherwise a less than
* zero value is returned.
*/
int
-workqueue_enq(struct workqueue *wqp, struct work *wp)
+workqueue_enq(struct workqueue *wqp, const char *name, struct work *wp)
{
if (wqp == NULL || wp == NULL) {
return -EINVAL;
}
+ if (name == NULL) {
+ return -EINVAL;
+ }
+
/* Verify that we have a valid workqueue */
if (__unlikely(wqp->cookie != WQ_COOKIE)) {
panic("workq: bad cookie on work enqueue\n");
}
+ wp->name = strdup(name);
mutex_acquire(wqp->lock, 0);
/*
@@ -249,3 +253,22 @@ workqueue_destroy(struct workqueue *wqp)
memset(wqp, 0, sizeof(*wqp));
return 0;
}
+
+/*
+ * Cleanup after work
+ *
+ * @wp: Work to clean up
+ */
+int
+work_destroy(struct work *wp)
+{
+ if (wp == NULL) {
+ return -EINVAL;
+ }
+
+ if (wp->name != NULL) {
+ dynfree(wp->name);
+ }
+
+ return 0;
+}