sync: enable compilation with -autofree

pull/6715/head
Delyan Angelov 2020-10-29 12:17:08 +02:00
parent 367067dfff
commit be02ee97fb
1 changed files with 8 additions and 4 deletions

View File

@ -109,17 +109,21 @@ pub fn new_channel<T>(n u32) &Channel {
} }
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 }
rsem := if n > 0 { u32(0) } else { 1 }
rbuf := if n > 0 { malloc(int(n * st)) } else { byteptr(0) }
sbuf := if n > 0 { vcalloc(int(n * 2)) } else { byteptr(0) }
return &Channel{ return &Channel{
writesem: new_semaphore_init(if n > 0 { n } else { 1 }) writesem: new_semaphore_init(wsem)
readsem: new_semaphore_init(if n > 0 { u32(0) } else { 1 }) readsem: new_semaphore_init(rsem)
writesem_im: new_semaphore() writesem_im: new_semaphore()
readsem_im: new_semaphore() readsem_im: new_semaphore()
objsize: st objsize: st
cap: n cap: n
write_free: n write_free: n
read_avail: 0 read_avail: 0
ringbuf: if n > 0 { malloc(int(n * st)) } else { byteptr(0) } ringbuf: rbuf
statusbuf: if n > 0 { vcalloc(int(n * 2)) } else { byteptr(0) } statusbuf: sbuf
write_subscriber: 0 write_subscriber: 0
read_subscriber: 0 read_subscriber: 0
} }