summaryrefslogtreecommitdiff
path: root/hw/vigs/work_queue.h
blob: 0a7592ba30b0252ace1fbffe5c5eb3405268b9b8 (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
#ifndef _QEMU_WORK_QUEUE_H
#define _QEMU_WORK_QUEUE_H

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/queue.h"
#include "qemu/thread.h"
#include "qapi/error.h"

struct work_queue_item;

typedef void (*work_queue_func)(struct work_queue_item */*wq_item*/);

struct work_queue_item
{
    QTAILQ_ENTRY(work_queue_item) entry;

    work_queue_func func;
};

struct work_queue
{
    QemuThread thread;
    QemuMutex mutex;
    QemuCond add_cond;
    QemuCond wait_cond;

    QTAILQ_HEAD(, work_queue_item) items;

    int num_items;

    bool destroying;
};

void work_queue_item_init(struct work_queue_item *wq_item,
                          work_queue_func func);

struct work_queue *work_queue_create(const char *name);

void work_queue_add_item(struct work_queue *wq,
                         struct work_queue_item *wq_item);

void work_queue_wait(struct work_queue *wq);

void work_queue_destroy(struct work_queue *wq);

#define TYPE_WORKQUEUEOBJECT "work_queue"

typedef struct {
    Object base;
    struct work_queue *wq;
} WorkQueueObject;

#define WORKQUEUEOBJECT(obj) \
   OBJECT_CHECK(WorkQueueObject, obj, TYPE_WORKQUEUEOBJECT)

WorkQueueObject *workqueueobject_create(bool *ambiguous);

WorkQueueObject *workqueueobject_find(const char *id);

#endif