-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwait_queue.c
67 lines (56 loc) · 1.04 KB
/
wait_queue.c
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
62
63
64
65
66
67
#include <wait_queue.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <mem.h>
int wait_queue_deinit(wq_handle *handle)
{
if (!handle || !*handle)
return -EINVAL;
kfree((void *)*handle);
*handle = 0;
return 0;
}
int wait_queue_init(wq_handle *handle)
{
if (!handle)
return -EINVAL;
wq_t *w = (wq_t *) kmalloc(sizeof(wq_t));
if (!w)
return -ENOMEM;
w->obj_cnt = 0;
INIT_LIST_HEAD(&w->list);
*handle = (wq_handle) w;
return 0;
}
int wait_queue_insert(wq_handle handle, list_head_t *node)
{
if (!handle || !node)
return -EINVAL;
wq_t *w = (wq_t *) handle;
list_add_tail(node, &w->list);
w->obj_cnt++;
return 0;
}
list_head_t *wait_queue_remove(wq_handle handle)
{
list_head_t *node;
if (!handle)
return NULL;
wq_t *w = (wq_t *) handle;
if (list_empty(&w->list))
return NULL;
w->obj_cnt--;
list_for_each(node, &w->list) {
list_del(node);
return node;
}
return NULL;
}
int wait_queue_objects(wq_handle handle)
{
if (!handle)
return -EINVAL;
wq_t *w = (wq_t *) handle;
return w->obj_cnt;
}