File: filelock.h

package info (click to toggle)
libwibble 1.1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 1,040 kB
  • ctags: 2,721
  • sloc: cpp: 14,542; makefile: 196; perl: 87; sh: 26
file content (53 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (2)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef WIBBLE_SYS_FILELOCK_H
#define WIBBLE_SYS_FILELOCK_H

#include <wibble/sys/macros.h>

#ifdef POSIX

#include <fcntl.h>

namespace wibble {
namespace sys {
namespace fs {

/**
 * RAII fcntl advisory file lock
 *
 * See fcntl(2) for details.
 */
struct FileLock
{
    int fd;
    struct flock lock;

    /**
     * Create the lockfile with the given name.
     *
     * \a lock will be initialised with the parameters and used to unlock
     * in the destructor. Please feel free to change the contents of the \a
     * lock structure if you need a different part to be unlocked.
     *
     * @param write
     *   If false, use a read lock, else a write lock.
     */
    FileLock(int fd, short l_type, short l_whence=SEEK_SET, off_t l_start=0, off_t l_len=0);

	/**
	 * Unlocks using the values in \a lock
	 */
	~FileLock();

private:
	// Disallow copying
	FileLock(const FileLock&);
	FileLock& operator=(const FileLock&);
};

}
}
}

// vim:set ts=4 sw=4:
#endif
#endif