sync: close channels atomically only once (#9645)

pull/9647/head
Uwe Krüger 2021-04-09 09:57:41 +02:00 committed by GitHub
parent e6a67e7172
commit 78e3bb748b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -138,7 +138,10 @@ fn new_channel_st(n u32, st u32) &Channel {
}
pub fn (mut ch Channel) close() {
C.atomic_store_u16(&ch.closed, 1)
open_val := u16(0)
if !C.atomic_compare_exchange_strong_u16(&ch.closed, &open_val, 1) {
return
}
mut nulladr := voidptr(0)
for !C.atomic_compare_exchange_weak_ptr(&ch.adr_written, &nulladr, voidptr(-1)) {
nulladr = voidptr(0)