gc: extend optimized mode to channel buffers (#10443)
parent
e5debbbe01
commit
a8437584aa
|
@ -121,15 +121,19 @@ pub:
|
||||||
|
|
||||||
pub fn new_channel<T>(n u32) &Channel {
|
pub fn new_channel<T>(n u32) &Channel {
|
||||||
st := sizeof(T)
|
st := sizeof(T)
|
||||||
|
if isreftype(T) {
|
||||||
return new_channel_st(n, st)
|
return new_channel_st(n, st)
|
||||||
|
} else {
|
||||||
|
return new_channel_st_noscan(n, st)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_channel_st(n u32, st u32) &Channel {
|
fn new_channel_st(n u32, st u32) &Channel {
|
||||||
wsem := if n > 0 { n } else { 1 }
|
wsem := if n > 0 { n } else { 1 }
|
||||||
rsem := if n > 0 { u32(0) } else { 1 }
|
rsem := if n > 0 { u32(0) } else { 1 }
|
||||||
rbuf := if n > 0 { unsafe { malloc(int(n * st)) } } else { &byte(0) }
|
rbuf := if n > 0 { unsafe { malloc(int(n * st)) } } else { &byte(0) }
|
||||||
sbuf := if n > 0 { vcalloc(int(n * 2)) } else { &byte(0) }
|
sbuf := if n > 0 { vcalloc_noscan(int(n * 2)) } else { &byte(0) }
|
||||||
mut ch := &Channel{
|
mut ch := Channel{
|
||||||
objsize: st
|
objsize: st
|
||||||
cap: n
|
cap: n
|
||||||
write_free: n
|
write_free: n
|
||||||
|
@ -143,7 +147,33 @@ fn new_channel_st(n u32, st u32) &Channel {
|
||||||
ch.readsem.init(rsem)
|
ch.readsem.init(rsem)
|
||||||
ch.writesem_im.init(0)
|
ch.writesem_im.init(0)
|
||||||
ch.readsem_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 {
|
pub fn (ch &Channel) auto_str(typename string) string {
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor {
|
||||||
if isnil(context.callback) {
|
if isnil(context.callback) {
|
||||||
panic('You need to pass a valid callback to new_pool_processor.')
|
panic('You need to pass a valid callback to new_pool_processor.')
|
||||||
}
|
}
|
||||||
mut pool := &PoolProcessor{
|
mut pool := PoolProcessor{
|
||||||
items: []
|
items: []
|
||||||
results: []
|
results: []
|
||||||
shared_context: voidptr(0)
|
shared_context: voidptr(0)
|
||||||
|
@ -55,7 +55,7 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor {
|
||||||
thread_cb: voidptr(context.callback)
|
thread_cb: voidptr(context.callback)
|
||||||
}
|
}
|
||||||
pool.waitgroup.init()
|
pool.waitgroup.init()
|
||||||
return pool
|
return &pool
|
||||||
}
|
}
|
||||||
|
|
||||||
// set_max_jobs gives you the ability to override the number
|
// set_max_jobs gives you the ability to override the number
|
||||||
|
|
|
@ -26,9 +26,9 @@ mut:
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_waitgroup() &WaitGroup {
|
pub fn new_waitgroup() &WaitGroup {
|
||||||
mut wg := &WaitGroup{}
|
mut wg := WaitGroup{}
|
||||||
wg.init()
|
wg.init()
|
||||||
return wg
|
return &wg
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut wg WaitGroup) init() {
|
pub fn (mut wg WaitGroup) init() {
|
||||||
|
|
|
@ -3116,7 +3116,8 @@ fn (mut g Gen) expr(node ast.Expr) {
|
||||||
}
|
}
|
||||||
ast.ChanInit {
|
ast.ChanInit {
|
||||||
elem_typ_str := g.typ(node.elem_type)
|
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 {
|
if node.has_cap {
|
||||||
g.expr(node.cap_expr)
|
g.expr(node.cap_expr)
|
||||||
} else {
|
} 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)
|
return g.type_default((sym.info as ast.Alias).parent_type)
|
||||||
}
|
}
|
||||||
.chan {
|
.chan {
|
||||||
elemtypstr := g.typ(sym.chan_info().elem_type)
|
elem_type := sym.chan_info().elem_type
|
||||||
return 'sync__new_channel_st(0, sizeof($elemtypstr))'
|
elemtypstr := g.typ(elem_type)
|
||||||
|
noscan := g.check_noscan(elem_type)
|
||||||
|
return 'sync__new_channel_st${noscan}(0, sizeof($elemtypstr))'
|
||||||
}
|
}
|
||||||
.array {
|
.array {
|
||||||
elem_typ := sym.array_info().elem_type
|
elem_typ := sym.array_info().elem_type
|
||||||
|
|
|
@ -56,6 +56,7 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
|
||||||
// string. methods
|
// string. methods
|
||||||
'18.add',
|
'18.add',
|
||||||
'18.trim_space',
|
'18.trim_space',
|
||||||
|
'18.repeat',
|
||||||
'18.replace',
|
'18.replace',
|
||||||
'18.clone',
|
'18.clone',
|
||||||
'18.clone_static',
|
'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_') {
|
|| k.starts_with('map_') {
|
||||||
walker.fn_decl(mut mfn)
|
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 {
|
} else {
|
||||||
for map_fn_name in ['new_map', 'new_map_init', 'map_hash_string', 'new_dense_array'] {
|
for map_fn_name in ['new_map', 'new_map_init', 'map_hash_string', 'new_dense_array'] {
|
||||||
|
|
Loading…
Reference in New Issue