Skip to content

Commit 40c38f9

Browse files
Using multiple insertion points to ensure all jobs are always inserted in O(1)
Fully separated unprocessed jobs and processed jobs Reverse jobs after updating status to minimise contention
1 parent 21a70e1 commit 40c38f9

File tree

13 files changed

+660
-971
lines changed

13 files changed

+660
-971
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,32 @@ inline int descendingPriorityOrder(JobPriority lhs,
25112511
return (lhs == rhs ? 0 : lhs > rhs ? -1 : 1);
25122512
}
25132513

2514+
enum { PriorityBucketCount = 5 };
2515+
2516+
inline int getPriorityBucketIndex(JobPriority priority) {
2517+
// Any unknown priorities will be rounded up to a known one.
2518+
// Priorities higher than UserInteractive are clamped to UserInteractive.
2519+
// Jobs of unknown priorities will end up in the same bucket as jobs of a
2520+
// corresponding known priority. Within the bucket they will be sorted in
2521+
// FIFO order.
2522+
if (priority > JobPriority::UserInitiated) {
2523+
// UserInteractive and higher
2524+
return 0;
2525+
} else if (priority > JobPriority::Default) {
2526+
// UserInitiated
2527+
return 1;
2528+
} else if (priority > JobPriority::Utility) {
2529+
// Default
2530+
return 2;
2531+
} else if (priority > JobPriority::Background) {
2532+
// Utility
2533+
return 3;
2534+
} else {
2535+
// Background and lower
2536+
return 4;
2537+
}
2538+
}
2539+
25142540
inline JobPriority withUserInteractivePriorityDowngrade(JobPriority priority) {
25152541
return (priority == JobPriority::UserInteractive) ? JobPriority::UserInitiated
25162542
: priority;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- HeaderFooterLayout.h -----------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_HEADER_FOOTER_LAYOUT_H
14+
#define SWIFT_BASIC_HEADER_FOOTER_LAYOUT_H
15+
16+
namespace swift {
17+
18+
template <class Header, class Footer, size_t TotalSize>
19+
struct HeaderFooterLayoutPadding {
20+
private:
21+
enum : ptrdiff_t {
22+
maxFooterOffset = TotalSize - (ptrdiff_t)sizeof(Footer),
23+
footerAlignment = (ptrdiff_t)alignof(Footer),
24+
footerOffset = maxFooterOffset - (maxFooterOffset % footerAlignment),
25+
size = footerOffset - (ptrdiff_t)sizeof(Header)
26+
};
27+
char padding[size];
28+
};
29+
30+
template <class Header, class Footer, size_t TotalSize>
31+
struct HeaderFooterLayout
32+
: Header,
33+
HeaderFooterLayoutPadding<Header, Footer, TotalSize>,
34+
Footer {};
35+
36+
} // namespace swift
37+
38+
#endif // SWIFT_BASIC_HEADER_FOOTER_LAYOUT_H
39+

0 commit comments

Comments
 (0)