vlib: replace all `goto` statements with labelled break (#8531)
parent
7ec116d588
commit
82482167ce
|
@ -32,7 +32,6 @@ fn (mut s Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
|
||||||
s.subindex++
|
s.subindex++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
goto next
|
|
||||||
} else {
|
} else {
|
||||||
s.failed = true
|
s.failed = true
|
||||||
if is_tail {
|
if is_tail {
|
||||||
|
@ -42,7 +41,6 @@ fn (mut s Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
next:
|
|
||||||
s.index++
|
s.index++
|
||||||
s.subindex = 0
|
s.subindex = 0
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -563,6 +563,7 @@ pub fn channel_select(mut channels []&Channel, dir []Direction, mut objrefs []vo
|
||||||
}
|
}
|
||||||
stopwatch := if timeout <= 0 { time.StopWatch{} } else { time.new_stopwatch({}) }
|
stopwatch := if timeout <= 0 { time.StopWatch{} } else { time.new_stopwatch({}) }
|
||||||
mut event_idx := -1 // negative index means `timed out`
|
mut event_idx := -1 // negative index means `timed out`
|
||||||
|
outer:
|
||||||
for {
|
for {
|
||||||
rnd := rand.u32_in_range(0, u32(channels.len))
|
rnd := rand.u32_in_range(0, u32(channels.len))
|
||||||
mut num_closed := 0
|
mut num_closed := 0
|
||||||
|
@ -575,7 +576,7 @@ pub fn channel_select(mut channels []&Channel, dir []Direction, mut objrefs []vo
|
||||||
stat := channels[i].try_push_priv(objrefs[i], true)
|
stat := channels[i].try_push_priv(objrefs[i], true)
|
||||||
if stat == .success {
|
if stat == .success {
|
||||||
event_idx = i
|
event_idx = i
|
||||||
goto restore
|
break outer
|
||||||
} else if stat == .closed {
|
} else if stat == .closed {
|
||||||
num_closed++
|
num_closed++
|
||||||
}
|
}
|
||||||
|
@ -583,7 +584,7 @@ pub fn channel_select(mut channels []&Channel, dir []Direction, mut objrefs []vo
|
||||||
stat := channels[i].try_pop_priv(objrefs[i], true)
|
stat := channels[i].try_pop_priv(objrefs[i], true)
|
||||||
if stat == .success {
|
if stat == .success {
|
||||||
event_idx = i
|
event_idx = i
|
||||||
goto restore
|
break outer
|
||||||
} else if stat == .closed {
|
} else if stat == .closed {
|
||||||
num_closed++
|
num_closed++
|
||||||
}
|
}
|
||||||
|
@ -591,21 +592,20 @@ pub fn channel_select(mut channels []&Channel, dir []Direction, mut objrefs []vo
|
||||||
}
|
}
|
||||||
if num_closed == channels.len {
|
if num_closed == channels.len {
|
||||||
event_idx = -2
|
event_idx = -2
|
||||||
goto restore
|
break outer
|
||||||
}
|
}
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
goto restore
|
break outer
|
||||||
}
|
}
|
||||||
if timeout > 0 {
|
if timeout > 0 {
|
||||||
remaining := timeout - stopwatch.elapsed()
|
remaining := timeout - stopwatch.elapsed()
|
||||||
if !sem.timed_wait(remaining) {
|
if !sem.timed_wait(remaining) {
|
||||||
goto restore
|
break outer
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sem.wait()
|
sem.wait()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
restore:
|
|
||||||
// reset subscribers
|
// reset subscribers
|
||||||
for i, ch in channels {
|
for i, ch in channels {
|
||||||
if dir[i] == .push {
|
if dir[i] == .push {
|
||||||
|
|
|
@ -149,6 +149,7 @@ pub fn (mut sem Semaphore) wait() {
|
||||||
}
|
}
|
||||||
C.pthread_mutex_lock(&sem.mtx)
|
C.pthread_mutex_lock(&sem.mtx)
|
||||||
c = C.atomic_load_u32(&sem.count)
|
c = C.atomic_load_u32(&sem.count)
|
||||||
|
outer:
|
||||||
for {
|
for {
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
C.pthread_cond_wait(&sem.cond, &sem.mtx)
|
C.pthread_cond_wait(&sem.cond, &sem.mtx)
|
||||||
|
@ -159,11 +160,10 @@ pub fn (mut sem Semaphore) wait() {
|
||||||
if c > 1 {
|
if c > 1 {
|
||||||
C.pthread_cond_signal(&sem.cond)
|
C.pthread_cond_signal(&sem.cond)
|
||||||
}
|
}
|
||||||
goto unlock
|
break outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock:
|
|
||||||
C.pthread_mutex_unlock(&sem.mtx)
|
C.pthread_mutex_unlock(&sem.mtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,11 +184,12 @@ pub fn (mut sem Semaphore) timed_wait(timeout time.Duration) bool {
|
||||||
t_spec := timeout.timespec()
|
t_spec := timeout.timespec()
|
||||||
mut res := 0
|
mut res := 0
|
||||||
c = C.atomic_load_u32(&sem.count)
|
c = C.atomic_load_u32(&sem.count)
|
||||||
|
outer:
|
||||||
for {
|
for {
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
res = C.pthread_cond_timedwait(&sem.cond, &sem.mtx, &t_spec)
|
res = C.pthread_cond_timedwait(&sem.cond, &sem.mtx, &t_spec)
|
||||||
if res == C.ETIMEDOUT {
|
if res == C.ETIMEDOUT {
|
||||||
goto unlock
|
break outer
|
||||||
}
|
}
|
||||||
c = C.atomic_load_u32(&sem.count)
|
c = C.atomic_load_u32(&sem.count)
|
||||||
}
|
}
|
||||||
|
@ -197,11 +198,10 @@ pub fn (mut sem Semaphore) timed_wait(timeout time.Duration) bool {
|
||||||
if c > 1 {
|
if c > 1 {
|
||||||
C.pthread_cond_signal(&sem.cond)
|
C.pthread_cond_signal(&sem.cond)
|
||||||
}
|
}
|
||||||
goto unlock
|
break outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock:
|
|
||||||
C.pthread_mutex_unlock(&sem.mtx)
|
C.pthread_mutex_unlock(&sem.mtx)
|
||||||
return res == 0
|
return res == 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ pub fn (mut sem Semaphore) wait() {
|
||||||
}
|
}
|
||||||
C.AcquireSRWLockExclusive(&sem.mtx)
|
C.AcquireSRWLockExclusive(&sem.mtx)
|
||||||
c = C.atomic_load_u32(&sem.count)
|
c = C.atomic_load_u32(&sem.count)
|
||||||
|
outer:
|
||||||
for {
|
for {
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
C.SleepConditionVariableSRW(&sem.cond, &sem.mtx, C.INFINITE, 0)
|
C.SleepConditionVariableSRW(&sem.cond, &sem.mtx, C.INFINITE, 0)
|
||||||
|
@ -135,11 +136,10 @@ pub fn (mut sem Semaphore) wait() {
|
||||||
if c > 1 {
|
if c > 1 {
|
||||||
C.WakeConditionVariable(&sem.cond)
|
C.WakeConditionVariable(&sem.cond)
|
||||||
}
|
}
|
||||||
goto unlock
|
break outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock:
|
|
||||||
C.ReleaseSRWLockExclusive(&sem.mtx)
|
C.ReleaseSRWLockExclusive(&sem.mtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,11 +160,12 @@ pub fn (mut sem Semaphore) timed_wait(timeout time.Duration) bool {
|
||||||
t_ms := u32(timeout / time.millisecond)
|
t_ms := u32(timeout / time.millisecond)
|
||||||
mut res := 0
|
mut res := 0
|
||||||
c = C.atomic_load_u32(&sem.count)
|
c = C.atomic_load_u32(&sem.count)
|
||||||
|
outer:
|
||||||
for {
|
for {
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
res = C.SleepConditionVariableSRW(&sem.cond, &sem.mtx, t_ms, 0)
|
res = C.SleepConditionVariableSRW(&sem.cond, &sem.mtx, t_ms, 0)
|
||||||
if res == 0 {
|
if res == 0 {
|
||||||
goto unlock
|
break outer
|
||||||
}
|
}
|
||||||
c = C.atomic_load_u32(&sem.count)
|
c = C.atomic_load_u32(&sem.count)
|
||||||
}
|
}
|
||||||
|
@ -173,11 +174,10 @@ pub fn (mut sem Semaphore) timed_wait(timeout time.Duration) bool {
|
||||||
if c > 1 {
|
if c > 1 {
|
||||||
C.WakeConditionVariable(&sem.cond)
|
C.WakeConditionVariable(&sem.cond)
|
||||||
}
|
}
|
||||||
goto unlock
|
break outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock:
|
|
||||||
C.ReleaseSRWLockExclusive(&sem.mtx)
|
C.ReleaseSRWLockExclusive(&sem.mtx)
|
||||||
return res != 0
|
return res != 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue