Skip to content

Commit 1476fe5

Browse files
committed
Add a task scheduler for background indexing and preparation
The scheduler isn’t actually being used yet but it’s complex and generic enough that it’s possible to review it by itself.
1 parent 8046100 commit 1476fe5

File tree

9 files changed

+984
-0
lines changed

9 files changed

+984
-0
lines changed

Package.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ let package = Package(
4949
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
5050
),
5151

52+
// MARK: CAtomics
53+
.target(
54+
name: "CAtomics",
55+
dependencies: []
56+
),
57+
5258
// MARK: CSKTestSupport
5359
.target(
5460
name: "CSKTestSupport",
@@ -170,6 +176,7 @@ let package = Package(
170176
name: "SKCore",
171177
dependencies: [
172178
"BuildServerProtocol",
179+
"CAtomics",
173180
"LanguageServerProtocol",
174181
"LanguageServerProtocolJSONRPC",
175182
"LSPLogging",

Sources/CAtomics/CAtomics.c

Whitespace-only changes.

Sources/CAtomics/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_library(CAtomics INTERFACE)
2+
target_include_directories(CAtomics INTERFACE "include")

Sources/CAtomics/include/CAtomics.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===----------------------------------------------------------------------===//
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 SOURCEKITLSP_CATOMICS_H
14+
#define SOURCEKITLSP_CATOMICS_H
15+
16+
#include <stdbool.h>
17+
#include <stdint.h>
18+
#include <sys/types.h>
19+
20+
// MARK: - AtomicBool
21+
22+
typedef struct {
23+
_Atomic(bool) value;
24+
} AtomicBool;
25+
26+
__attribute__((swift_name("AtomicBool.init(initialValue:)")))
27+
static inline AtomicBool atomic_bool_create(bool initialValue) {
28+
AtomicBool atomic;
29+
atomic.value = initialValue;
30+
return atomic;
31+
}
32+
33+
__attribute__((swift_name("getter:AtomicBool.value(self:)")))
34+
static inline bool atomic_bool_get(AtomicBool *atomic) {
35+
return atomic->value;
36+
}
37+
38+
__attribute__((swift_name("setter:AtomicBool.value(self:_:)")))
39+
static inline void atomic_bool_set(AtomicBool *atomic, bool newValue) {
40+
atomic->value = newValue;
41+
}
42+
43+
// MARK: - AtomicUInt8
44+
45+
typedef struct {
46+
_Atomic(uint8_t) value;
47+
} AtomicUInt8;
48+
49+
__attribute__((swift_name("AtomicUInt8.init(initialValue:)")))
50+
static inline AtomicUInt8 atomic_uint8_create(uint8_t initialValue) {
51+
AtomicUInt8 atomic;
52+
atomic.value = initialValue;
53+
return atomic;
54+
}
55+
56+
__attribute__((swift_name("getter:AtomicUInt8.value(self:)")))
57+
static inline uint8_t atomic_uint8_get(AtomicUInt8 *atomic) {
58+
return atomic->value;
59+
}
60+
61+
__attribute__((swift_name("setter:AtomicUInt8.value(self:_:)")))
62+
static inline void atomic_uint8_set(AtomicUInt8 *atomic, uint8_t newValue) {
63+
atomic->value = newValue;
64+
}
65+
66+
#endif // SOURCEKITLSP_CATOMICS_H
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CAtomics {
2+
header "CAtomics.h"
3+
export *
4+
}

Sources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_subdirectory(BuildServerProtocol)
2+
add_subdirectory(CAtomics)
23
add_subdirectory(Csourcekitd)
34
add_subdirectory(Diagnose)
45
add_subdirectory(LanguageServerProtocol)

Sources/SKCore/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ add_library(SKCore STATIC
1313
MainFilesProvider.swift
1414
PathPrefixMapping.swift
1515
SplitShellCommand.swift
16+
TaskScheduler.swift
1617
Toolchain.swift
1718
ToolchainRegistry.swift
1819
XCToolchainPlist.swift)
1920
set_target_properties(SKCore PROPERTIES
2021
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
2122
target_link_libraries(SKCore PUBLIC
2223
BuildServerProtocol
24+
CAtomics
2325
LanguageServerProtocol
2426
LanguageServerProtocolJSONRPC
2527
LSPLogging

0 commit comments

Comments
 (0)