Android-cuttlefish cvd tool
instance_lock.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <optional>
19#include <string>
20
22
23namespace cuttlefish {
24
25// This class is not thread safe.
28
29 public:
30 unsigned Instance() const;
33
34 private:
35 InstanceLockFile(LockFile&& lock_file, unsigned instance_num);
37 const unsigned instance_num_;
38};
39
41 public:
42 InstanceLockFileManager(std::string instance_locks_path);
43
44 Result<InstanceLockFile> AcquireLock(unsigned instance_num);
46
47 // TODO: This routine should be removed and replaced with allocd
48 // The caller must check if the instance_num belongs to the user, before
49 // calling this. It is a quick fix for b/316824572
50 Result<void> RemoveLockFile(unsigned instance_num);
51
52 private:
53 Result<std::string> LockFilePath(unsigned instance_num);
55
58};
59
60} // namespace cuttlefish
Definition: instance_lock.h:40
Result< std::string > LockFilePath(unsigned instance_num)
Definition: instance_lock.cpp:53
Result< InstanceLockFile > AcquireUnusedLock()
Definition: instance_lock.cpp:68
InstanceLockFileManager(std::string instance_locks_path)
Definition: instance_lock.cpp:49
Result< void > RemoveLockFile(unsigned instance_num)
Definition: instance_lock.cpp:62
LockFileManager lock_file_manager_
Definition: instance_lock.h:57
std::string instance_locks_path_
Definition: instance_lock.h:56
Result< std::optional< InstanceLockFile > > TryAcquireLock(unsigned instance_num)
Definition: instance_lock.cpp:85
Result< InstanceLockFile > AcquireLock(unsigned instance_num)
Definition: instance_lock.cpp:77
Definition: instance_lock.h:26
LockFile lock_file_
Definition: instance_lock.h:36
InstanceLockFile(LockFile &&lock_file, unsigned instance_num)
Definition: instance_lock.cpp:33
unsigned Instance() const
Definition: instance_lock.cpp:37
const unsigned instance_num_
Definition: instance_lock.h:37
Result< InUseState > Status() const
Definition: instance_lock.cpp:39
Definition: lock_file.h:80
Definition: lock_file.h:36
Definition: alloc_driver.h:20
InUseState
Definition: lock_file.h:27
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30