git: b9662312dff8 - main - devel/libdispatch: bring back Grand Central Dispatch API support library (+)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 08 Nov 2022 09:44:13 UTC
The branch main has been updated by fluffy: URL: https://cgit.FreeBSD.org/ports/commit/?id=b9662312dff8f05fb241525a2fda6adc33183dbb commit b9662312dff8f05fb241525a2fda6adc33183dbb Author: Dima Panov <fluffy@FreeBSD.org> AuthorDate: 2022-11-08 09:43:02 +0000 Commit: Dima Panov <fluffy@FreeBSD.org> CommitDate: 2022-11-08 09:43:02 +0000 devel/libdispatch: bring back Grand Central Dispatch API support library (+) --- MOVED | 1 - devel/Makefile | 1 + devel/libdispatch/Makefile | 18 ++ devel/libdispatch/distinfo | 3 + ...ch-cmake_modules_DispatchCompilerWarnings.cmake | 10 + .../files/patch-cmake_modules_SwiftSupport.cmake | 11 + devel/libdispatch/files/patch-private_private.h | 20 ++ devel/libdispatch/files/patch-src_CMakeLists.txt | 11 + devel/libdispatch/files/patch-src_event_event.c | 23 ++ .../files/patch-src_event_event__internal.h | 11 + .../files/patch-src_event_event__kevent.c | 259 +++++++++++++++++++++ .../libdispatch/files/patch-src_event_workqueue.c | 55 +++++ devel/libdispatch/files/patch-src_init.c | 38 +++ devel/libdispatch/files/patch-src_internal.h | 15 ++ devel/libdispatch/files/patch-src_io.c | 20 ++ devel/libdispatch/files/patch-src_queue.c | 106 +++++++++ devel/libdispatch/files/patch-src_shims_lock.c | 119 ++++++++++ devel/libdispatch/files/patch-src_shims_lock.h | 45 ++++ devel/libdispatch/files/patch-src_source.c | 16 ++ .../libdispatch/files/patch-src_swift_Source.swift | 47 ++++ .../files/patch-src_swift_Wrapper.swift | 29 +++ devel/libdispatch/files/patch-tests_CMakeLists.txt | 15 ++ .../libdispatch/files/patch-tests_bsdtestharness.c | 32 +++ .../files/patch-tests_dispatch__workqueue.c | 75 ++++++ devel/libdispatch/pkg-descr | 2 + devel/libdispatch/pkg-plist | 35 +++ 26 files changed, 1016 insertions(+), 1 deletion(-) diff --git a/MOVED b/MOVED index f3234a259f21..66f1c34b2a66 100644 --- a/MOVED +++ b/MOVED @@ -14507,7 +14507,6 @@ devel/hs-bytestring-nums||2020-05-05|Has expired: No releases since 2012 devel/iz||2020-05-05|Has expired: Broken for more than 6 months devel/jfrog-cli||2020-05-05|Has expired: Broken for more than 6 months devel/libcfg||2020-05-05|Has expired: Broken for more than 6 months -devel/libdispatch||2020-05-05|Has expired: Broken for more than 6 months devel/libjson++||2020-05-05|Has expired: Broken for more than 6 months devel/libmonetra||2020-05-05|Has expired: Broken for more than 6 months devel/libol||2020-05-05|Has expired: Broken for more than 6 months diff --git a/devel/Makefile b/devel/Makefile index 4d384a47567a..693da10dc79d 100644 --- a/devel/Makefile +++ b/devel/Makefile @@ -1149,6 +1149,7 @@ SUBDIR += libdatrie SUBDIR += libdbusmenu SUBDIR += libdbusmenu-qt + SUBDIR += libdispatch SUBDIR += libddoc SUBDIR += libdevq SUBDIR += libdfui diff --git a/devel/libdispatch/Makefile b/devel/libdispatch/Makefile new file mode 100644 index 000000000000..5a55af337245 --- /dev/null +++ b/devel/libdispatch/Makefile @@ -0,0 +1,18 @@ +PORTNAME= libdispatch +DISTVERSION= 5.5 +CATEGORIES= devel + +MAINTAINER= fluffy@FreeBSD.org +COMMENT= Grand Central Dispatch API support library + +LICENSE= APACHE20 + +USES= cmake compiler:c++17-lang +USE_LDCONFIG= yes + +USE_GITHUB= yes +GH_ACCOUNT= apple +GH_PROJECT= swift-corelibs-libdispatch +GH_TAGNAME= swift-${DISTVERSION}-RELEASE + +.include <bsd.port.mk> diff --git a/devel/libdispatch/distinfo b/devel/libdispatch/distinfo new file mode 100644 index 000000000000..addabed1af96 --- /dev/null +++ b/devel/libdispatch/distinfo @@ -0,0 +1,3 @@ +TIMESTAMP = 1667817651 +SHA256 (apple-swift-corelibs-libdispatch-5.5-swift-5.5-RELEASE_GH0.tar.gz) = 5efdfa1d2897c598acea42fc00776477bb3713645686774f5ff0818b26649e62 +SIZE (apple-swift-corelibs-libdispatch-5.5-swift-5.5-RELEASE_GH0.tar.gz) = 592054 diff --git a/devel/libdispatch/files/patch-cmake_modules_DispatchCompilerWarnings.cmake b/devel/libdispatch/files/patch-cmake_modules_DispatchCompilerWarnings.cmake new file mode 100644 index 000000000000..bc8ec4df8ca5 --- /dev/null +++ b/devel/libdispatch/files/patch-cmake_modules_DispatchCompilerWarnings.cmake @@ -0,0 +1,10 @@ +--- cmake/modules/DispatchCompilerWarnings.cmake.orig 2021-09-17 04:54:52 UTC ++++ cmake/modules/DispatchCompilerWarnings.cmake +@@ -2,7 +2,6 @@ else() + if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") + # TODO: someone needs to provide the msvc equivalent warning flags + else() +- add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Werror>) + add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wall>) + add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wextra>) + diff --git a/devel/libdispatch/files/patch-cmake_modules_SwiftSupport.cmake b/devel/libdispatch/files/patch-cmake_modules_SwiftSupport.cmake new file mode 100644 index 000000000000..9f7eb35422c1 --- /dev/null +++ b/devel/libdispatch/files/patch-cmake_modules_SwiftSupport.cmake @@ -0,0 +1,11 @@ +--- cmake/modules/SwiftSupport.cmake.orig 2021-09-17 04:54:52 UTC ++++ cmake/modules/SwiftSupport.cmake +@@ -23,6 +23,8 @@ function(get_swift_host_arch result_var_name) + set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") + set("${result_var_name}" "armv7" PARENT_SCOPE) ++ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64") ++ set("${result_var_name}" "amd64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") + set("${result_var_name}" "x86_64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64") diff --git a/devel/libdispatch/files/patch-private_private.h b/devel/libdispatch/files/patch-private_private.h new file mode 100644 index 000000000000..64fb8e2c3bfd --- /dev/null +++ b/devel/libdispatch/files/patch-private_private.h @@ -0,0 +1,20 @@ +--- private/private.h.orig 2021-09-17 04:54:52 UTC ++++ private/private.h +@@ -177,7 +177,7 @@ void _dispatch_prohibit_transition_to_multithreaded(bo + + #if TARGET_OS_MAC + #define DISPATCH_COCOA_COMPAT 1 +-#elif defined(__linux__) || defined(__FreeBSD__) || defined(_WIN32) ++#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(_WIN32) + #define DISPATCH_COCOA_COMPAT 1 + #else + #define DISPATCH_COCOA_COMPAT 0 +@@ -191,6 +191,8 @@ typedef int dispatch_runloop_handle_t; + typedef mach_port_t dispatch_runloop_handle_t; + #elif defined(__linux__) || defined(__FreeBSD__) + typedef int dispatch_runloop_handle_t; ++#elif defined(__unix__) ++typedef uint64_t dispatch_runloop_handle_t; + #elif defined(_WIN32) + typedef void *dispatch_runloop_handle_t; + #else diff --git a/devel/libdispatch/files/patch-src_CMakeLists.txt b/devel/libdispatch/files/patch-src_CMakeLists.txt new file mode 100644 index 000000000000..ee85289310eb --- /dev/null +++ b/devel/libdispatch/files/patch-src_CMakeLists.txt @@ -0,0 +1,11 @@ +--- src/CMakeLists.txt.orig 2021-09-17 04:54:52 UTC ++++ src/CMakeLists.txt +@@ -127,7 +127,7 @@ target_compile_options(dispatch PRIVATE -fblocks) + # FIXME(compnerd) add check for -fblocks? + target_compile_options(dispatch PRIVATE -fblocks) + +-check_c_compiler_flag("-momit-leaf-frame-pointer -Werror -Wall -O3" C_SUPPORTS_OMIT_LEAF_FRAME_POINTER) ++check_c_compiler_flag("-momit-leaf-frame-pointer -Wall" C_SUPPORTS_OMIT_LEAF_FRAME_POINTER) + if (C_SUPPORTS_OMIT_LEAF_FRAME_POINTER) + target_compile_options(dispatch PRIVATE -momit-leaf-frame-pointer) + endif() diff --git a/devel/libdispatch/files/patch-src_event_event.c b/devel/libdispatch/files/patch-src_event_event.c new file mode 100644 index 000000000000..873c9243e688 --- /dev/null +++ b/devel/libdispatch/files/patch-src_event_event.c @@ -0,0 +1,23 @@ +--- src/event/event.c.orig 2021-09-17 04:54:52 UTC ++++ src/event/event.c +@@ -766,9 +766,9 @@ _dispatch_timer_heap_update(dispatch_timer_heap_t dth, + #pragma mark timer unote + + #define _dispatch_timer_du_debug(what, du) \ +- _dispatch_debug("kevent-source[%p]: %s kevent[%p] { ident = 0x%x }", \ ++ _dispatch_debug("kevent-source[%p]: %s kevent[%p] { ident = 0x%llx }", \ + _dispatch_wref2ptr((du)->du_owner_wref), what, \ +- (du), (du)->du_ident) ++ (du), (unsigned long long)(du)->du_ident) + + DISPATCH_ALWAYS_INLINE + static inline unsigned int +@@ -792,7 +792,7 @@ _dispatch_timer_unote_disarm(dispatch_timer_source_ref + _dispatch_timer_unote_disarm(dispatch_timer_source_refs_t dt, + dispatch_timer_heap_t dth) + { +- uint32_t tidx = dt->du_ident; ++ uint32_t tidx = (uint32_t)dt->du_ident; + + dispatch_assert(_dispatch_unote_armed(dt)); + _dispatch_timer_heap_remove(&dth[tidx], dt); diff --git a/devel/libdispatch/files/patch-src_event_event__internal.h b/devel/libdispatch/files/patch-src_event_event__internal.h new file mode 100644 index 000000000000..a26dd6e77ce8 --- /dev/null +++ b/devel/libdispatch/files/patch-src_event_event__internal.h @@ -0,0 +1,11 @@ +--- src/event/event_internal.h.orig 2021-09-17 04:54:52 UTC ++++ src/event/event_internal.h +@@ -125,6 +125,8 @@ typedef uintptr_t dispatch_unote_ident_t; + + #if defined(_WIN32) + typedef uintptr_t dispatch_unote_ident_t; ++#elif defined(__FreeBSD__) ++typedef uintptr_t dispatch_unote_ident_t; + #else + typedef uint32_t dispatch_unote_ident_t; + #endif diff --git a/devel/libdispatch/files/patch-src_event_event__kevent.c b/devel/libdispatch/files/patch-src_event_event__kevent.c new file mode 100644 index 000000000000..6a56878e962d --- /dev/null +++ b/devel/libdispatch/files/patch-src_event_event__kevent.c @@ -0,0 +1,259 @@ +--- src/event/event_kevent.c.orig 2021-09-17 04:54:52 UTC ++++ src/event/event_kevent.c +@@ -101,8 +101,12 @@ _evfiltstr(short filt) + _evfilt2(EVFILT_MACHPORT); + _evfilt2(DISPATCH_EVFILT_MACH_NOTIFICATION); + #endif ++#ifdef EVFILT_FS + _evfilt2(EVFILT_FS); ++#endif ++#ifdef EVFILT_USER + _evfilt2(EVFILT_USER); ++#endif + #ifdef EVFILT_SOCK + _evfilt2(EVFILT_SOCK); + #endif +@@ -236,9 +240,9 @@ dispatch_kevent_debug(const char *verb, const dispatch + + #define _dispatch_du_debug(what, du) \ + _dispatch_debug("kevent-source[%p]: %s kevent[%p] " \ +- "{ filter = %s, ident = 0x%x }", \ ++ "{ filter = %s, ident = 0x%llx }", \ + _dispatch_wref2ptr((du)->du_owner_wref), what, \ +- (du), _evfiltstr((du)->du_filter), (du)->du_ident) ++ (du), _evfiltstr((du)->du_filter), (unsigned long long)(du)->du_ident) + + #if DISPATCH_MACHPORT_DEBUG + #ifndef MACH_PORT_TYPE_SPREQUEST +@@ -388,8 +392,10 @@ _dispatch_kevent_print_error(dispatch_kevent_t ke) + switch (ke->data) { + case 0: + return; ++#if DISPATCH_USE_KEVENT_QOS + case ERANGE: /* A broken QoS was passed to kevent_id() */ + DISPATCH_INTERNAL_CRASH(ke->qos, "Invalid kevent priority"); ++#endif + default: + // log the unexpected error + _dispatch_bug_kevent_client("kevent", _evfiltstr(ke->filter), +@@ -397,7 +403,7 @@ _dispatch_kevent_print_error(dispatch_kevent_t ke) + ke->flags & EV_DELETE ? "delete" : + ke->flags & EV_ADD ? "add" : + ke->flags & EV_ENABLE ? "enable" : "monitor", +- (int)ke->data, ke->ident, ke->udata, du); ++ (int)ke->data, ke->ident, (uint64_t)ke->udata, du); + } + } + +@@ -528,11 +534,17 @@ _dispatch_kevent_merge_muxed(dispatch_kevent_t ke) + } + } + ++#define DISPATCH_KEVENT_ERSATZ_EVFILT_USER_MASK 0xfffffe00 ++ + DISPATCH_NOINLINE + static void + _dispatch_kevent_drain(dispatch_kevent_t ke) + { ++#ifdef EVFILT_USER + if (ke->filter == EVFILT_USER) { ++#else ++ if (ke->filter == EVFILT_TIMER && ke->ident == DISPATCH_KEVENT_ERSATZ_EVFILT_USER_MASK) { ++#endif + _dispatch_kevent_mgr_debug("received", ke); + return; + } +@@ -579,10 +591,17 @@ _dispatch_kq_create(intptr_t *fd_ptr) + _dispatch_kq_create(intptr_t *fd_ptr) + { + static const dispatch_kevent_s kev = { ++#ifdef EVFILT_USER + .ident = 1, + .filter = EVFILT_USER, + .flags = EV_ADD|EV_CLEAR, + .udata = (dispatch_kevent_udata_t)DISPATCH_WLH_MANAGER, ++#else ++ .ident = DISPATCH_KEVENT_ERSATZ_EVFILT_USER_MASK, ++ .filter = EVFILT_TIMER, ++ .flags = EV_ADD|EV_DISABLE, ++ .data = 1, ++#endif + }; + int kqfd; + +@@ -591,7 +610,6 @@ _dispatch_kq_create(intptr_t *fd_ptr) + guardid_t guard = (uintptr_t)fd_ptr; + kqfd = guarded_kqueue_np(&guard, GUARD_CLOSE | GUARD_DUP); + #else +- (void)guard_ptr; + kqfd = kqueue(); + #endif + if (kqfd == -1) { +@@ -727,6 +745,10 @@ retry: + (void)avail; + const struct timespec timeout_immediately = {}, *timeout = NULL; + if (flags & KEVENT_FLAG_IMMEDIATE) timeout = &timeout_immediately; ++#ifdef EVFILT_USER ++ const struct timespec timeout_1ms = {.tv_sec = 0, .tv_nsec = 1000000}; ++ if (ke->ident == DISPATCH_KEVENT_ERSATZ_EVFILT_USER_MASK) timeout = &timeout_1ms; ++#endif + r = kevent(kqfd, ke, n, ke_out, n_out, timeout); + #endif + #if DISPATCH_USE_KEVENT_WORKLOOP +@@ -743,7 +765,7 @@ retry: + switch (err) { + case ENOMEM: + _dispatch_temporary_resource_shortage(); +- /* FALLTHROUGH */ ++ DISPATCH_FALLTHROUGH; + case EINTR: + goto retry; + case EBADF: +@@ -754,7 +776,7 @@ retry: + (flags & KEVENT_FLAG_DYNAMIC_KQ_MUST_EXIST)) { + return 0; + } +- /* FALLTHROUGH */ ++ DISPATCH_FALLTHROUGH; + #endif // DISPATCH_USE_KEVENT_WORKLOOP + default: + DISPATCH_CLIENT_CRASH(err, "Unexpected error from kevent"); +@@ -786,9 +808,15 @@ _dispatch_kq_drain(dispatch_wlh_t wlh, dispatch_kevent + + #if DISPATCH_DEBUG + for (r = 0; r < n; r++) { ++#ifdef EVFILT_USER + if (ke[r].filter != EVFILT_USER || DISPATCH_MGR_QUEUE_DEBUG) { + _dispatch_kevent_debug_n(NULL, ke + r, r, n); + } ++#else ++ if (DISPATCH_MGR_QUEUE_DEBUG) { ++ _dispatch_kevent_debug_n(NULL, ke + r, r, n); ++ } ++#endif + } + #endif + +@@ -860,7 +888,6 @@ _dispatch_kq_unote_set_kevent(dispatch_unote_t _du, di + du->du_priority), + #endif + }; +- (void)pp; // if DISPATCH_USE_KEVENT_QOS == 0 + } + + DISPATCH_ALWAYS_INLINE +@@ -921,9 +948,13 @@ _dispatch_kq_deferred_update(dispatch_wlh_t wlh, dispa + ke->udata); + dispatch_kevent_t dk = _dispatch_kq_deferred_reuse_slot(wlh, ddi, slot); + *dk = *ke; ++#ifdef EVFILT_USER + if (ke->filter != EVFILT_USER) { + _dispatch_kevent_mgr_debug("deferred", ke); + } ++#else ++ _dispatch_kevent_mgr_debug("deferred", ke); ++#endif + } else { + _dispatch_kq_update_one(wlh, ke); + } +@@ -985,6 +1016,7 @@ _dispatch_sync_ipc_handoff_end(dispatch_wlh_t wlh, mac + } + #endif + ++#if DISPATCH_HAVE_DIRECT_KNOTES + DISPATCH_NOINLINE + static bool + _dispatch_kq_unote_update(dispatch_wlh_t wlh, dispatch_unote_t _du, +@@ -1055,6 +1087,7 @@ done: + dispatch_assume_zero(r); + return true; + } ++#endif + + #pragma mark dispatch_muxnote_t + +@@ -1283,6 +1316,7 @@ _dispatch_unote_unregister_direct(dispatch_unote_t du, + #pragma mark - + #pragma mark dispatch_event_loop + ++#if DISPATCH_USE_KEVENT_WORKLOOP + enum { + DISPATCH_WORKLOOP_ASYNC, + DISPATCH_WORKLOOP_ASYNC_FROM_SYNC, +@@ -1316,6 +1350,7 @@ static char const * const _dispatch_workloop_actions[] + [DISPATCH_WORKLOOP_SYNC_WAKE] = "sync-wake", + [DISPATCH_WORKLOOP_SYNC_END] = "sync-end", + }; ++#endif + + void + _dispatch_event_loop_atfork_child(void) +@@ -1410,7 +1445,7 @@ _dispatch_kq_fill_workloop_event(dispatch_kevent_t ke, + switch (which) { + case DISPATCH_WORKLOOP_ASYNC_FROM_SYNC: + fflags |= NOTE_WL_END_OWNERSHIP; +- /* FALLTHROUGH */ ++ DISPATCH_FALLTHROUGH; + case DISPATCH_WORKLOOP_ASYNC: + case DISPATCH_WORKLOOP_ASYNC_DISCOVER_SYNC: + case DISPATCH_WORKLOOP_ASYNC_QOS_UPDATE: +@@ -1434,10 +1469,10 @@ _dispatch_kq_fill_workloop_event(dispatch_kevent_t ke, + + case DISPATCH_WORKLOOP_ASYNC_LEAVE_FROM_SYNC: + fflags |= NOTE_WL_END_OWNERSHIP; +- /* FALLTHROUGH */ ++ DISPATCH_FALLTHROUGH; + case DISPATCH_WORKLOOP_ASYNC_LEAVE_FROM_TRANSFER: + fflags |= NOTE_WL_IGNORE_ESTALE; +- /* FALLTHROUGH */ ++ DISPATCH_FALLTHROUGH; + case DISPATCH_WORKLOOP_ASYNC_LEAVE: + dispatch_assert(!_dq_state_is_enqueued_on_target(dq_state)); + action = EV_ADD | EV_DELETE | EV_ENABLE; +@@ -1881,10 +1916,17 @@ _dispatch_event_loop_poke(dispatch_wlh_t wlh, uint64_t + { + if (wlh == DISPATCH_WLH_MANAGER) { + dispatch_kevent_s ke = (dispatch_kevent_s){ ++#ifdef EVFILT_USER + .ident = 1, + .filter = EVFILT_USER, + .fflags = NOTE_TRIGGER, + .udata = (dispatch_kevent_udata_t)DISPATCH_WLH_MANAGER, ++#else ++ .ident = DISPATCH_KEVENT_ERSATZ_EVFILT_USER_MASK, ++ .filter = EVFILT_TIMER, ++ .flags = EV_ADD|EV_ENABLE, ++ .data = 1 ++#endif + }; + return _dispatch_kq_deferred_update(DISPATCH_WLH_ANON, &ke); + } else if (wlh && wlh != DISPATCH_WLH_ANON) { +@@ -2357,6 +2399,12 @@ _dispatch_event_loop_timer_arm(dispatch_timer_heap_t d + target += range.leeway; + range.leeway = 0; + } ++#if !NOTE_ABSOLUTE ++ target = range.delay; ++#if defined(__FreeBSD__) ++ target /= 1000000; ++#endif ++#endif + + _dispatch_event_loop_timer_program(dth, tidx, target, range.leeway, + EV_ADD | EV_ENABLE); +@@ -2445,6 +2493,7 @@ const dispatch_source_type_s _dispatch_source_type_vno + .dst_merge_evt = _dispatch_source_merge_evt, + }; + ++#ifdef EVFILT_FS + const dispatch_source_type_s _dispatch_source_type_vfs = { + .dst_kind = "vfs", + .dst_filter = EVFILT_FS, +@@ -2477,6 +2526,7 @@ const dispatch_source_type_s _dispatch_source_type_vfs + .dst_create = _dispatch_unote_create_without_handle, + .dst_merge_evt = _dispatch_source_merge_evt, + }; ++#endif + + #ifdef EVFILT_SOCK + const dispatch_source_type_s _dispatch_source_type_sock = { diff --git a/devel/libdispatch/files/patch-src_event_workqueue.c b/devel/libdispatch/files/patch-src_event_workqueue.c new file mode 100644 index 000000000000..151e807f356e --- /dev/null +++ b/devel/libdispatch/files/patch-src_event_workqueue.c @@ -0,0 +1,55 @@ +--- src/event/workqueue.c.orig 2021-09-17 04:54:52 UTC ++++ src/event/workqueue.c +@@ -180,6 +180,52 @@ _dispatch_workq_count_runnable_workers(dispatch_workq_ + + _dispatch_unfair_lock_unlock(&mon->registered_tid_lock); + } ++#elif defined(__FreeBSD__) ++#include <sys/param.h> ++#include <sys/sysctl.h> ++#include <sys/proc.h> ++ ++static void ++_dispatch_workq_count_runnable_workers(dispatch_workq_monitor_t mon) ++{ ++ struct kinfo_proc kp[WORKQ_MAX_TRACKED_TIDS] = {0}; ++ size_t size, len; ++ int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)getpid(), (int)sizeof(struct kinfo_proc), 0}; ++ if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) { ++ _dispatch_debug("workq: Failed to sysctl1"); ++ return; ++ } ++ ++ size = size > sizeof(kp)? sizeof(kp): size; ++ len = size / sizeof(struct kinfo_proc); ++ mib[5] = (int)len; ++ if (sysctl(mib, 6, kp, &size, NULL, 0) < 0) { ++ _dispatch_debug("workq: Failed to sysctl2"); ++ return; ++ } ++ ++ int running_count = 0; ++ ++ _dispatch_unfair_lock_lock(&mon->registered_tid_lock); ++ ++ for (int i = 0; i < mon->num_registered_tids; i++) { ++ dispatch_tid tid = mon->registered_tids[i]; ++ for (size_t j = 0; j < len; j++) { ++ if ((dispatch_tid)kp[j].p_tid != tid) { ++ continue; ++ } ++ ++ if (kp[j].p_stat == SRUN || kp[j].p_stat == SIDL || kp[j].p_stat == SONPROC) { ++ running_count++; ++ break; ++ } ++ } ++ } ++ ++ mon->num_runnable = running_count; ++ ++ _dispatch_unfair_lock_unlock(&mon->registered_tid_lock); ++} + #else + #error must define _dispatch_workq_count_runnable_workers + #endif diff --git a/devel/libdispatch/files/patch-src_init.c b/devel/libdispatch/files/patch-src_init.c new file mode 100644 index 000000000000..33af1ade1a36 --- /dev/null +++ b/devel/libdispatch/files/patch-src_init.c @@ -0,0 +1,38 @@ +--- src/init.c.orig 2021-09-17 04:54:52 UTC ++++ src/init.c +@@ -961,7 +961,6 @@ _dispatch_continuation_get_function_symbol(dispatch_co + return dc->dc_func; + } + +-#if HAVE_MACH + void + _dispatch_bug_kevent_client(const char *msg, const char *filter, + const char *operation, int err, uint64_t ident, uint64_t udata, +@@ -1005,7 +1004,6 @@ _dispatch_bug_kevent_client(const char *msg, const cha + msg, strerror(err), err, udata, filter, ident, ident, func); + } + } +-#endif // HAVE_MACH + + #if RDAR_49023449 + +@@ -1048,7 +1046,7 @@ _dispatch_bug_kevent_vanished(dispatch_unote_t du) + "{ %p[%s], ident: %" PRIdPTR " / 0x%" PRIxPTR ", handler: %p }", + dux_type(du._du)->dst_kind, dou._dq, + dou._dq->dq_label ? dou._dq->dq_label : "<unknown>", +- du._du->du_ident, du._du->du_ident, func); ++ (intptr_t)du._du->du_ident, (uintptr_t)du._du->du_ident, func); + } + + #endif // RDAR_49023449 +@@ -1153,8 +1151,8 @@ _dispatch_logv_init(void *context DISPATCH_UNUSED) + } + #else + dprintf(dispatch_logfile, "=== log file opened for %s[%u] at " +- "%ld.%06u ===\n", getprogname() ?: "", getpid(), +- tv.tv_sec, (int)tv.tv_usec); ++ "%lld.%06u ===\n", getprogname() ?: "", getpid(), ++ (time_t)tv.tv_sec, (int)tv.tv_usec); + #endif + } + } diff --git a/devel/libdispatch/files/patch-src_internal.h b/devel/libdispatch/files/patch-src_internal.h new file mode 100644 index 000000000000..f36de567dc00 --- /dev/null +++ b/devel/libdispatch/files/patch-src_internal.h @@ -0,0 +1,15 @@ +--- src/internal.h.orig 2021-09-17 04:54:52 UTC ++++ src/internal.h +@@ -475,12 +475,10 @@ struct dispatch_unote_class_s; + + struct dispatch_unote_class_s; + +-#if HAVE_MACH + DISPATCH_NOINLINE DISPATCH_COLD + void _dispatch_bug_kevent_client(const char *msg, const char *filter, + const char *operation, int err, uint64_t ident, uint64_t udata, + struct dispatch_unote_class_s *du); +-#endif // HAVE_MACH + + DISPATCH_NOINLINE DISPATCH_COLD + void _dispatch_bug_kevent_vanished(struct dispatch_unote_class_s *du); diff --git a/devel/libdispatch/files/patch-src_io.c b/devel/libdispatch/files/patch-src_io.c new file mode 100644 index 000000000000..519919464bc8 --- /dev/null +++ b/devel/libdispatch/files/patch-src_io.c @@ -0,0 +1,20 @@ +--- src/io.c.orig 2021-09-17 04:54:52 UTC ++++ src/io.c +@@ -22,7 +22,7 @@ + + #if defined(__FreeBSD__) + #include <fcntl.h> +-#define F_RDADVISE F_RDAHEAD ++//#define F_RDADVISE F_RDAHEAD + #endif + + #ifndef DISPATCH_IO_DEBUG +@@ -2308,7 +2308,7 @@ _dispatch_operation_advise(dispatch_operation_t op, si + default: (void)dispatch_assume_zero(err); break; + } + #else +-#error "_dispatch_operation_advise not implemented on this platform" ++ (void)err; + #endif // defined(F_RDADVISE) + #endif // defined(_WIN32) + } diff --git a/devel/libdispatch/files/patch-src_queue.c b/devel/libdispatch/files/patch-src_queue.c new file mode 100644 index 000000000000..e1464314faaf --- /dev/null +++ b/devel/libdispatch/files/patch-src_queue.c @@ -0,0 +1,106 @@ +--- src/queue.c.orig 2021-09-17 04:54:52 UTC ++++ src/queue.c +@@ -6469,6 +6469,8 @@ _dispatch_runloop_handle_is_valid(dispatch_runloop_han + return MACH_PORT_VALID(handle); + #elif defined(__linux__) + return handle >= 0; ++#elif defined(__unix__) ++ return handle >= 0; + #elif defined(_WIN32) + return handle != NULL; + #else +@@ -6485,6 +6487,8 @@ _dispatch_runloop_queue_get_handle(dispatch_lane_t dq) + #elif defined(__linux__) + // decode: 0 is a valid fd, so offset by 1 to distinguish from NULL + return ((dispatch_runloop_handle_t)(uintptr_t)dq->do_ctxt) - 1; ++#elif defined(__unix__) ++ return ((dispatch_runloop_handle_t)(uintptr_t)dq->do_ctxt); + #elif defined(_WIN32) + return ((dispatch_runloop_handle_t)(uintptr_t)dq->do_ctxt); + #else +@@ -6502,6 +6506,8 @@ _dispatch_runloop_queue_set_handle(dispatch_lane_t dq, + #elif defined(__linux__) + // encode: 0 is a valid fd, so offset by 1 to distinguish from NULL + dq->do_ctxt = (void *)(uintptr_t)(handle + 1); ++#elif defined(__unix__) ++ dq->do_ctxt = (void *)(uintptr_t)handle; + #elif defined(_WIN32) + dq->do_ctxt = (void *)(uintptr_t)handle; + #else +@@ -6509,6 +6515,12 @@ _dispatch_runloop_queue_set_handle(dispatch_lane_t dq, + #endif + } + ++#if defined(__unix__) ++#define DISPATCH_RUNLOOP_HANDLE_PACK(rfd, wfd) (((uint64_t)(rfd) << 32) | (wfd)) ++#define DISPATCH_RUNLOOP_HANDLE_RFD(h) ((int)((h) >> 32)) ++#define DISPATCH_RUNLOOP_HANDLE_WFD(h) ((int)((h) & 0xffffffff)) ++#endif ++ + static void + _dispatch_runloop_queue_handle_init(void *ctxt) + { +@@ -6558,6 +6570,14 @@ _dispatch_runloop_queue_handle_init(void *ctxt) + } + } + handle = fd; ++#elif defined(__unix__) ++ int fds[2]; ++ int r = pipe2(fds, O_CLOEXEC | O_NONBLOCK); ++ if (r == -1) { ++ DISPATCH_CLIENT_CRASH(errno, "pipe2 failure"); ++ } ++ uint32_t rfd = (uint32_t)fds[0], wfd = (uint32_t)fds[1]; ++ handle = DISPATCH_RUNLOOP_HANDLE_PACK(rfd, wfd); + #elif defined(_WIN32) + HANDLE hEvent; + hEvent = CreateEventW(NULL, /*bManualReset=*/FALSE, +@@ -6592,6 +6612,11 @@ _dispatch_runloop_queue_handle_dispose(dispatch_lane_t + #elif defined(__linux__) + int rc = close(handle); + (void)dispatch_assume_zero(rc); ++#elif defined(__unix__) ++ int rc = close(DISPATCH_RUNLOOP_HANDLE_WFD(handle)); ++ (void)dispatch_assume_zero(rc); ++ rc = close(DISPATCH_RUNLOOP_HANDLE_RFD(handle)); ++ (void)dispatch_assume_zero(rc); + #elif defined(_WIN32) + BOOL bSuccess; + bSuccess = CloseHandle(handle); +@@ -6628,6 +6653,13 @@ _dispatch_runloop_queue_class_poke(dispatch_lane_t dq) + result = eventfd_write(handle, 1); + } while (result == -1 && errno == EINTR); + (void)dispatch_assume_zero(result); ++#elif defined(__unix__) ++ int wfd = DISPATCH_RUNLOOP_HANDLE_WFD(handle); ++ ssize_t result; ++ do { ++ result = write(wfd, "x", 1); ++ } while (result == -1 && errno == EINTR); ++ (void)dispatch_assume_zero(result - 1); + #elif defined(_WIN32) + BOOL bSuccess; + bSuccess = SetEvent(handle); +@@ -6915,7 +6947,7 @@ _dispatch_runloop_root_queue_wakeup_4CF(dispatch_queue + _dispatch_runloop_queue_wakeup(upcast(dq)._dl, 0, false); + } + +-#if TARGET_OS_MAC || defined(_WIN32) ++#if TARGET_OS_MAC || defined(_WIN32) || defined(__FreeBSD__) + dispatch_runloop_handle_t + _dispatch_runloop_root_queue_get_port_4CF(dispatch_queue_t dq) + { +@@ -7304,6 +7336,13 @@ _gettid(void) + _gettid(void) + { + return (pid_t)pthread_getthreadid_np(); ++} ++#elif defined(__FreeBSD__) ++DISPATCH_ALWAYS_INLINE ++static inline pid_t ++_gettid(void) ++{ ++ return getthrid(); + } + #elif defined(_WIN32) + DISPATCH_ALWAYS_INLINE diff --git a/devel/libdispatch/files/patch-src_shims_lock.c b/devel/libdispatch/files/patch-src_shims_lock.c new file mode 100644 index 000000000000..c267242cb840 --- /dev/null +++ b/devel/libdispatch/files/patch-src_shims_lock.c @@ -0,0 +1,119 @@ +--- src/shims/lock.c.orig 2021-09-17 04:54:52 UTC ++++ src/shims/lock.c +@@ -56,6 +56,18 @@ _dispatch_thread_switch(dispatch_lock value, dispatch_ + #endif + #endif + ++#if defined(__unix__) ++DISPATCH_ALWAYS_INLINE ++static inline void ++_dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags, ++ uint32_t timeout) ++{ ++ (void)value; ++ (void)flags; ++ (void)timeout; ++} ++#endif ++ + #pragma mark - semaphores + + #if USE_MACH_SEM +@@ -394,8 +406,10 @@ _dispatch_unfair_lock_wake(uint32_t *uaddr, uint32_t f + #include <sys/time.h> + #ifdef __ANDROID__ + #include <sys/syscall.h> +-#else ++#elif __linux__ + #include <syscall.h> ++#else ++#include <sys/futex.h> + #endif /* __ANDROID__ */ + + DISPATCH_ALWAYS_INLINE +@@ -404,7 +418,12 @@ _dispatch_futex(uint32_t *uaddr, int op, uint32_t val, + const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3, + int opflags) + { ++#if __linux__ + return (int)syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3); ++#else ++ (void)val3; ++ return futex(uaddr, op | opflags, (int)val, timeout, uaddr2); ++#endif + } + + // returns 0, ETIMEDOUT, EFAULT, EINTR, EWOULDBLOCK +@@ -414,11 +433,15 @@ _futex_blocking_op(uint32_t *uaddr, int futex_op, uint + const struct timespec *timeout, int flags) + { + for (;;) { +- int rc = _dispatch_futex(uaddr, futex_op, val, timeout, NULL, 0, flags); +- if (!rc) { ++ int err = _dispatch_futex(uaddr, futex_op, val, timeout, NULL, 0, flags); ++ if (!err) { + return 0; + } +- switch (errno) { ++#if __linux__ ++ // syscall sets errno to communicate error code. ++ err = errno ++#endif ++ switch (err) { + case EINTR: + /* + * if we have a timeout, we need to return for the caller to +@@ -454,6 +477,7 @@ _dispatch_futex_wake(uint32_t *uaddr, int wake, int op + DISPATCH_INTERNAL_CRASH(errno, "_dlock_wake() failed"); + } + ++#if HAVE_FUTEX_PI + static void + _dispatch_futex_lock_pi(uint32_t *uaddr, struct timespec *timeout, int detect, + int opflags) +@@ -471,6 +495,7 @@ _dispatch_futex_unlock_pi(uint32_t *uaddr, int opflags + if (rc == 0) return; + DISPATCH_CLIENT_CRASH(errno, "futex_unlock_pi() failed"); + } ++#endif + + #endif + #pragma mark - wait for address +@@ -509,6 +534,19 @@ _dispatch_wait_on_address(uint32_t volatile *_address, + return _dispatch_futex_wait(address, value, NULL, FUTEX_PRIVATE_FLAG); + #elif defined(_WIN32) + return WaitOnAddress(address, &value, sizeof(value), INFINITE) == TRUE; ++#elif defined(__FreeBSD__) ++ uint64_t usecs = 0; ++ int rc; ++ if (nsecs == DISPATCH_TIME_FOREVER) { ++ return _dispatch_ulock_wait(address, value, 0, flags); ++ } ++ do { ++ usecs = howmany(nsecs, NSEC_PER_USEC); ++ if (usecs > UINT32_MAX) usecs = UINT32_MAX; ++ rc = _dispatch_ulock_wait(address, value, (uint32_t)usecs, flags); ++ } while (usecs == UINT32_MAX && rc == ETIMEDOUT && ++ (nsecs = _dispatch_timeout(timeout)) != 0); ++ return rc; + #else + #error _dispatch_wait_on_address unimplemented for this platform + #endif +@@ -599,7 +637,7 @@ _dispatch_unfair_lock_lock_slow(dispatch_unfair_lock_t + } + } + } +-#elif HAVE_FUTEX ++#elif HAVE_FUTEX_PI + void + _dispatch_unfair_lock_lock_slow(dispatch_unfair_lock_t dul, + dispatch_lock_options_t flags) +@@ -636,7 +674,7 @@ _dispatch_unfair_lock_unlock_slow(dispatch_unfair_lock + if (_dispatch_lock_has_waiters(cur)) { + _dispatch_unfair_lock_wake(&dul->dul_lock, 0); + } +-#elif HAVE_FUTEX ++#elif HAVE_FUTEX_PI + // futex_unlock_pi() handles both OWNER_DIED which we abuse & WAITERS + _dispatch_futex_unlock_pi(&dul->dul_lock, FUTEX_PRIVATE_FLAG); + #else diff --git a/devel/libdispatch/files/patch-src_shims_lock.h b/devel/libdispatch/files/patch-src_shims_lock.h new file mode 100644 index 000000000000..75d1230dcf5e --- /dev/null +++ b/devel/libdispatch/files/patch-src_shims_lock.h @@ -0,0 +1,45 @@ +--- src/shims/lock.h.orig 2021-09-17 04:54:52 UTC ++++ src/shims/lock.h +@@ -100,6 +100,25 @@ _dispatch_lock_owner(dispatch_lock lock_value) + return lock_value & DLOCK_OWNER_MASK; + } + ++#elif defined(__FreeBSD__) ++ ++typedef uint32_t dispatch_tid; ++typedef uint32_t dispatch_lock; ++ ++#define DLOCK_OWNER_NULL ((dispatch_tid)0) ++#define DLOCK_OWNER_MASK ((dispatch_lock)0xfffffffc) ++#define DLOCK_WAITERS_BIT ((dispatch_lock)0x00000001) ++#define DLOCK_FAILED_TRYLOCK_BIT ((dispatch_lock)0x00000002) ++ ++#define _dispatch_tid_self() ((dispatch_tid)(_dispatch_get_tsd_base()->tid)) ++ ++DISPATCH_ALWAYS_INLINE ++static inline dispatch_tid ++_dispatch_lock_owner(dispatch_lock lock_value) ++{ ++ return lock_value & DLOCK_OWNER_MASK; ++} ++ + #else + # error define _dispatch_lock encoding scheme for your platform here + #endif +@@ -167,10 +186,15 @@ _dispatch_lock_has_failed_trylock(dispatch_lock lock_v + #endif + + #ifndef HAVE_FUTEX +-#ifdef __linux__ ++#if defined(__linux__) + #define HAVE_FUTEX 1 ++#define HAVE_FUTEX_PI 1 ++#elif defined(__FreeBSD__) ++#define HAVE_FUTEX 0 ++#define HAVE_FUTEX_PI 0 + #else + #define HAVE_FUTEX 0 ++#define HAVE_FUTEX_PI 0 + #endif + #endif // HAVE_FUTEX + diff --git a/devel/libdispatch/files/patch-src_source.c b/devel/libdispatch/files/patch-src_source.c new file mode 100644 index 000000000000..c812cacf1e11 --- /dev/null +++ b/devel/libdispatch/files/patch-src_source.c @@ -0,0 +1,16 @@ +--- src/source.c.orig 2021-09-17 04:54:52 UTC ++++ src/source.c +@@ -1398,11 +1398,11 @@ _dispatch_source_debug_attr(dispatch_source_t ds, char + dispatch_source_refs_t dr = ds->ds_refs; + dispatch_queue_flags_t dqf = _dispatch_queue_atomic_flags(ds); + dispatch_unote_state_t du_state = _dispatch_unote_state(dr); +- return dsnprintf(buf, bufsiz, "target = %s[%p], ident = 0x%x, " ++ return dsnprintf(buf, bufsiz, "target = %s[%p], ident = 0x%llx, " + "mask = 0x%x, pending_data = 0x%llx, registered = %d, " + "armed = %d, %s%s%s", + target && target->dq_label ? target->dq_label : "", target, +- dr->du_ident, dr->du_fflags, (unsigned long long)dr->ds_pending_data, ++ (unsigned long long)dr->du_ident, dr->du_fflags, (unsigned long long)dr->ds_pending_data, + _du_state_registered(du_state), _du_state_armed(du_state), + (dqf & DSF_CANCELED) ? "cancelled, " : "", + (dqf & DSF_NEEDS_EVENT) ? "needs-event, " : "", diff --git a/devel/libdispatch/files/patch-src_swift_Source.swift b/devel/libdispatch/files/patch-src_swift_Source.swift new file mode 100644 index 000000000000..76aebc195c96 --- /dev/null +++ b/devel/libdispatch/files/patch-src_swift_Source.swift @@ -0,0 +1,47 @@ +--- src/swift/Source.swift.orig 2021-09-17 04:54:52 UTC ++++ src/swift/Source.swift +@@ -116,7 +116,7 @@ extension DispatchSource { + } + #endif + +-#if !os(Linux) && !os(Android) && !os(Windows) ++#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD) + public struct ProcessEvent : OptionSet, RawRepresentable { + public let rawValue: UInt + public init(rawValue: UInt) { self.rawValue = rawValue } +@@ -174,7 +174,7 @@ extension DispatchSource { + } + #endif + +-#if !os(Linux) && !os(Android) && !os(Windows) ++#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD) + public class func makeProcessSource(identifier: pid_t, eventMask: ProcessEvent, queue: DispatchQueue? = nil) -> DispatchSourceProcess { + let source = dispatch_source_create(_swift_dispatch_source_type_PROC(), UInt(identifier), eventMask.rawValue, queue?.__wrapped) + return DispatchSource(source: source) as DispatchSourceProcess +@@ -224,7 +224,7 @@ extension DispatchSource { + return DispatchSource(source: source) as DispatchSourceUserDataReplace + } + +-#if !os(Linux) && !os(Android) && !os(Windows) ++#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD) + public class func makeFileSystemObjectSource(fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject { + let source = dispatch_source_create(_swift_dispatch_source_type_VNODE(), UInt(fileDescriptor), eventMask.rawValue, queue?.__wrapped) + return DispatchSource(source: source) as DispatchSourceFileSystemObject +@@ -290,7 +290,7 @@ extension DispatchSourceMemoryPressure { + } + #endif + +-#if !os(Linux) && !os(Android) && !os(Windows) ++#if !os(Linux) && !os(Android) && !os(Windows) && !os(FreeBSD) *** 236 LINES SKIPPED ***