Skip to content

Commit 33aaf78

Browse files
committed
Updates for 1121 release for Windows
Make the 1121 release build on Windows. This is sufficient for getting a basic Hello World dispatch program to run under swift again.
1 parent aac4452 commit 33aaf78

15 files changed

+134
-40
lines changed

src/event/event_windows.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,20 @@
2424
#pragma mark dispatch_unote_t
2525

2626
bool
27-
_dispatch_unote_register(dispatch_unote_t du DISPATCH_UNUSED,
28-
dispatch_wlh_t wlh DISPATCH_UNUSED,
29-
dispatch_priority_t pri DISPATCH_UNUSED)
27+
_dispatch_unote_register_muxed(dispatch_unote_t du DISPATCH_UNUSED)
3028
{
3129
WIN_PORT_ERROR();
3230
return false;
3331
}
3432

3533
void
36-
_dispatch_unote_resume(dispatch_unote_t du DISPATCH_UNUSED)
34+
_dispatch_unote_resume_muxed(dispatch_unote_t du DISPATCH_UNUSED)
3735
{
3836
WIN_PORT_ERROR();
3937
}
4038

4139
bool
42-
_dispatch_unote_unregister(dispatch_unote_t du DISPATCH_UNUSED,
43-
uint32_t flags DISPATCH_UNUSED)
40+
_dispatch_unote_unregister_muxed(dispatch_unote_t du DISPATCH_UNUSED)
4441
{
4542
WIN_PORT_ERROR();
4643
return false;
@@ -49,15 +46,17 @@ _dispatch_unote_unregister(dispatch_unote_t du DISPATCH_UNUSED,
4946
#pragma mark timers
5047

5148
void
52-
_dispatch_event_loop_timer_arm(uint32_t tidx DISPATCH_UNUSED,
49+
_dispatch_event_loop_timer_arm(dispatch_timer_heap_t dth DISPATCH_UNUSED,
50+
uint32_t tidx DISPATCH_UNUSED,
5351
dispatch_timer_delay_s range DISPATCH_UNUSED,
5452
dispatch_clock_now_cache_t nows DISPATCH_UNUSED)
5553
{
5654
WIN_PORT_ERROR();
5755
}
5856

5957
void
60-
_dispatch_event_loop_timer_delete(uint32_t tidx DISPATCH_UNUSED)
58+
_dispatch_event_loop_timer_delete(dispatch_timer_heap_t dth DISPATCH_UNUSED,
59+
uint32_t tidx DISPATCH_UNUSED)
6160
{
6261
WIN_PORT_ERROR();
6362
}
@@ -78,6 +77,12 @@ _dispatch_event_loop_drain(uint32_t flags DISPATCH_UNUSED)
7877
WIN_PORT_ERROR();
7978
}
8079

80+
void
81+
_dispatch_event_loop_cancel_waiter(dispatch_sync_context_t dsc DISPATCH_UNUSED)
82+
{
83+
WIN_PORT_ERROR();
84+
}
85+
8186
void
8287
_dispatch_event_loop_wake_owner(dispatch_sync_context_t dsc,
8388
dispatch_wlh_t wlh, uint64_t old_state, uint64_t new_state)
@@ -109,9 +114,9 @@ _dispatch_event_loop_assert_not_owned(dispatch_wlh_t wlh)
109114
#endif
110115

111116
void
112-
_dispatch_event_loop_leave_immediate(dispatch_wlh_t wlh, uint64_t dq_state)
117+
_dispatch_event_loop_leave_immediate(uint64_t dq_state)
113118
{
114-
(void)wlh; (void)dq_state;
119+
(void)dq_state;
115120
}
116121

117122
#endif // DISPATCH_EVENT_BACKEND_WINDOWS

src/event/workqueue.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ _dispatch_workq_worker_register(dispatch_queue_global_t root_q)
9797
_dispatch_unfair_lock_unlock(&mon->registered_tid_lock);
9898
#else
9999
(void)root_q;
100-
(void)cls;
101100
#endif // HAVE_DISPATCH_WORKQ_MONITORING
102101
}
103102

@@ -124,7 +123,6 @@ _dispatch_workq_worker_unregister(dispatch_queue_global_t root_q)
124123
_dispatch_unfair_lock_unlock(&mon->registered_tid_lock);
125124
#else
126125
(void)root_q;
127-
(void)cls;
128126
#endif // HAVE_DISPATCH_WORKQ_MONITORING
129127
}
130128

src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ DISPATCH_VTABLE_SUBCLASS_INSTANCE(queue_main, lane,
739739
.dq_push = _dispatch_main_queue_push,
740740
);
741741

742-
#if DISPATCH_COCOA_COMPAT
742+
#if DISPATCH_COCOA_COMPAT || defined(_WIN32)
743743
DISPATCH_VTABLE_SUBCLASS_INSTANCE(queue_runloop, lane,
744744
.do_type = DISPATCH_QUEUE_RUNLOOP_TYPE,
745745
.do_dispose = _dispatch_runloop_queue_dispose,

src/inline_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ _dispatch_queue_drain_try_lock_wlh(dispatch_queue_t dq, uint64_t *dq_state)
12941294
if (unlikely(!_dq_state_is_base_wlh(old_state) ||
12951295
!_dq_state_is_enqueued_on_target(old_state) ||
12961296
_dq_state_is_enqueued_on_manager(old_state))) {
1297-
#if !__LP64__
1297+
#if DISPATCH_SIZEOF_PTR == 4
12981298
old_state >>= 32;
12991299
#endif
13001300
DISPATCH_INTERNAL_CRASH(old_state, "Invalid wlh state");

src/io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,11 +1399,11 @@ _dispatch_fd_entry_create_with_fd(dispatch_fd_t fd, uintptr_t hash)
13991399
int result = ioctlsocket((SOCKET)fd, (long)FIONBIO, &value);
14001400
(void)dispatch_assume_zero(result);
14011401
_dispatch_stream_init(fd_entry,
1402-
_dispatch_get_root_queue(DISPATCH_QOS_DEFAULT, false));
1402+
_dispatch_get_default_queue(false));
14031403
} else {
14041404
dispatch_suspend(fd_entry->barrier_queue);
1405-
dispatch_once_f(&_dispatch_io_devs_lockq_pred, NULL,
1406-
_dispatch_io_devs_lockq_init);
1405+
dispatch_once_f(&_dispatch_io_init_pred, NULL,
1406+
_dispatch_io_queues_init);
14071407
dispatch_async(_dispatch_io_devs_lockq, ^{
14081408
_dispatch_disk_init(fd_entry, 0);
14091409
dispatch_resume(fd_entry->barrier_queue);

src/object.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ _dispatch_xref_dispose(dispatch_object_t dou)
203203
break;
204204
#endif
205205
case DISPATCH_QUEUE_RUNLOOP_TYPE:
206+
#if DISPATCH_COCOA_COMPAT
206207
_dispatch_runloop_queue_xref_dispose(dou._dl);
208+
#endif
207209
break;
208210
}
209211
return _dispatch_release_tailcall(dou._os_obj);

src/queue.c

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ dispatch_block_testcancel(dispatch_block_t db)
571571
return (bool)(dbpd->dbpd_atomic_flags & DBF_CANCELED);
572572
}
573573

574-
long
574+
intptr_t
575575
dispatch_block_wait(dispatch_block_t db, dispatch_time_t timeout)
576576
{
577577
dispatch_block_private_data_t dbpd = _dispatch_block_get_data(db);
@@ -2536,7 +2536,7 @@ _dispatch_queue_setter_assert_inactive(dispatch_queue_class_t dq)
25362536
{
25372537
uint64_t dq_state = os_atomic_load2o(dq._dq, dq_state, relaxed);
25382538
if (likely(dq_state & DISPATCH_QUEUE_INACTIVE)) return;
2539-
#ifndef __LP64__
2539+
#if DISPATCH_SIZEOF_PTR == 4
25402540
dq_state >>= 32;
25412541
#endif
25422542
DISPATCH_CLIENT_CRASH((uintptr_t)dq_state,
@@ -2851,7 +2851,7 @@ _dispatch_lane_class_dispose(dispatch_lane_class_t dqu, bool *allow_free)
28512851
DISPATCH_CLIENT_CRASH((uintptr_t)dq_state,
28522852
"Release of a locked queue");
28532853
}
2854-
#ifndef __LP64__
2854+
#if DISPATCH_SIZEOF_PTR == 4
28552855
dq_state >>= 32;
28562856
#endif
28572857
DISPATCH_CLIENT_CRASH((uintptr_t)dq_state,
@@ -3948,6 +3948,9 @@ dispatch_workloop_set_scheduler_priority(dispatch_workloop_t dwl, int priority,
39483948
_dispatch_queue_setter_assert_inactive(dwl);
39493949
_dispatch_workloop_attributes_alloc_if_needed(dwl);
39503950

3951+
#if defined(_WIN32)
3952+
// TODO(compnerd) setup thread priorities
3953+
#else
39513954
if (priority) {
39523955
dwl->dwl_attr->dwla_sched.sched_priority = priority;
39533956
dwl->dwl_attr->dwla_flags |= DISPATCH_WORKLOOP_ATTR_HAS_SCHED;
@@ -3962,6 +3965,7 @@ dispatch_workloop_set_scheduler_priority(dispatch_workloop_t dwl, int priority,
39623965
} else {
39633966
dwl->dwl_attr->dwla_flags &= ~DISPATCH_WORKLOOP_ATTR_HAS_POLICY;
39643967
}
3968+
#endif
39653969
}
39663970

39673971
void
@@ -3971,6 +3975,9 @@ dispatch_workloop_set_qos_class_floor(dispatch_workloop_t dwl,
39713975
_dispatch_queue_setter_assert_inactive(dwl);
39723976
_dispatch_workloop_attributes_alloc_if_needed(dwl);
39733977

3978+
#if defined(_WIN32)
3979+
// TODO(compnerd) honour QoS
3980+
#else
39743981
dispatch_qos_t qos = _dispatch_qos_from_qos_class(cls);
39753982

39763983
if (qos) {
@@ -3987,6 +3994,7 @@ dispatch_workloop_set_qos_class_floor(dispatch_workloop_t dwl,
39873994
} else {
39883995
dwl->dwl_attr->dwla_flags &= ~DISPATCH_WORKLOOP_ATTR_HAS_POLICY;
39893996
}
3997+
#endif
39903998
}
39913999

39924000
void
@@ -4036,6 +4044,7 @@ _dispatch_workloop_activate_simulator_fallback(dispatch_workloop_t dwl,
40364044
}
40374045
#endif // TARGET_OS_MAC
40384046

4047+
#if !defined(_WIN32)
40394048
static const struct dispatch_queue_global_s _dispatch_custom_workloop_root_queue = {
40404049
DISPATCH_GLOBAL_OBJECT_HEADER(queue_global),
40414050
.dq_state = DISPATCH_ROOT_QUEUE_STATE_INIT_VALUE,
@@ -4047,10 +4056,12 @@ static const struct dispatch_queue_global_s _dispatch_custom_workloop_root_queue
40474056
.dq_serialnum = DISPATCH_QUEUE_SERIAL_NUMBER_WLF,
40484057
.dgq_thread_pool_size = 1,
40494058
};
4059+
#endif
40504060

40514061
static void
40524062
_dispatch_workloop_activate_attributes(dispatch_workloop_t dwl)
40534063
{
4064+
#if !defined(_WIN32)
40544065
dispatch_workloop_attr_t dwla = dwl->dwl_attr;
40554066
pthread_attr_t attr;
40564067

@@ -4076,7 +4087,7 @@ _dispatch_workloop_activate_attributes(dispatch_workloop_t dwl)
40764087
(unsigned long)dwla->dwla_cpupercent.refillms);
40774088
}
40784089
#endif // HAVE_PTHREAD_ATTR_SETCPUPERCENT_NP
4079-
#if TARGET_OS_MAC
4090+
#if TARGET_OS_MAC
40804091
if (_dispatch_workloop_has_kernel_attributes(dwl)) {
40814092
int rv = _pthread_workloop_create((uint64_t)dwl, 0, &attr);
40824093
switch (rv) {
@@ -4093,6 +4104,7 @@ _dispatch_workloop_activate_attributes(dispatch_workloop_t dwl)
40934104
}
40944105
#endif // TARGET_OS_MAC
40954106
pthread_attr_destroy(&attr);
4107+
#endif
40964108
}
40974109

40984110
void
@@ -4108,7 +4120,7 @@ _dispatch_workloop_dispose(dispatch_workloop_t dwl, bool *allow_free)
41084120
DISPATCH_CLIENT_CRASH((uintptr_t)dq_state,
41094121
"Release of a locked workloop");
41104122
}
4111-
#ifndef __LP64__
4123+
#if DISPATCH_SIZEOF_PTR == 4
41124124
dq_state >>= 32;
41134125
#endif
41144126
DISPATCH_CLIENT_CRASH((uintptr_t)dq_state,
@@ -4499,7 +4511,7 @@ _dispatch_workloop_wakeup(dispatch_workloop_t dwl, dispatch_qos_t qos,
44994511
});
45004512

45014513
if (unlikely(_dq_state_is_suspended(old_state))) {
4502-
#ifndef __LP64__
4514+
#if DISPATCH_SIZEOF_PTR == 4
45034515
old_state >>= 32;
45044516
#endif
45054517
DISPATCH_CLIENT_CRASH(old_state, "Waking up an inactive workloop");
@@ -5119,7 +5131,6 @@ _dispatch_mgr_sched_qos2prio(qos_class_t qos)
51195131
static void
51205132
_dispatch_mgr_sched_init(void *ctxt DISPATCH_UNUSED)
51215133
{
5122-
#if !defined(_WIN32)
51235134
struct sched_param param;
51245135
#if DISPATCH_USE_MGR_THREAD && DISPATCH_USE_PTHREAD_ROOT_QUEUES
51255136
dispatch_pthread_root_queue_context_t pqc = _dispatch_mgr_root_queue.do_ctxt;
@@ -5142,10 +5153,6 @@ _dispatch_mgr_sched_init(void *ctxt DISPATCH_UNUSED)
51425153
}
51435154
#endif
51445155
_dispatch_mgr_sched.default_prio = param.sched_priority;
5145-
#else // defined(_WIN32)
5146-
_dispatch_mgr_sched.policy = 0;
5147-
_dispatch_mgr_sched.default_prio = THREAD_PRIORITY_NORMAL;
5148-
#endif // defined(_WIN32)
51495156
_dispatch_mgr_sched.prio = _dispatch_mgr_sched.default_prio;
51505157
}
51515158
#endif // DISPATCH_USE_PTHREAD_ROOT_QUEUES || DISPATCH_USE_KEVENT_WORKQUEUE
@@ -5673,7 +5680,9 @@ static void
56735680
_dispatch_root_queue_poke_slow(dispatch_queue_global_t dq, int n, int floor)
56745681
{
56755682
int remaining = n;
5683+
#if !defined(_WIN32)
56765684
int r = ENOSYS;
5685+
#endif
56775686

56785687
_dispatch_root_queues_init();
56795688
_dispatch_debug_root_queue(dq, __func__);
@@ -5771,9 +5780,11 @@ _dispatch_root_queue_poke_slow(dispatch_queue_global_t dq, int n, int floor)
57715780
}
57725781
_dispatch_temporary_resource_shortage();
57735782
}
5783+
#if DISPATCH_USE_PTHREAD_ROOT_QUEUES
57745784
if (_dispatch_mgr_sched.prio > _dispatch_mgr_sched.default_prio) {
57755785
(void)dispatch_assume_zero(SetThreadPriority((HANDLE)hThread, _dispatch_mgr_sched.prio) == TRUE);
57765786
}
5787+
#endif
57775788
CloseHandle((HANDLE)hThread);
57785789
} while (--remaining);
57795790
#endif // defined(_WIN32)
@@ -6451,7 +6462,7 @@ _dispatch_pthread_root_queue_dispose(dispatch_queue_global_t dq,
64516462

64526463
DISPATCH_STATIC_GLOBAL(bool _dispatch_program_is_probably_callback_driven);
64536464

6454-
#if DISPATCH_COCOA_COMPAT
6465+
#if DISPATCH_COCOA_COMPAT || defined(_WIN32)
64556466
DISPATCH_STATIC_GLOBAL(dispatch_once_t _dispatch_main_q_handle_pred);
64566467

64576468
DISPATCH_ALWAYS_INLINE
@@ -6462,6 +6473,8 @@ _dispatch_runloop_handle_is_valid(dispatch_runloop_handle_t handle)
64626473
return MACH_PORT_VALID(handle);
64636474
#elif defined(__linux__)
64646475
return handle >= 0;
6476+
#elif defined(_WIN32)
6477+
return handle != NULL;
64656478
#else
64666479
#error "runloop support not implemented on this platform"
64676480
#endif
@@ -6476,6 +6489,8 @@ _dispatch_runloop_queue_get_handle(dispatch_lane_t dq)
64766489
#elif defined(__linux__)
64776490
// decode: 0 is a valid fd, so offset by 1 to distinguish from NULL
64786491
return ((dispatch_runloop_handle_t)(uintptr_t)dq->do_ctxt) - 1;
6492+
#elif defined(_WIN32)
6493+
return ((dispatch_runloop_handle_t)(uintptr_t)dq->do_ctxt);
64796494
#else
64806495
#error "runloop support not implemented on this platform"
64816496
#endif
@@ -6491,6 +6506,8 @@ _dispatch_runloop_queue_set_handle(dispatch_lane_t dq,
64916506
#elif defined(__linux__)
64926507
// encode: 0 is a valid fd, so offset by 1 to distinguish from NULL
64936508
dq->do_ctxt = (void *)(uintptr_t)(handle + 1);
6509+
#elif defined(_WIN32)
6510+
dq->do_ctxt = (void *)(uintptr_t)handle;
64946511
#else
64956512
#error "runloop support not implemented on this platform"
64966513
#endif
@@ -6545,6 +6562,13 @@ _dispatch_runloop_queue_handle_init(void *ctxt)
65456562
}
65466563
}
65476564
handle = fd;
6565+
#elif defined(_WIN32)
6566+
HANDLE hEvent = CreateEventW(NULL, /*bManualReset=*/TRUE,
6567+
/*bInitialState=*/FALSE, NULL);
6568+
if (hEvent == NULL) {
6569+
DISPATCH_CLIENT_CRASH(GetLastError(), "CreateEventW");
6570+
}
6571+
handle = hEvent;
65486572
#else
65496573
#error "runloop support not implemented on this platform"
65506574
#endif
@@ -6571,6 +6595,9 @@ _dispatch_runloop_queue_handle_dispose(dispatch_lane_t dq)
65716595
#elif defined(__linux__)
65726596
int rc = close(handle);
65736597
(void)dispatch_assume_zero(rc);
6598+
#elif defined(_WIN32)
6599+
BOOL bResult = CloseHandle(handle);
6600+
(void)dispatch_assume_zero(!bResult);
65746601
#else
65756602
#error "runloop support not implemented on this platform"
65766603
#endif
@@ -6603,6 +6630,9 @@ _dispatch_runloop_queue_class_poke(dispatch_lane_t dq)
66036630
result = eventfd_write(handle, 1);
66046631
} while (result == -1 && errno == EINTR);
66056632
(void)dispatch_assume_zero(result);
6633+
#elif defined(_WIN32)
6634+
BOOL bResult = SetEvent(handle);
6635+
(void)dispatch_assert_zero(!bResult);
66066636
#else
66076637
#error "runloop support not implemented on this platform"
66086638
#endif
@@ -6900,7 +6930,8 @@ _dispatch_runloop_root_queue_get_port_4CF(dispatch_queue_t dq)
69006930
#endif // DISPATCH_COCOA_COMPAT
69016931
#pragma mark -
69026932
#pragma mark dispatch_main_queue
6903-
#if DISPATCH_COCOA_COMPAT
6933+
6934+
#if DISPATCH_COCOA_COMPAT || defined(_WIN32)
69046935

69056936
dispatch_runloop_handle_t
69066937
_dispatch_get_main_queue_handle_4CF(void)
@@ -6984,7 +7015,9 @@ _dispatch_sig_thread(void *ctxt DISPATCH_UNUSED)
69847015
{
69857016
// never returns, so burn bridges behind us
69867017
_dispatch_clear_stack(0);
6987-
#if !defined(_WIN32)
7018+
#if defined(_WIN32)
7019+
Sleep(INFINITE);
7020+
#else
69887021
_dispatch_sigsuspend();
69897022
#endif
69907023
}

0 commit comments

Comments
 (0)