hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

lock.ha (532B)


      1 // License: MPL-2.0
      2 use rt;
      3 
      4 // Lock operation to use with [[lock]].
      5 export type lockop = enum int {
      6 	// shared file lock
      7 	SHARED    = rt::LOCK_SH,
      8 	// exclusive file lock
      9 	EXCLUSIVE = rt::LOCK_EX,
     10 	// unlock file
     11 	UNLOCK    = rt::LOCK_UN,
     12 };
     13 
     14 // Apply or remove an advisory lock on an open file. If block is true, the request will block while waiting
     15 // for the lock.
     16 export fn lock(fd: file, block: bool, op: lockop) (bool | error) = {
     17 	let flags = op: int;
     18 	if (!block) flags |= rt::LOCK_NB;
     19 	return platform_lock(fd, flags);
     20 };