2
* Copyright (C) 2015 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Michi Henning <michi.henning@canonical.com>
33
class AdvisoryFileLock final
36
AdvisoryFileLock(std::string const& path);
37
AdvisoryFileLock(AdvisoryFileLock const&) = delete;
38
AdvisoryFileLock& operator=(AdvisoryFileLock const&) = delete;
39
AdvisoryFileLock(AdvisoryFileLock&&) = default;
40
AdvisoryFileLock& operator=(AdvisoryFileLock&&) = default;
43
static int const sleep_interval = 100;
45
// Returns true if lock can be acquired within msecs, false otherwise.
46
// Pass milliseconds::zero() to wait indefinitely.
47
// Throws if lock is already held by the calling process.
48
// Wait is implemented as a busy-wait loop, retrying every sleep_interval milliseconds.
49
bool lock(std::chrono::milliseconds msecs = std::chrono::milliseconds::zero());
51
// Throws if lock is not held by the calling process.
60
} // namespace internal
62
} // namespace thumbnailer
64
} // namespace service