gc: extend optimized mode to channel buffers (#10443)

pull/10457/head
Uwe Krüger 2021-06-14 17:12:47 +02:00 committed by GitHub
parent e5debbbe01
commit a8437584aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 11 deletions

View File

@ -121,15 +121,19 @@ pub:
pub fn new_channel<T>(n u32) &Channel {
st := sizeof(T)
if isreftype(T) {
return new_channel_st(n, st)
} else {
return new_channel_st_noscan(n, st)
}
}
fn new_channel_st(n u32, st u32) &Channel {
wsem := if n > 0 { n } else { 1 }
rsem := if n > 0 { u32(0) } else { 1 }
rbuf := if n > 0 { unsafe { malloc(int(n * st)) } } else { &byte(0) }
sbuf := if n > 0 { vcalloc(int(n * 2)) } else { &byte(0) }
mut ch := &Channel{
sbuf := if n > 0 { vcalloc_noscan(int(n * 2)) } else { &byte(0) }
mut ch := Channel{
objsize: st
cap: n
write_free: n
@ -143,7 +147,33 @@ fn new_channel_st(n u32, st u32) &Channel {
ch.readsem.init(rsem)
ch.writesem_im.init(0)
ch.readsem_im.init(0)
return ch
return &ch
}
fn new_channel_st_noscan(n u32, st u32) &Channel {
$if gcboehm_opt ? {
wsem := if n > 0 { n } else { 1 }
rsem := if n > 0 { u32(0) } else { 1 }
rbuf := if n > 0 { unsafe { malloc_noscan(int(n * st)) } } else { &byte(0) }
sbuf := if n > 0 { vcalloc_noscan(int(n * 2)) } else { &byte(0) }
mut ch := Channel{
objsize: st
cap: n
write_free: n
read_avail: 0
ringbuf: rbuf
statusbuf: sbuf
write_subscriber: 0
read_subscriber: 0
}
ch.writesem.init(wsem)
ch.readsem.init(rsem)
ch.writesem_im.init(0)
ch.readsem_im.init(0)
return &ch
} $else {
return new_channel_st(n, st)
}
}
pub fn (ch &Channel) auto_str(typename string) string {

View File

@ -45,7 +45,7 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor {
if isnil(context.callback) {
panic('You need to pass a valid callback to new_pool_processor.')
}
mut pool := &PoolProcessor{
mut pool := PoolProcessor{
items: []
results: []
shared_context: voidptr(0)
@ -55,7 +55,7 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor {
thread_cb: voidptr(context.callback)
}
pool.waitgroup.init()
return pool
return &pool
}
// set_max_jobs gives you the ability to override the number

View File

@ -26,9 +26,9 @@ mut:
}
pub fn new_waitgroup() &WaitGroup {
mut wg := &WaitGroup{}
mut wg := WaitGroup{}
wg.init()
return wg
return &wg
}
pub fn (mut wg WaitGroup) init() {

View File

@ -3116,7 +3116,8 @@ fn (mut g Gen) expr(node ast.Expr) {
}
ast.ChanInit {
elem_typ_str := g.typ(node.elem_type)
g.write('sync__new_channel_st(')
noscan := g.check_noscan(node.elem_type)
g.write('sync__new_channel_st${noscan}(')
if node.has_cap {
g.expr(node.cap_expr)
} else {
@ -6074,8 +6075,10 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
return g.type_default((sym.info as ast.Alias).parent_type)
}
.chan {
elemtypstr := g.typ(sym.chan_info().elem_type)
return 'sync__new_channel_st(0, sizeof($elemtypstr))'
elem_type := sym.chan_info().elem_type
elemtypstr := g.typ(elem_type)
noscan := g.check_noscan(elem_type)
return 'sync__new_channel_st${noscan}(0, sizeof($elemtypstr))'
}
.array {
elem_typ := sym.array_info().elem_type

View File

@ -56,6 +56,7 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
// string. methods
'18.add',
'18.trim_space',
'18.repeat',
'18.replace',
'18.clone',
'18.clone_static',
@ -302,6 +303,14 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
|| k.starts_with('map_') {
walker.fn_decl(mut mfn)
}
if pref.gc_mode in [.boehm_full_opt, .boehm_incr_opt] {
if k in ['new_map_noscan_key', 'new_map_noscan_value', 'new_map_noscan_key_value',
'new_map_init_noscan_key', 'new_map_init_noscan_value',
'new_map_init_noscan_key_value',
] {
walker.fn_decl(mut mfn)
}
}
}
} else {
for map_fn_name in ['new_map', 'new_map_init', 'map_hash_string', 'new_dense_array'] {