aboutsummaryrefslogtreecommitdiff
path: root/locker_unix.go
diff options
context:
space:
mode:
author2026-02-05 14:35:00 +0300
committer2026-02-05 14:35:00 +0300
commit641a95063946bf7f4b8fdd1e938a917bc3f75cb2 (patch)
treed19a6b92845de37e66b57b305fbcaf9f4816ffe9 /locker_unix.go
downloadfqueue-641a95063946bf7f4b8fdd1e938a917bc3f75cb2.tar.gz
fqueue-641a95063946bf7f4b8fdd1e938a917bc3f75cb2.tar.bz2
fqueue-641a95063946bf7f4b8fdd1e938a917bc3f75cb2.tar.xz
fqueue-641a95063946bf7f4b8fdd1e938a917bc3f75cb2.zip
initialHEADmaster
Diffstat (limited to 'locker_unix.go')
-rw-r--r--locker_unix.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/locker_unix.go b/locker_unix.go
new file mode 100644
index 0000000..8d08751
--- /dev/null
+++ b/locker_unix.go
@@ -0,0 +1,30 @@
+//go:build !windows
+// +build !windows
+
+package fqueue
+
+import "golang.org/x/sys/unix"
+
+func lock(fd int, wait bool) error {
+ lock := unix.Flock_t{
+ Type: unix.F_WRLCK, // эксклюзивная блокировка записи
+ Whence: 0, // SEEK_SET
+ Start: 0,
+ Len: 0, // блокируем весь файл
+ }
+ cmd := unix.F_SETLK
+ if wait {
+ cmd = unix.F_SETLKW // блокирующий вызов
+ }
+ return unix.FcntlFlock(uintptr(fd), cmd, &lock)
+}
+
+func unlock(fd int) error {
+ lock := unix.Flock_t{
+ Type: unix.F_UNLCK,
+ Whence: 0,
+ Start: 0,
+ Len: 0,
+ }
+ return unix.FcntlFlock(uintptr(fd), unix.F_SETLK, &lock)
+}