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