cgen: create enclosing block on C side for V `lock` blocks (#8538)

pull/8540/head^2
Uwe Krüger 2021-02-03 23:25:01 +01:00 committed by GitHub
parent 2424e2cb02
commit cee00a3551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -3448,7 +3448,9 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) {
g.writeln('\t\tsync__RwMutex_lock((sync__RwMutex*)_arr_$mtxs[$mtxs]);')
g.writeln('}')
}
g.writeln('/*lock*/ {')
g.stmts(node.stmts)
g.writeln('}')
if node.lockeds.len == 0 {
// this should not happen
} else if node.lockeds.len == 1 {
@ -3465,7 +3467,7 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) {
g.writeln('\t\tsync__RwMutex_runlock((sync__RwMutex*)_arr_$mtxs[$mtxs]);')
g.writeln('\telse')
g.writeln('\t\tsync__RwMutex_unlock((sync__RwMutex*)_arr_$mtxs[$mtxs]);')
g.writeln('}')
g.write('}')
}
}

View File

@ -48,12 +48,12 @@ fn test_shared_as_value() {
assert v == 35
}
rlock m {
w := m_val(m)
assert w == -3.125
u := m_val(m)
assert u == -3.125
}
lock a {
x := a_val(a)
assert x == 4
u := a_val(a)
assert u == 4
}
}