Skip to content

Commit

Permalink
Revert "remove dispatch declarations; use CLinuxGCD"
Browse files Browse the repository at this point in the history
This reverts commit 919bc67.
  • Loading branch information
lhoward committed Nov 30, 2024
1 parent 919bc67 commit 03c9e84
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
9 changes: 0 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
"version" : "0.9.0"
}
},
{
"identity" : "clinuxgcd",
"kind" : "remoteSourceControl",
"location" : "https://github.com/PADL/CLinuxGCD.git",
"state" : {
"revision" : "75635d354c4ef14675803e2d6c5dd08026e7b61a",
"version" : "6.0.2"
}
},
{
"identity" : "ioringswift",
"kind" : "remoteSourceControl",
Expand Down
3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ let package = Package(
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/madmachineio/SwiftIO", from: "0.1.0"),
.package(url: "https://github.com/PADL/IORingSwift.git", from: "0.1.2"),
.package(url: "https://github.com/PADL/CLinuxGCD.git", from: "6.0.2"),
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"),
.package(url: "https://github.com/lhoward/AsyncExtensions", from: "0.9.0"),
.package(url: "https://github.com/apple/swift-system", from: "1.0.0"),
Expand All @@ -54,8 +53,6 @@ let package = Package(
name: "LinuxHalSwiftIO",
dependencies: [
.product(name: "CSwiftIO", package: "SwiftIO"),
.product(name: "CBlockHeaders", package: "CLinuxGCD"),
.product(name: "CDispatchHeaders", package: "CLinuxGCD")
],
linkerSettings: [
.linkedLibrary("gpiod", .when(platforms: [.linux])),
Expand Down
50 changes: 50 additions & 0 deletions Sources/LinuxHalSwiftIO/swift_hal_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

#pragma once

#include <inttypes.h>
#include <string.h>
#include <fcntl.h>

#include <sys/param.h>

#if __has_include(<Block.h>)
#include <Block.h>
#elif __has_include(<Block/Block.h>)
Expand All @@ -25,7 +31,51 @@ void *_Block_copy(const void *);
void _Block_release(const void *);
#endif

#if __has_include(<dispatch/dispatch.h>)
#include <dispatch/dispatch.h>
#else
// on Linux dispatch/dispatch.h is only available with unsafe Swift flags,
// which preclude the use of this package as a versioned dependency
struct dispatch_source_type_s {} __attribute__((aligned(sizeof(uintptr_t))));

typedef struct dispatch_source_s *dispatch_source_t;
typedef struct dispatch_queue_s *dispatch_queue_t;
typedef const struct dispatch_source_type_s *dispatch_source_type_t;

typedef void (^dispatch_block_t)(void);

extern const struct dispatch_source_type_s _dispatch_source_type_read;
extern const struct dispatch_source_type_s _dispatch_source_type_write;
extern const struct dispatch_source_type_s _dispatch_source_type_timer;

void dispatch_release(void *object);
void dispatch_resume(void *object);
void dispatch_suspend(void *object);

void *dispatch_get_context(void *object);
void dispatch_set_context(void *object, void *context);

void dispatch_source_cancel(void *object);
void dispatch_source_set_event_handler(dispatch_source_t source, dispatch_block_t handler);
void dispatch_source_set_cancel_handler(dispatch_source_t source, dispatch_block_t handler);

typedef uint64_t dispatch_time_t;

uintptr_t dispatch_source_get_handle(dispatch_source_t source);

dispatch_queue_t dispatch_get_global_queue(intptr_t identifier, uintptr_t flags);
dispatch_source_t dispatch_source_create(dispatch_source_type_t type, uintptr_t handle, uintptr_t mask, dispatch_queue_t queue);
void dispatch_source_set_timer(dispatch_source_t source, dispatch_time_t start, uint64_t interval, uint64_t leeway);
dispatch_time_t dispatch_time(dispatch_time_t when, int64_t delta);

#define dispatch_cancel dispatch_source_cancel
#define DISPATCH_QUEUE_PRIORITY_DEFAULT 0
#define DISPATCH_SOURCE_TYPE_READ (&_dispatch_source_type_read)
#define DISPATCH_SOURCE_TYPE_WRITE (&_dispatch_source_type_write)
#define DISPATCH_SOURCE_TYPE_TIMER (&_dispatch_source_type_timer)
#define DISPATCH_TIME_NOW (0ull)
#define DISPATCH_TIME_FOREVER (~0ull)
#endif

#include <syslog.h>

Expand Down

0 comments on commit 03c9e84

Please sign in to comment.