From: Brendan Hansen Date: Tue, 23 Nov 2021 18:24:53 +0000 (-0600) Subject: bugfixes with range iterator and mutex improvement X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ebf5eb5418391df5d039d7f5ec98d10da80b743b;p=onyx.git bugfixes with range iterator and mutex improvement --- diff --git a/core/container/iter.onyx b/core/container/iter.onyx index 8778c9cd..c035c8d1 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -338,11 +338,21 @@ from_array :: (arr: [] $T) -> Iterator(^T) { } next :: (use c: ^Context) -> (i32, bool) { - if v >= r.high { - return 0, false; + if r.step > 0 { + if v >= r.high { + return 0, false; + } else { + defer v += r.step; + return v, true; + } + } else { - defer v += r.step; - return v, true; + if v < r.high { + return 0, false; + } else { + defer v += r.step; + return v, true; + } } } diff --git a/core/sync/mutex.onyx b/core/sync/mutex.onyx index 5fb23160..90618284 100644 --- a/core/sync/mutex.onyx +++ b/core/sync/mutex.onyx @@ -24,10 +24,12 @@ Mutex :: struct { mutex_init :: (m: ^Mutex) { m.lock = 0; + m.owner = -1; } mutex_destroy :: (m: ^Mutex) { m.lock = -1; + m.owner = -1; } mutex_lock :: (m: ^Mutex) { @@ -42,6 +44,8 @@ mutex_lock :: (m: ^Mutex) { if context.thread_id != 0 { __atomic_wait(^m.lock, 1); } + } else { + while (m.lock == 1) --- } } @@ -68,6 +72,7 @@ scoped_mutex :: macro (m: ^Mutex) { } critical_section :: macro (m: ^Mutex, body: Code) -> i32 { + scoped_mutex :: scoped_mutex; scoped_mutex(m); #insert body;