comparison src/parallel_execution/DebugWorker/state_db.c @ 1015:e6778c866876

add DebugWorker and DebugTaskManager
author Takato Matsuoka <t.matsuoka@cr.ie.u-ryukyu.ac.jp>
date Tue, 18 Jan 2022 19:54:28 +0900
parents
children
comparison
equal deleted inserted replaced
1014:a9c630cc1c65 1015:e6778c866876
1 #include <stdlib.h>
2
3 #include "state_db.h"
4 #include "memory.h"
5
6 StateDB
7 create_stateDB()
8 {
9 StateDB s = (StateDB)malloc(sizeof(StateNode));
10 if (!s) die_exit("Cann't alloc state db node.");
11 return s;
12 }
13
14 static MemoryPtr mem_db;
15
16 static int state_count0;
17
18 void
19 reset_state_count()
20 {
21 state_count0 = 0;
22 }
23
24 int
25 state_count()
26 {
27 return state_count0;
28 }
29
30
31 /*
32
33 lookup_StateDB(struct state *s, StateDB *parent, StatePtr *out)
34
35 s->memory points the real memory
36 if s is new, it is copied in the database (parent).
37 if s is in the database, existing state is returned.
38
39 if return value is 0, it returns new state.
40 if out is null, no copy_state is created. (lookup mode)
41
42 Founded state or newly created state is returned in out.
43
44 */
45
46 int
47 lookup_StateDB(StateDB s, StateDB *parent, StateDB *out)
48 {
49 StateDB db;
50 int r;
51
52 while(1) {
53 db = *parent;
54 if (!db) {
55 /* not found */
56 if (out) {
57 db = create_stateDB();
58 db->left = db->right = 0;
59 db->memory = copy_memory(s->memory,&mem_db);
60 db->hash = s->hash;
61 state_count0 ++;
62 *parent = db;
63 *out = db;
64 }
65 return 0;
66 }
67 if (s->hash == db->hash) {
68 r = cmp_memory(s->memory,db->memory);
69 } else
70 r = (s->hash > db->hash)? 1 : -1;
71 if(!r) {
72 /* bingo */
73 if (out) *out = db;
74 return 1;
75 } else if (r>0) {
76 parent = &db->left;
77 } else if (r<0) {
78 parent = &db->right;
79 }
80 }
81 }
82
83 int
84 visit_StateDB(StateDB s, StateDB *parent, StateDB* out, int visit)
85 {
86 int exists = lookup_StateDB(s,parent,out);
87 if (!exists) return 0;
88 if ((*out)->visit >= visit) {
89 return 1;
90 }
91 (*out)->visit = visit;
92 return 0;
93 }
94 /* end */