v2: fix support for 'go fn()' in modules. sync.pool is again multithreaded.

pull/4220/head
Delyan Angelov 2020-04-03 19:44:49 +03:00
parent c32ed8af51
commit b411d29577
2 changed files with 17 additions and 14 deletions

View File

@ -116,9 +116,7 @@ pub fn (pool mut PoolProcessor) work_on_pointers(items []voidptr) {
pool.thread_contexts << [voidptr(0)].repeat(pool.items.len) pool.thread_contexts << [voidptr(0)].repeat(pool.items.len)
pool.waitgroup.add(njobs) pool.waitgroup.add(njobs)
for i := 0; i < njobs; i++ { for i := 0; i < njobs; i++ {
// TODO: uncomment when `go func()` works again with v2 go process_in_thread(pool,i)
// go process_in_thread(pool,i)
process_in_thread(pool,i)
} }
pool.waitgroup.wait() pool.waitgroup.wait()
} }

View File

@ -25,6 +25,7 @@ struct Gen {
typedefs strings.Builder typedefs strings.Builder
definitions strings.Builder // typedefs, defines etc (everything that goes to the top of the file) definitions strings.Builder // typedefs, defines etc (everything that goes to the top of the file)
inits strings.Builder // contents of `void _vinit(){}` inits strings.Builder // contents of `void _vinit(){}`
gowrappers strings.Builder // all go callsite wrappers
table &table.Table table &table.Table
pref &pref.Preferences pref &pref.Preferences
mut: mut:
@ -63,6 +64,7 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
out: strings.new_builder(100) out: strings.new_builder(100)
typedefs: strings.new_builder(100) typedefs: strings.new_builder(100)
definitions: strings.new_builder(100) definitions: strings.new_builder(100)
gowrappers: strings.new_builder(100)
inits: strings.new_builder(100) inits: strings.new_builder(100)
table: table table: table
pref: pref pref: pref
@ -100,7 +102,7 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
if g.is_test { if g.is_test {
g.write_tests_main() g.write_tests_main()
} }
return g.hashes() + g.typedefs.str() + g.definitions.str() + g.out.str() return g.hashes() + g.typedefs.str() + g.definitions.str() + g.gowrappers.str() + g.out.str()
} }
pub fn (g &Gen) hashes() string { pub fn (g &Gen) hashes() string {
@ -2839,22 +2841,26 @@ fn (g mut Gen) go_stmt(node ast.GoStmt) {
g.definitions.writeln('\t$styp arg${i+1};') g.definitions.writeln('\t$styp arg${i+1};')
} }
g.definitions.writeln('} $wrapper_struct_name;') g.definitions.writeln('} $wrapper_struct_name;')
g.definitions.writeln('void* ${wrapper_fn_name}($wrapper_struct_name *arg) {') g.definitions.writeln('void* ${wrapper_fn_name}($wrapper_struct_name *arg);')
g.definitions.write(name + '(')
g.gowrappers.writeln('void* ${wrapper_fn_name}($wrapper_struct_name *arg) {')
g.gowrappers.write('\t${name}(')
if it.is_method { if it.is_method {
g.definitions.write('arg->arg0') g.gowrappers.write('arg->arg0')
if it.args.len > 0 { if it.args.len > 0 {
g.definitions.write(', ') g.gowrappers.write(', ')
} }
} }
for i in 0..it.args.len { for i in 0..it.args.len {
g.definitions.write('arg->arg${i+1}') g.gowrappers.write('arg->arg${i+1}')
if i < it.args.len - 1 { if i < it.args.len - 1 {
g.definitions.write(', ') g.gowrappers.write(', ')
} }
} }
g.definitions.writeln(');\n return 0; }') g.gowrappers.writeln(');')
g.gowrappers.writeln('\treturn 0;')
g.gowrappers.writeln('}')
g.threaded_fns << name g.threaded_fns << name
} }
else{} else{}
@ -2898,4 +2904,3 @@ fn type_to_fmt(typ table.Type) string {
} }
return '%d' return '%d'
} }