MCPcopy Create free account
hub / github.com/bcndev/bytecoin / ExclusiveLock

Method ExclusiveLock

src/platform/ExclusiveLock.cpp:22–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21using namespace platform;
22ExclusiveLock::ExclusiveLock(const std::string &folder, const std::string &file) {
23 std::string full_path = folder + "/" + file;
24#if !TARGET_OS_IPHONE // We do not need lock on iOS because only 1 instance of app will be running
25#ifdef _WIN32
26 auto wfull_path = FileStream::utf8_to_utf16(expand_path(full_path));
27 handle = CreateFileW(wfull_path.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
28 if (handle == INVALID_HANDLE_VALUE)
29#else
30 fd = open(expand_path(full_path).c_str(), O_CREAT | O_WRONLY, 0600);
31 int status = lockf(fd, F_TLOCK, 4096);
32 if (status != 0)
33#endif
34 throw FailedToLock("ExclusiveLock fail at path=" + full_path);
35#endif
36}
37
38ExclusiveLock::~ExclusiveLock() {
39#if !TARGET_OS_IPHONE

Callers

nothing calls this directly

Calls 2

expand_pathFunction · 0.85
FailedToLockClass · 0.85

Tested by

no test coverage detected