Skip to content

Commit

Permalink
Add a task scheduler for background indexing and preparation
Browse files Browse the repository at this point in the history
The scheduler isn’t actually being used yet but it’s complex and generic enough that it’s possible to review it by itself.
  • Loading branch information
ahoppen committed May 1, 2024
1 parent 8046100 commit 1476fe5
Show file tree
Hide file tree
Showing 9 changed files with 984 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ let package = Package(
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
),

// MARK: CAtomics
.target(
name: "CAtomics",
dependencies: []
),

// MARK: CSKTestSupport
.target(
name: "CSKTestSupport",
Expand Down Expand Up @@ -170,6 +176,7 @@ let package = Package(
name: "SKCore",
dependencies: [
"BuildServerProtocol",
"CAtomics",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"LSPLogging",
Expand Down
Empty file added Sources/CAtomics/CAtomics.c
Empty file.
2 changes: 2 additions & 0 deletions Sources/CAtomics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(CAtomics INTERFACE)
target_include_directories(CAtomics INTERFACE "include")
66 changes: 66 additions & 0 deletions Sources/CAtomics/include/CAtomics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SOURCEKITLSP_CATOMICS_H
#define SOURCEKITLSP_CATOMICS_H

#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>

// MARK: - AtomicBool

typedef struct {
_Atomic(bool) value;
} AtomicBool;

__attribute__((swift_name("AtomicBool.init(initialValue:)")))
static inline AtomicBool atomic_bool_create(bool initialValue) {
AtomicBool atomic;
atomic.value = initialValue;
return atomic;
}

__attribute__((swift_name("getter:AtomicBool.value(self:)")))
static inline bool atomic_bool_get(AtomicBool *atomic) {
return atomic->value;
}

__attribute__((swift_name("setter:AtomicBool.value(self:_:)")))
static inline void atomic_bool_set(AtomicBool *atomic, bool newValue) {
atomic->value = newValue;
}

// MARK: - AtomicUInt8

typedef struct {
_Atomic(uint8_t) value;
} AtomicUInt8;

__attribute__((swift_name("AtomicUInt8.init(initialValue:)")))
static inline AtomicUInt8 atomic_uint8_create(uint8_t initialValue) {
AtomicUInt8 atomic;
atomic.value = initialValue;
return atomic;
}

__attribute__((swift_name("getter:AtomicUInt8.value(self:)")))
static inline uint8_t atomic_uint8_get(AtomicUInt8 *atomic) {
return atomic->value;
}

__attribute__((swift_name("setter:AtomicUInt8.value(self:_:)")))
static inline void atomic_uint8_set(AtomicUInt8 *atomic, uint8_t newValue) {
atomic->value = newValue;
}

#endif // SOURCEKITLSP_CATOMICS_H
4 changes: 4 additions & 0 deletions Sources/CAtomics/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CAtomics {
header "CAtomics.h"
export *
}
1 change: 1 addition & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(BuildServerProtocol)
add_subdirectory(CAtomics)
add_subdirectory(Csourcekitd)
add_subdirectory(Diagnose)
add_subdirectory(LanguageServerProtocol)
Expand Down
2 changes: 2 additions & 0 deletions Sources/SKCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ add_library(SKCore STATIC
MainFilesProvider.swift
PathPrefixMapping.swift
SplitShellCommand.swift
TaskScheduler.swift
Toolchain.swift
ToolchainRegistry.swift
XCToolchainPlist.swift)
set_target_properties(SKCore PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_link_libraries(SKCore PUBLIC
BuildServerProtocol
CAtomics
LanguageServerProtocol
LanguageServerProtocolJSONRPC
LSPLogging
Expand Down
Loading

0 comments on commit 1476fe5

Please sign in to comment.