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/>.
25 fn mutex_new(w : world) : (world, mutex);
26 fn mutex_lock(w : world, m : mutex) : world;
27 fn mutex_unlock(w : world, m : mutex) : world;
33 type mutex := msgqueue(unit_type);
35 fn mutex_new(implicit w : world) : (world, mutex)
37 var m := msgqueue_new(unit_type);
42 fn mutex_lock(implicit w : world, m : mutex) : world
44 var tag, val := msgqueue_receive(m);
47 fn mutex_unlock(implicit w : world, m : mutex) : world
49 if msgqueue_is_nonempty(m) then
50 abort internal("unlocking unlocked mutex");
51 msgqueue_send(m, 0, unit_value);