mirror of
https://github.com/c-cube/nanoev.git
synced 2025-12-06 11:15:48 -05:00
fix(unix): properly implement timers(!)
This commit is contained in:
parent
1dcadb3470
commit
03af765e43
1 changed files with 19 additions and 1 deletions
|
|
@ -174,17 +174,35 @@ let next_deadline_ (self : st) : float option =
|
||||||
let step (self : st) : unit =
|
let step (self : st) : unit =
|
||||||
let@ _sp = Trace_.with_span ~__FILE__ ~__LINE__ "nanoev.unix.step" in
|
let@ _sp = Trace_.with_span ~__FILE__ ~__LINE__ "nanoev.unix.step" in
|
||||||
(* gather the subscriptions and timeout *)
|
(* gather the subscriptions and timeout *)
|
||||||
|
let now = now_ () in
|
||||||
let timeout, sub_r, sub_w =
|
let timeout, sub_r, sub_w =
|
||||||
let@ self = with_lock_ self in
|
let@ self = with_lock_ self in
|
||||||
recompute_if_needed self;
|
recompute_if_needed self;
|
||||||
let timeout =
|
let timeout =
|
||||||
match next_deadline_ self with
|
match next_deadline_ self with
|
||||||
| None -> 30.
|
| None -> 30.
|
||||||
| Some d -> max 0. (d -. now_ ())
|
| Some d -> max 0. (d -. now)
|
||||||
in
|
in
|
||||||
timeout, self.sub_r, self.sub_w
|
timeout, self.sub_r, self.sub_w
|
||||||
in
|
in
|
||||||
|
|
||||||
|
(* run timers *)
|
||||||
|
while
|
||||||
|
if Heap.is_empty self.timer then
|
||||||
|
false
|
||||||
|
else (
|
||||||
|
let (Timer t) = Heap.peek_min_exn self.timer in
|
||||||
|
if t.deadline <= now then (
|
||||||
|
ignore (Heap.pop_min_exn self.timer : timer_ev);
|
||||||
|
t.f t.x t.y;
|
||||||
|
true
|
||||||
|
) else
|
||||||
|
false
|
||||||
|
)
|
||||||
|
do
|
||||||
|
()
|
||||||
|
done;
|
||||||
|
|
||||||
(* enter [select] *)
|
(* enter [select] *)
|
||||||
Atomic.set self.in_select true;
|
Atomic.set self.in_select true;
|
||||||
let r_reads, r_writes, _ =
|
let r_reads, r_writes, _ =
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue