-
Notifications
You must be signed in to change notification settings - Fork 0
/
pat-thr.c
80 lines (62 loc) · 1.14 KB
/
pat-thr.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
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <util.h>
#include <pat.ih>
int
thr_alloc(struct thread *thr[static 2])
{
struct thread *ret;
ret = calloc(1, sizeof *ret);
if (!ret) return ENOMEM;
thr[0] = ret;
thr[1] = ret;
return 0;
}
int
thr_cmp(struct thread *lt, struct thread *rt)
{
size_t i;
size_t min;
ptrdiff_t cmp;
if (!lt && !rt) return 0;
if (!lt) return -1;
if (!rt) return 1;
min = umin(lt->nmat, rt->nmat);
for (i = 0; i < min; ++i) {
cmp = ucmp(lt->mat[i].off, rt->mat[i].off);
if (cmp) return -cmp;
cmp = ucmp(lt->mat[i].ext, rt->mat[i].ext);
if (cmp) return cmp;
}
return 0;
}
int
thr_init(struct thread *th, struct ins *prog)
{
th->ip = prog;
th->nmat = 0;
return 0;
}
void
thr_fork(struct thread *dst, struct thread *src)
{
dst->ip = src->ip;
dst->nmat = src->nmat;
memcpy(dst->mat, src->mat, sizeof dst->mat);
}
void
thr_free(struct thread *th)
{
struct thread *a;
while (th) a = th, th = a->next, free(a);
}
void
thr_mv(struct thread *dst[static 2], struct thread **src)
{
struct thread *tmp;
tmp = src[0];
src[0] = src[0]->next;
tmp->next = dst[0];
dst[0] = tmp;
}