2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
23 type msgqueue(t : type);
25 fn msgqueue_new(w : world, t : type) : (world, msgqueue(t));
26 fn msgqueue_send(w : world, t : type, q : msgqueue(t), tag : int, v : t) : world;
27 fn msgqueue_replace(w : world, t : type, q : msgqueue(t), tag : int, v : t) : world;
28 fn msgqueue_receive(w : world, t : type, q : msgqueue(t)) : (world, int, t);
29 fn msgqueue_receive_tag(w : world, t : type, q : msgqueue(t), tag : int) : (world, int, t);
30 fn msgqueue_receive_nonblock(w : world, t : type, q : msgqueue(t)) : (world, int, t);
31 fn msgqueue_receive_tag_nonblock(w : world, t : type, q : msgqueue(t), tag : int) : (world, int, t);
32 fn msgqueue_peek_nonblock(w : world, t : type, q : msgqueue(t)) : (world, int, t);
33 fn msgqueue_peek_tag_nonblock(w : world, t : type, q : msgqueue(t), tag : int) : (world, int, t);
34 fn msgqueue_wait~lazy(w : world, t : type, q : msgqueue(t)) : unit_type;
35 fn msgqueue_is_nonempty(w : world, t : type, q : msgqueue(t)) : bool;
36 fn msgqueue_any~lazy(w : world, t1 t2 : type, q1 : msgqueue(t1), q2 : msgqueue(t2)) : bool;
40 type msgqueue(t : type) := internal_type;
42 fn msgqueue_new(w : world, t : type) : (world, msgqueue(t))
46 pcode IO IO_MsgQueue_New 2 1 0 =w2 =q w;
50 fn msgqueue_send(w : world, t : type, q : msgqueue(t), tag : int, v : t) : world
53 pcode IO IO_MsgQueue_Send 1 4 1 =w2 w q tag v 0;
57 fn msgqueue_replace(w : world, t : type, q : msgqueue(t), tag : int, v : t) : world
60 pcode IO IO_MsgQueue_Send 1 4 1 =w2 w q tag v 1;
64 fn msgqueue_receive(w : world, t : type, q : msgqueue(t)) : (world, int, t)
69 pcode IO IO_MsgQueue_Receive 3 2 1 =w2 =tg =v w q 0;
73 fn msgqueue_receive_tag(w : world, t : type, q : msgqueue(t), tag : int) : (world, int, t)
78 pcode IO IO_MsgQueue_Receive 3 3 1 =w2 =tg =v w q tag 1;
82 fn msgqueue_receive_nonblock(w : world, t : type, q : msgqueue(t)) : (world, int, t)
87 pcode IO IO_MsgQueue_Receive 3 2 1 =w2 =tg =v w q 2;
91 fn msgqueue_receive_tag_nonblock(w : world, t : type, q : msgqueue(t), tag : int) : (world, int, t)
96 pcode IO IO_MsgQueue_Receive 3 3 1 =w2 =tg =v w q tag 3;
100 fn msgqueue_peek_nonblock(w : world, t : type, q : msgqueue(t)) : (world, int, t)
105 pcode IO IO_MsgQueue_Receive 3 2 1 =w2 =tg =v w q 6;
109 fn msgqueue_peek_tag_nonblock(w : world, t : type, q : msgqueue(t), tag : int) : (world, int, t)
114 pcode IO IO_MsgQueue_Receive 3 3 1 =w2 =tg =v w q tag 7;
118 fn msgqueue_wait~lazy(w : world, t : type, q : msgqueue(t)) : unit_type
120 pcode IO IO_MsgQueue_Wait 0 2 0 w q;
124 fn msgqueue_is_nonempty(w : world, t : type, q : msgqueue(t)) : bool
127 pcode IO IO_MsgQueue_Is_Nonempty 1 2 0 =e w q;
131 fn msgqueue_any~lazy(implicit w : world, t1 t2 : type, q1 : msgqueue(t1), q2 : msgqueue(t2)) : bool
133 var wait1 := msgqueue_wait(t1, q1);
134 var wait2 := msgqueue_wait(t2, q2);
135 return any(wait1, wait2);