10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-22 20:35:19 +01:00

Accelerated queue

This commit is contained in:
Anthony Scemama 2016-08-02 17:44:41 +02:00
parent 76f2953a02
commit a6fa9ddd88

View File

@ -9,6 +9,7 @@ type t =
clients : Id.Client.t Set.Poly.t;
next_client_id : Id.Client.t;
next_task_id : Id.Task.t;
number_of_queued : int;
}
@ -20,6 +21,7 @@ let create () =
clients = Set.Poly.empty;
next_client_id = Id.Client.of_int 1;
next_task_id = Id.Task.of_int 1;
number_of_queued = 0;
}
@ -33,6 +35,7 @@ let add_task ~task q =
queued = task_id :: q.queued ;
tasks = Map.add q.tasks ~key:task_id ~data:task ;
next_task_id = Id.Task.increment task_id ;
number_of_queued = q.number_of_queued + 1;
}
@ -59,6 +62,7 @@ let pop_task ~client_id q =
{ q with
queued = new_queue ;
running = Map.add running ~key:task_id ~data:client_id ;
number_of_queued = q.number_of_queued - 1;
}
in new_q, Some task_id, (Map.find q.tasks task_id)
| [] -> q, None, None
@ -103,7 +107,7 @@ let number q =
Map.length q.tasks
let number_of_queued q =
List.length q.queued
q.number_of_queued
let number_of_running q =
Map.length q.running