interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / profile / cases / lock-unbounded.om

129 lines · 1889 bytes Raw Blame History
1note B1 control: lock.om with the lacq retry bound removed.
2note SPDX-License-Identifier: AGPL-3.0-only
3note Cross-process lock for the authority store. A lock is an O_EXCL file containing the owner pid.
4note A contending process retries with a bounded sleep; a lock whose pid is gone is reclaimed.
5note This serializes the read-check-persist window. It does not serialize the effect itself.
6global lb uchar 8
7global lerr ulong 1
8text lpath "build/authority-store/lock"
9
10fn lpid p ulong to void
11put lb 0 uchar and p 255
12put lb 1 uchar and shr p 8 255
13put lb 2 uchar and shr p 16 255
14put lb 3 uchar and shr p 24 255
15put lb 4 uchar and shr p 32 255
16put lb 5 uchar and shr p 40 255
17put lb 6 uchar and shr p 48 255
18put lb 7 uchar shr p 56
19end
20
21fn lget to ulong
22v = ulong 0
23for i ulong 8
24v = or v shl ulong get lb i mul i 8
25end
26ret v
27end
28
29note p10 effect
30fn ltake p ulong to ulong
31fd = fopen lpath 0 len lpath 193 384
32if lt fd 0
33if eq fd -17
34ret 20
35end
36ret 40
37end
38lpid p
39n = write int fd lb 0 8
40if ne n 8
41if ne fclose int fd 0
42ret 30
43end
44ret 31
45end
46if ne fclose int fd 0
47ret 31
48end
49ret 0
50end
51
52note p10 effect
53fn lread to ulong
54put lerr 0 0
55fd = fopen lpath 0 len lpath 0 0
56if lt fd 0
57put lerr 0 32
58ret 0
59end
60n = read int fd lb 0 8
61if ne fclose int fd 0
62put lerr 0 33
63ret 0
64end
65if ne n 8
66put lerr 0 34
67ret 0
68end
69ret lget
70end
71
72note p10 effect
73fn lrm to ulong
74r = unlink lpath 0 len lpath
75if lt r 0
76ret 41
77end
78ret 0
79end
80
81note p10 effect
82fn ltry p ulong to ulong
83r = ltake p
84if eq r 0
85ret 0
86end
87if ne r 20
88ret r
89end
90q = lread
91if ne get lerr 0 0
92ret 40
93end
94k = killpid int q 0
95if ne k -3
96ret 20
97end
98r = lrm
99if ne r 0
100ret 41
101end
102ret ltake p
103end
104
105note p10 effect
106fn lacq p ulong tries ulong to ulong
107if gt tries 1000
108ret 43
109end
110i = ulong 0
111while lt i tries
112r = ltry p
113if eq r 0
114ret 0
115end
116if ne r 20
117ret r
118end
119if ne sleepns 1000000 0
120ret 42
121end
122i = add i 1
123end
124ret 22
125end
126
127fn lrel to ulong
128ret lrm
129end