diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-11-25 18:15:36 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-11-25 18:15:36 +0100 |
commit | 2b646cc0a3ec9b84555ded92a7bd2bc053ac3890 (patch) | |
tree | 04dc3aecdc02eb099a77fa242c7983ce2cef0f18 | |
parent | 35226d93e729bb98825eea4ab388c4045b838834 (diff) | |
download | libgee-2b646cc0a3ec9b84555ded92a7bd2bc053ac3890.tar.gz |
Flatten call structure a bit
-rw-r--r-- | gee/lazy.vala | 12 | ||||
-rw-r--r-- | gee/promise.vala | 26 |
2 files changed, 21 insertions, 17 deletions
diff --git a/gee/lazy.vala b/gee/lazy.vala index 4e09e8b..19839c5 100644 --- a/gee/lazy.vala +++ b/gee/lazy.vala @@ -110,14 +110,18 @@ public class Gee.Lazy<G> { _mutex.lock (); if (_lazy._func != null) { if (_state == State.EVAL) { + bool res = true; while (_state == State.EVAL) { - if (!_eval.wait_until (_mutex, end_time)) { - value = null; - _mutex.unlock (); - return false; + res = _eval.wait_until (_mutex, end_time); + if (!res) { + break; } } _mutex.unlock (); + if (!res) { + value = null; + return false; + } } else { do_eval (); } diff --git a/gee/promise.vala b/gee/promise.vala index 020138e..ed7b872 100644 --- a/gee/promise.vala +++ b/gee/promise.vala @@ -92,11 +92,9 @@ public class Gee.Promise<G> { public unowned G wait () throws FutureError { _mutex.lock (); State state = _state; - if (_state == State.INIT) { - while (_state == State.INIT) { - _set.wait (_mutex); - state = _state; - } + while (_state == State.INIT) { + _set.wait (_mutex); + state = _state; } _mutex.unlock (); switch (state) { @@ -114,17 +112,19 @@ public class Gee.Promise<G> { public bool wait_until (int64 end_time, out unowned G? value = null) throws FutureError { _mutex.lock (); State state = _state; - if (state == State.INIT) { - while (_state == State.INIT) { - if (!_set.wait_until (_mutex, end_time)) { - value = null; - _mutex.unlock (); - return false; - } - state = _state; + bool res = true; + while (_state == State.INIT) { + res = _set.wait_until (_mutex, end_time); + if (!res) { + break; } + state = _state; } _mutex.unlock (); + if (!res) { + value = null; + return false; + } switch (state) { case State.ABANDON: throw new FutureError.ABANDON_PROMISE ("Promise has been abandon"); |