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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# Output serialization functions.
import textwrap
from dist import compare_srcfile
class SerialArg:
def __init__(self, typestr, name, sized=0):
self.typestr = typestr
self.name = name
self.sized = sized
class Serial:
def __init__(self, name, op, args):
self.name = name
self.op = op
self.args = args
msgtypes = [
Serial('col_append', 'WT_WORKQ_FUNC', [
SerialArg('WT_INSERT_HEAD **', 'inshead'),
SerialArg('WT_INSERT ***', 'ins_stack'),
SerialArg('WT_INSERT_HEAD **', 'new_inslist', 1),
SerialArg('WT_INSERT_HEAD *', 'new_inshead', 1),
SerialArg('WT_INSERT *', 'new_ins', 0),
SerialArg('u_int', 'skipdepth'),
]),
Serial('cache_read', 'WT_WORKQ_READ', [
SerialArg('WT_PAGE *', 'parent'),
SerialArg('WT_REF *', 'parent_ref'),
SerialArg('int', 'dsk_verify'),
]),
Serial('evict_file', 'WT_WORKQ_EVICT', [
SerialArg('int', 'close_method'),
]),
Serial('insert', 'WT_WORKQ_FUNC', [
SerialArg('WT_PAGE *', 'page'),
SerialArg('uint32_t', 'write_gen'),
SerialArg('WT_INSERT_HEAD **', 'inshead'),
SerialArg('WT_INSERT ***', 'ins_stack'),
SerialArg('WT_INSERT_HEAD **', 'new_inslist', 1),
SerialArg('WT_INSERT_HEAD *', 'new_inshead', 1),
SerialArg('WT_INSERT *', 'new_ins', 0),
SerialArg('u_int', 'skipdepth'),
]),
Serial('row_key', 'WT_WORKQ_FUNC', [
SerialArg('WT_PAGE *', 'page'),
SerialArg('WT_ROW *', 'row_arg'),
SerialArg('WT_IKEY *', 'ikey'),
]),
Serial('update', 'WT_WORKQ_FUNC', [
SerialArg('WT_PAGE *', 'page'),
SerialArg('uint32_t', 'write_gen'),
SerialArg('WT_UPDATE **', 'srch_upd'),
SerialArg('WT_UPDATE **', 'new_upd', 1),
SerialArg('WT_UPDATE *', 'upd', 0),
]),
]
# decl --
# Return a declaration for the variable.
def decl(l):
o = l.typestr
if o[-1] != '*':
o += ' '
return o + l.name
# decl_p --
# Return a declaration for a reference to the variable, which requires
# another level of indirection.
def decl_p(l):
o = l.typestr
if o[-1] != '*':
o += ' '
return o + '*' + l.name + 'p'
# output --
# Create functions to schedule tasks for the workQ thread.
def output(entry, f):
# structure declaration
f.write('''
typedef struct {
''')
for l in entry.args:
f.write('\t' + decl(l) + ';\n')
if l.sized:
f.write('\tsize_t ' + l.name + '_size;\n')
f.write('\tint ' + l.name + '_taken;\n')
f.write('} __wt_' + entry.name + '_args;\n\n')
# pack function
f.write('static inline int\n__wt_' + entry.name + '_serial(\n')
o = 'WT_SESSION_IMPL *session'
for l in entry.args:
if l.sized:
o += ', ' + decl_p(l) + ', size_t ' + l.name + '_size'
else:
o += ', ' + decl(l)
o += ')'
f.write('\n'.join('\t' + l for l in textwrap.wrap(o, 70)))
f.write('''
{
\t__wt_''' + entry.name + '''_args _args, *args = &_args;
\tint ret;
''')
for l in entry.args:
if l.sized:
f.write('''\tif (''' + l.name + '''p == NULL)
\t\targs->''' + l.name + ''' = NULL;
\telse {
\t\targs->''' + l.name + ''' = *''' + l.name + '''p;
\t\t*''' + l.name + '''p = NULL;
\t\targs->''' + l.name + '''_size = ''' + l.name + '''_size;
\t}
\targs->''' + l.name + '''_taken = 0;
''')
else:
f.write('\targs->' + l.name + ' = ' + l.name + ';\n\n')
f.write('\tret = __wt_session_serialize_func(session,\n')
f.write('\t ' + entry.op +
', __wt_' + entry.name + '_serial_func, args);\n\n')
for l in entry.args:
if l.sized:
f.write('\tif (!args->' + l.name + '_taken)\n')
f.write('\t\t__wt_free(session, args->' + l.name + ');\n')
f.write('\treturn (ret);\n')
f.write('}\n\n')
# unpack function
f.write('static inline void\n__wt_' + entry.name + '_unpack(\n')
o = 'WT_SESSION_IMPL *session'
for l in entry.args:
o += ', ' + decl_p(l)
o +=')'
f.write('\n'.join('\t' + l for l in textwrap.wrap(o, 70)))
f.write('''
{
\t__wt_''' + entry.name + '''_args *args =
\t (__wt_''' + entry.name + '''_args *)session->wq_args;
''')
for l in entry.args:
f.write('\t*' + l.name + 'p = args->' + l.name + ';\n')
f.write('}\n')
# taken functions
for l in entry.args:
if l.sized:
f.write('''
static inline void\n__wt_''' + entry.name + '_' + l.name + '''_taken(WT_SESSION_IMPL *session, WT_PAGE *page)
{
\t__wt_''' + entry.name + '''_args *args =
\t (__wt_''' + entry.name + '''_args *)session->wq_args;
\targs->''' + l.name + '''_taken = 1;
\tWT_ASSERT(session, args->''' + l.name + '''_size != 0);
\t__wt_cache_page_workq_incr(session, page, args->''' + l.name + '''_size);
}
''')
#####################################################################
# Update serial.i.
#####################################################################
tmp_file = '__tmp'
tfile = open(tmp_file, 'w')
tfile.write('/* DO NOT EDIT: automatically built by dist/serial.py. */\n')
for entry in msgtypes:
output(entry, tfile)
tfile.close()
compare_srcfile(tmp_file, '../src/include/serial.i')
|