1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: make v test-cleancode test everything by default (#10050)

This commit is contained in:
Delyan Angelov
2021-05-08 13:32:29 +03:00
committed by GitHub
parent cba2cb6b9c
commit 8a380f4699
132 changed files with 3230 additions and 3440 deletions

View File

@ -16,6 +16,7 @@ fn C.SleepConditionVariableSRW(voidptr, voidptr, u32, u32) int
// Mutex HANDLE
type MHANDLE = voidptr
// Semaphore HANDLE
type SHANDLE = voidptr
@ -25,18 +26,18 @@ type SHANDLE = voidptr
[heap]
pub struct Mutex {
mut:
mx C.SRWLOCK // mutex handle
mx C.SRWLOCK // mutex handle
}
[heap]
pub struct RwMutex {
mut:
mx C.SRWLOCK // mutex handle
mx C.SRWLOCK // mutex handle
}
[heap]
struct Semaphore {
mtx C.SRWLOCK
mtx C.SRWLOCK
cond C.CONDITION_VARIABLE
mut:
count u32
@ -113,7 +114,9 @@ pub fn (mut sem Semaphore) init(n u32) {
pub fn (mut sem Semaphore) post() {
mut c := C.atomic_load_u32(&sem.count)
for c > 1 {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c+1) { return }
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c + 1) {
return
}
}
C.AcquireSRWLockExclusive(&sem.mtx)
c = C.atomic_fetch_add_u32(&sem.count, 1)
@ -126,18 +129,20 @@ pub fn (mut sem Semaphore) post() {
pub fn (mut sem Semaphore) wait() {
mut c := C.atomic_load_u32(&sem.count)
for c > 0 {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c-1) { return }
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c - 1) {
return
}
}
C.AcquireSRWLockExclusive(&sem.mtx)
c = C.atomic_load_u32(&sem.count)
outer:
for {
outer: for {
if c == 0 {
C.SleepConditionVariableSRW(&sem.cond, &sem.mtx, C.INFINITE, 0)
c = C.atomic_load_u32(&sem.count)
}
for c > 0 {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c-1) {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c - 1) {
if c > 1 {
C.WakeConditionVariable(&sem.cond)
}
@ -151,7 +156,9 @@ outer:
pub fn (mut sem Semaphore) try_wait() bool {
mut c := C.atomic_load_u32(&sem.count)
for c > 0 {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c-1) { return true }
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c - 1) {
return true
}
}
return false
}
@ -159,14 +166,16 @@ pub fn (mut sem Semaphore) try_wait() bool {
pub fn (mut sem Semaphore) timed_wait(timeout time.Duration) bool {
mut c := C.atomic_load_u32(&sem.count)
for c > 0 {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c-1) { return true }
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c - 1) {
return true
}
}
C.AcquireSRWLockExclusive(&sem.mtx)
t_ms := u32(timeout / time.millisecond)
mut res := 0
c = C.atomic_load_u32(&sem.count)
outer:
for {
outer: for {
if c == 0 {
res = C.SleepConditionVariableSRW(&sem.cond, &sem.mtx, t_ms, 0)
if res == 0 {
@ -175,7 +184,7 @@ outer:
c = C.atomic_load_u32(&sem.count)
}
for c > 0 {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c-1) {
if C.atomic_compare_exchange_weak_u32(&sem.count, &c, c - 1) {
if c > 1 {
C.WakeConditionVariable(&sem.cond)
}