mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
2fad7731c1
Summary: This diff introduces a `Priority` type for EdenFS. This type is used to pass along the priority of a request. The priority class itself contains two parts, `kind` and `offset`. `kind` uses the first 4-bytes and the reset 12-bytes are used to store offset. The idea is that we can roughly assign a priority kind to most of the requests and offset is used to dynamically tweak the priority of some particular requests. For example, when we saw a process is generate millions of requests we can use this to express "normal priority but less important than other process's normal priority". Reviewed By: chadaustin Differential Revision: D20287652 fbshipit-source-id: 9a849fb6cc6ba5e443fea978d5b4dc3ab8ca906a
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
enum class ImportPriorityKind : int16_t { Low = -1, Normal = 0, High };
|
|
|
|
struct ImportPriority {
|
|
ImportPriorityKind kind;
|
|
uint64_t offset : 48;
|
|
|
|
static const ImportPriority kNormal;
|
|
static const ImportPriority kHigh;
|
|
|
|
explicit constexpr ImportPriority()
|
|
: kind(ImportPriorityKind::Normal), offset(0) {}
|
|
explicit constexpr ImportPriority(ImportPriorityKind kind)
|
|
: kind(kind), offset(0) {}
|
|
constexpr ImportPriority(ImportPriorityKind kind, uint64_t offset)
|
|
: kind(kind), offset(offset) {}
|
|
|
|
constexpr inline int64_t value() const noexcept {
|
|
return (static_cast<int16_t>(kind) * (static_cast<uint64_t>(1) << 48)) +
|
|
offset;
|
|
}
|
|
|
|
friend bool operator<(
|
|
const ImportPriority& lhs,
|
|
const ImportPriority& rhs) noexcept {
|
|
return lhs.value() < rhs.value();
|
|
}
|
|
};
|
|
|
|
constexpr ImportPriority ImportPriority::kNormal{ImportPriorityKind::Normal};
|
|
constexpr ImportPriority ImportPriority::kHigh{ImportPriorityKind::High};
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|