MCPcopy Create free account
hub / github.com/WiseLibs/better-sqlite3 / SetLock

Method SetLock

src/util/fd-vfs.cpp:323–337  ·  view source on GitHub ↗

Acquires, upgrades, or releases an OS-level lock on the given byte range. Returns 0 on success, or -1 with errno set on failure.

Source from the content-addressed store, hash-verified

321 // Acquires, upgrades, or releases an OS-level lock on the given byte range.
322 // Returns 0 on success, or -1 with errno set on failure.
323 static int SetLock(Inode* inode, short type, off_t start, off_t len) {
324 // Only writable Files request write locks, and the lock descriptor
325 // is always writable when any writable File is open (see OpenMain).
326 assert(type != F_WRLCK || inode->lockFdWritable);
327 struct flock lock;
328 memset(&lock, 0, sizeof(lock));
329 lock.l_type = type;
330 lock.l_whence = SEEK_SET;
331 lock.l_start = start;
332 lock.l_len = len;
333 int rc;
334 do rc = fcntl(inode->lockFd, F_SETLK, &lock);
335 while (rc < 0 && errno == EINTR);
336 return rc;
337 }
338
339 static int LockError(int err, int fallback) {
340 switch (err) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected