@@ -8,13 +8,13 @@ import (
88 "golang.org/x/sys/unix"
99)
1010
11- func osGetSharedLock (file * os.File ) _ErrorCode {
11+ func osGetSharedLock (file * os.File ) error {
1212 return osFlock (file , unix .LOCK_SH | unix .LOCK_NB , _IOERR_RDLOCK )
1313}
1414
15- func osGetReservedLock (file * os.File ) _ErrorCode {
16- rc := osFlock (file , unix .LOCK_EX | unix .LOCK_NB , _IOERR_LOCK )
17- if rc == _BUSY {
15+ func osGetReservedLock (file * os.File ) error {
16+ err := osFlock (file , unix .LOCK_EX | unix .LOCK_NB , _IOERR_LOCK )
17+ if err == _BUSY {
1818 // The documentation states that a lock is upgraded by
1919 // releasing the previous lock, then acquiring the new lock.
2020 // Going over the source code of various BSDs, though,
@@ -26,64 +26,64 @@ func osGetReservedLock(file *os.File) _ErrorCode {
2626 // and invoke the busy handler if appropriate.
2727 return _BUSY_SNAPSHOT
2828 }
29- return rc
29+ return err
3030}
3131
32- func osGetExclusiveLock (file * os.File , state * LockLevel ) _ErrorCode {
32+ func osGetExclusiveLock (file * os.File , state * LockLevel ) error {
3333 if * state >= LOCK_RESERVED {
34- return _OK
34+ return nil
3535 }
3636 return osGetReservedLock (file )
3737}
3838
39- func osDowngradeLock (file * os.File , _ LockLevel ) _ErrorCode {
40- rc := osFlock (file , unix .LOCK_SH | unix .LOCK_NB , _IOERR_RDLOCK )
41- if rc == _BUSY {
39+ func osDowngradeLock (file * os.File , _ LockLevel ) error {
40+ err := osFlock (file , unix .LOCK_SH | unix .LOCK_NB , _IOERR_RDLOCK )
41+ if err == _BUSY {
4242 // The documentation states that a lock is downgraded by
4343 // releasing the previous lock then acquiring the new lock.
4444 // Going over the source code of various BSDs, though,
4545 // with LOCK_SH|LOCK_NB this should never happen.
4646 // Return IOERR_RDLOCK, as BUSY would cause an assert to fail.
4747 return _IOERR_RDLOCK
4848 }
49- return _OK
49+ return err
5050}
5151
52- func osReleaseLock (file * os.File , _ LockLevel ) _ErrorCode {
52+ func osReleaseLock (file * os.File , _ LockLevel ) error {
5353 for {
5454 err := unix .Flock (int (file .Fd ()), unix .LOCK_UN )
5555 if err == nil {
56- return _OK
56+ return nil
5757 }
5858 if err != unix .EINTR {
59- return _IOERR_UNLOCK
59+ return sysError { err , _IOERR_UNLOCK }
6060 }
6161 }
6262}
6363
64- func osCheckReservedLock (file * os.File ) (bool , _ErrorCode ) {
64+ func osCheckReservedLock (file * os.File ) (bool , error ) {
6565 // Test the RESERVED lock with fcntl(F_GETLK).
6666 // This only works on systems where fcntl and flock are compatible.
6767 // However, SQLite only calls this while holding a shared lock,
6868 // so the difference is immaterial.
69- lock , rc := osTestLock (file , _RESERVED_BYTE , 1 )
70- return lock == unix .F_WRLCK , rc
69+ lock , err := osTestLock (file , _RESERVED_BYTE , 1 , _IOERR_CHECKRESERVEDLOCK )
70+ return lock == unix .F_WRLCK , err
7171}
7272
73- func osFlock (file * os.File , how int , def _ErrorCode ) _ErrorCode {
73+ func osFlock (file * os.File , how int , def _ErrorCode ) error {
7474 err := unix .Flock (int (file .Fd ()), how )
7575 return osLockErrorCode (err , def )
7676}
7777
78- func osReadLock (file * os.File , start , len int64 ) _ErrorCode {
78+ func osReadLock (file * os.File , start , len int64 ) error {
7979 return osLock (file , unix .F_RDLCK , start , len , _IOERR_RDLOCK )
8080}
8181
82- func osWriteLock (file * os.File , start , len int64 ) _ErrorCode {
82+ func osWriteLock (file * os.File , start , len int64 ) error {
8383 return osLock (file , unix .F_WRLCK , start , len , _IOERR_LOCK )
8484}
8585
86- func osLock (file * os.File , typ int16 , start , len int64 , def _ErrorCode ) _ErrorCode {
86+ func osLock (file * os.File , typ int16 , start , len int64 , def _ErrorCode ) error {
8787 err := unix .FcntlFlock (file .Fd (), unix .F_SETLK , & unix.Flock_t {
8888 Type : typ ,
8989 Start : start ,
@@ -92,7 +92,7 @@ func osLock(file *os.File, typ int16, start, len int64, def _ErrorCode) _ErrorCo
9292 return osLockErrorCode (err , def )
9393}
9494
95- func osUnlock (file * os.File , start , len int64 ) _ErrorCode {
95+ func osUnlock (file * os.File , start , len int64 ) error {
9696 lock := unix.Flock_t {
9797 Type : unix .F_UNLCK ,
9898 Start : start ,
@@ -101,10 +101,10 @@ func osUnlock(file *os.File, start, len int64) _ErrorCode {
101101 for {
102102 err := unix .FcntlFlock (file .Fd (), unix .F_SETLK , & lock )
103103 if err == nil {
104- return _OK
104+ return nil
105105 }
106106 if err != unix .EINTR {
107- return _IOERR_UNLOCK
107+ return sysError { err , _IOERR_UNLOCK }
108108 }
109109 }
110110}
0 commit comments