summaryrefslogtreecommitdiffstats
path: root/common/workqueue.c
blob: dc6941dec122cc976fda8ec868157d26eda91136 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-2.0-only
#include <common.h>
#include <work.h>

static void wq_do_pending_work(struct work_queue *wq)
{
	struct work_struct *work, *tmp;

	list_for_each_entry_safe(work, tmp, &wq->work, list) {
		if (work->delayed && get_time_ns() < work->timeout)
			continue;

		list_del(&work->list);
		wq->fn(work);
	}
}

void wq_cancel_work(struct work_queue *wq)
{
	struct work_struct *work, *tmp;

	list_for_each_entry_safe(work, tmp, &wq->work, list) {
		list_del(&work->list);
		wq->cancel(work);
	}
}

static LIST_HEAD(work_queues);

/**
 * wq_do_all_works - do all pending work
 *
 * This calls all pending work functions
 */
void wq_do_all_works(void)
{
	struct work_queue *wq;

	list_for_each_entry(wq, &work_queues, list)
		wq_do_pending_work(wq);
}

/**
 * wq_register - register a new work queue
 * @wq:    The work queue
 */
void wq_register(struct work_queue *wq)
{
	INIT_LIST_HEAD(&wq->work);
	list_add_tail(&wq->list, &work_queues);
}

/**
 * wq_unregister - unregister a work queue
 * @wq:    The work queue
 */
void wq_unregister(struct work_queue *wq)
{
	wq_cancel_work(wq);
	list_del(&wq->list);
}