Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/profile/cases/lock-unbounded.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / profile / cases / lock-unbounded.om` 129 lines ยท 1889 bytes Raw Blame History 1 note B1 control: lock.om with the lacq retry bound removed. 2 note SPDX-License-Identifier: AGPL-3.0-only 3 note Cross-process lock for the authority store. A lock is an O_EXCL file containing the owner pid. 4 note A contending process retries with a bounded sleep; a lock whose pid is gone is reclaimed. 5 note This serializes the read-check-persist window. It does not serialize the effect itself. 6 global lb uchar 8 7 global lerr ulong 1 8 text lpath "build/authority-store/lock" 9 10 fn lpid p ulong to void 11 put lb 0 uchar and p 255 12 put lb 1 uchar and shr p 8 255 13 put lb 2 uchar and shr p 16 255 14 put lb 3 uchar and shr p 24 255 15 put lb 4 uchar and shr p 32 255 16 put lb 5 uchar and shr p 40 255 17 put lb 6 uchar and shr p 48 255 18 put lb 7 uchar shr p 56 19 end 20 21 fn lget to ulong 22 v = ulong 0 23 for i ulong 8 24 v = or v shl ulong get lb i mul i 8 25 end 26 ret v 27 end 28 29 note p10 effect 30 fn ltake p ulong to ulong 31 fd = fopen lpath 0 len lpath 193 384 32 if lt fd 0 33 if eq fd -17 34 ret 20 35 end 36 ret 40 37 end 38 lpid p 39 n = write int fd lb 0 8 40 if ne n 8 41 if ne fclose int fd 0 42 ret 30 43 end 44 ret 31 45 end 46 if ne fclose int fd 0 47 ret 31 48 end 49 ret 0 50 end 51 52 note p10 effect 53 fn lread to ulong 54 put lerr 0 0 55 fd = fopen lpath 0 len lpath 0 0 56 if lt fd 0 57 put lerr 0 32 58 ret 0 59 end 60 n = read int fd lb 0 8 61 if ne fclose int fd 0 62 put lerr 0 33 63 ret 0 64 end 65 if ne n 8 66 put lerr 0 34 67 ret 0 68 end 69 ret lget 70 end 71 72 note p10 effect 73 fn lrm to ulong 74 r = unlink lpath 0 len lpath 75 if lt r 0 76 ret 41 77 end 78 ret 0 79 end 80 81 note p10 effect 82 fn ltry p ulong to ulong 83 r = ltake p 84 if eq r 0 85 ret 0 86 end 87 if ne r 20 88 ret r 89 end 90 q = lread 91 if ne get lerr 0 0 92 ret 40 93 end 94 k = killpid int q 0 95 if ne k -3 96 ret 20 97 end 98 r = lrm 99 if ne r 0 100 ret 41 101 end 102 ret ltake p 103 end 104 105 note p10 effect 106 fn lacq p ulong tries ulong to ulong 107 if gt tries 1000 108 ret 43 109 end 110 i = ulong 0 111 while lt i tries 112 r = ltry p 113 if eq r 0 114 ret 0 115 end 116 if ne r 20 117 ret r 118 end 119 if ne sleepns `1000000` 0 120 ret 42 121 end 122 i = add i 1 123 end 124 ret 22 125 end 126 127 fn lrel to ulong 128 ret lrm 129 end