blob: 07393481e7d2715c56fb73a6608a6b713367f9d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/*-
* Copyright (c) 2014-2015 MongoDB, Inc.
* Copyright (c) 2008-2014 WiredTiger, Inc.
* All rights reserved.
*
* See the file LICENSE for redistribution information.
*/
#include "wt_internal.h"
/*
* __wt_bytelock --
* Lock/unlock a byte in a file.
*/
int
__wt_bytelock(WT_FH *fhp, wt_off_t byte, bool lock)
{
struct flock fl;
WT_DECL_RET;
/*
* WiredTiger requires this function be able to acquire locks past
* the end of file.
*
* Note we're using fcntl(2) locking: all fcntl locks associated with a
* file for a given process are removed when any file descriptor for the
* file is closed by the process, even if a lock was never requested for
* that file descriptor.
*/
fl.l_start = byte;
fl.l_len = 1;
fl.l_type = lock ? F_WRLCK : F_UNLCK;
fl.l_whence = SEEK_SET;
WT_SYSCALL_RETRY(fcntl(fhp->fd, F_SETLK, &fl), ret);
return (ret);
}
|