@@ -571,7 +571,7 @@ dispatch_block_testcancel(dispatch_block_t db)
571
571
return (bool )(dbpd -> dbpd_atomic_flags & DBF_CANCELED );
572
572
}
573
573
574
- long
574
+ intptr_t
575
575
dispatch_block_wait (dispatch_block_t db , dispatch_time_t timeout )
576
576
{
577
577
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)
2536
2536
{
2537
2537
uint64_t dq_state = os_atomic_load2o (dq ._dq , dq_state , relaxed );
2538
2538
if (likely (dq_state & DISPATCH_QUEUE_INACTIVE )) return ;
2539
- #ifndef __LP64__
2539
+ #if DISPATCH_SIZEOF_PTR == 4
2540
2540
dq_state >>= 32 ;
2541
2541
#endif
2542
2542
DISPATCH_CLIENT_CRASH ((uintptr_t )dq_state ,
@@ -2851,7 +2851,7 @@ _dispatch_lane_class_dispose(dispatch_lane_class_t dqu, bool *allow_free)
2851
2851
DISPATCH_CLIENT_CRASH ((uintptr_t )dq_state ,
2852
2852
"Release of a locked queue" );
2853
2853
}
2854
- #ifndef __LP64__
2854
+ #if DISPATCH_SIZEOF_PTR == 4
2855
2855
dq_state >>= 32 ;
2856
2856
#endif
2857
2857
DISPATCH_CLIENT_CRASH ((uintptr_t )dq_state ,
@@ -3948,6 +3948,9 @@ dispatch_workloop_set_scheduler_priority(dispatch_workloop_t dwl, int priority,
3948
3948
_dispatch_queue_setter_assert_inactive (dwl );
3949
3949
_dispatch_workloop_attributes_alloc_if_needed (dwl );
3950
3950
3951
+ #if defined(_WIN32 )
3952
+ // TODO(compnerd) setup thread priorities
3953
+ #else
3951
3954
if (priority ) {
3952
3955
dwl -> dwl_attr -> dwla_sched .sched_priority = priority ;
3953
3956
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,
3962
3965
} else {
3963
3966
dwl -> dwl_attr -> dwla_flags &= ~DISPATCH_WORKLOOP_ATTR_HAS_POLICY ;
3964
3967
}
3968
+ #endif
3965
3969
}
3966
3970
3967
3971
void
@@ -3971,6 +3975,9 @@ dispatch_workloop_set_qos_class_floor(dispatch_workloop_t dwl,
3971
3975
_dispatch_queue_setter_assert_inactive (dwl );
3972
3976
_dispatch_workloop_attributes_alloc_if_needed (dwl );
3973
3977
3978
+ #if defined(_WIN32 )
3979
+ // TODO(compnerd) honour QoS
3980
+ #else
3974
3981
dispatch_qos_t qos = _dispatch_qos_from_qos_class (cls );
3975
3982
3976
3983
if (qos ) {
@@ -3987,6 +3994,7 @@ dispatch_workloop_set_qos_class_floor(dispatch_workloop_t dwl,
3987
3994
} else {
3988
3995
dwl -> dwl_attr -> dwla_flags &= ~DISPATCH_WORKLOOP_ATTR_HAS_POLICY ;
3989
3996
}
3997
+ #endif
3990
3998
}
3991
3999
3992
4000
void
@@ -4036,6 +4044,7 @@ _dispatch_workloop_activate_simulator_fallback(dispatch_workloop_t dwl,
4036
4044
}
4037
4045
#endif // TARGET_OS_MAC
4038
4046
4047
+ #if !defined(_WIN32 )
4039
4048
static const struct dispatch_queue_global_s _dispatch_custom_workloop_root_queue = {
4040
4049
DISPATCH_GLOBAL_OBJECT_HEADER (queue_global ),
4041
4050
.dq_state = DISPATCH_ROOT_QUEUE_STATE_INIT_VALUE ,
@@ -4047,10 +4056,12 @@ static const struct dispatch_queue_global_s _dispatch_custom_workloop_root_queue
4047
4056
.dq_serialnum = DISPATCH_QUEUE_SERIAL_NUMBER_WLF ,
4048
4057
.dgq_thread_pool_size = 1 ,
4049
4058
};
4059
+ #endif
4050
4060
4051
4061
static void
4052
4062
_dispatch_workloop_activate_attributes (dispatch_workloop_t dwl )
4053
4063
{
4064
+ #if !defined(_WIN32 )
4054
4065
dispatch_workloop_attr_t dwla = dwl -> dwl_attr ;
4055
4066
pthread_attr_t attr ;
4056
4067
@@ -4076,7 +4087,7 @@ _dispatch_workloop_activate_attributes(dispatch_workloop_t dwl)
4076
4087
(unsigned long )dwla -> dwla_cpupercent .refillms );
4077
4088
}
4078
4089
#endif // HAVE_PTHREAD_ATTR_SETCPUPERCENT_NP
4079
- #if TARGET_OS_MAC
4090
+ #if TARGET_OS_MAC
4080
4091
if (_dispatch_workloop_has_kernel_attributes (dwl )) {
4081
4092
int rv = _pthread_workloop_create ((uint64_t )dwl , 0 , & attr );
4082
4093
switch (rv ) {
@@ -4093,6 +4104,7 @@ _dispatch_workloop_activate_attributes(dispatch_workloop_t dwl)
4093
4104
}
4094
4105
#endif // TARGET_OS_MAC
4095
4106
pthread_attr_destroy (& attr );
4107
+ #endif
4096
4108
}
4097
4109
4098
4110
void
@@ -4108,7 +4120,7 @@ _dispatch_workloop_dispose(dispatch_workloop_t dwl, bool *allow_free)
4108
4120
DISPATCH_CLIENT_CRASH ((uintptr_t )dq_state ,
4109
4121
"Release of a locked workloop" );
4110
4122
}
4111
- #ifndef __LP64__
4123
+ #if DISPATCH_SIZEOF_PTR == 4
4112
4124
dq_state >>= 32 ;
4113
4125
#endif
4114
4126
DISPATCH_CLIENT_CRASH ((uintptr_t )dq_state ,
@@ -4499,7 +4511,7 @@ _dispatch_workloop_wakeup(dispatch_workloop_t dwl, dispatch_qos_t qos,
4499
4511
});
4500
4512
4501
4513
if (unlikely (_dq_state_is_suspended (old_state ))) {
4502
- #ifndef __LP64__
4514
+ #if DISPATCH_SIZEOF_PTR == 4
4503
4515
old_state >>= 32 ;
4504
4516
#endif
4505
4517
DISPATCH_CLIENT_CRASH (old_state , "Waking up an inactive workloop" );
@@ -5119,7 +5131,6 @@ _dispatch_mgr_sched_qos2prio(qos_class_t qos)
5119
5131
static void
5120
5132
_dispatch_mgr_sched_init (void * ctxt DISPATCH_UNUSED )
5121
5133
{
5122
- #if !defined(_WIN32 )
5123
5134
struct sched_param param ;
5124
5135
#if DISPATCH_USE_MGR_THREAD && DISPATCH_USE_PTHREAD_ROOT_QUEUES
5125
5136
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)
5142
5153
}
5143
5154
#endif
5144
5155
_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)
5149
5156
_dispatch_mgr_sched .prio = _dispatch_mgr_sched .default_prio ;
5150
5157
}
5151
5158
#endif // DISPATCH_USE_PTHREAD_ROOT_QUEUES || DISPATCH_USE_KEVENT_WORKQUEUE
@@ -5673,7 +5680,9 @@ static void
5673
5680
_dispatch_root_queue_poke_slow (dispatch_queue_global_t dq , int n , int floor )
5674
5681
{
5675
5682
int remaining = n ;
5683
+ #if !defined(_WIN32 )
5676
5684
int r = ENOSYS ;
5685
+ #endif
5677
5686
5678
5687
_dispatch_root_queues_init ();
5679
5688
_dispatch_debug_root_queue (dq , __func__ );
@@ -5771,9 +5780,11 @@ _dispatch_root_queue_poke_slow(dispatch_queue_global_t dq, int n, int floor)
5771
5780
}
5772
5781
_dispatch_temporary_resource_shortage ();
5773
5782
}
5783
+ #if DISPATCH_USE_PTHREAD_ROOT_QUEUES
5774
5784
if (_dispatch_mgr_sched .prio > _dispatch_mgr_sched .default_prio ) {
5775
5785
(void )dispatch_assume_zero (SetThreadPriority ((HANDLE )hThread , _dispatch_mgr_sched .prio ) == TRUE);
5776
5786
}
5787
+ #endif
5777
5788
CloseHandle ((HANDLE )hThread );
5778
5789
} while (-- remaining );
5779
5790
#endif // defined(_WIN32)
@@ -6451,7 +6462,7 @@ _dispatch_pthread_root_queue_dispose(dispatch_queue_global_t dq,
6451
6462
6452
6463
DISPATCH_STATIC_GLOBAL (bool _dispatch_program_is_probably_callback_driven );
6453
6464
6454
- #if DISPATCH_COCOA_COMPAT
6465
+ #if DISPATCH_COCOA_COMPAT || defined( _WIN32 )
6455
6466
DISPATCH_STATIC_GLOBAL (dispatch_once_t _dispatch_main_q_handle_pred );
6456
6467
6457
6468
DISPATCH_ALWAYS_INLINE
@@ -6462,6 +6473,8 @@ _dispatch_runloop_handle_is_valid(dispatch_runloop_handle_t handle)
6462
6473
return MACH_PORT_VALID (handle );
6463
6474
#elif defined(__linux__ )
6464
6475
return handle >= 0 ;
6476
+ #elif defined(_WIN32 )
6477
+ return handle != NULL ;
6465
6478
#else
6466
6479
#error "runloop support not implemented on this platform"
6467
6480
#endif
@@ -6476,6 +6489,8 @@ _dispatch_runloop_queue_get_handle(dispatch_lane_t dq)
6476
6489
#elif defined(__linux__ )
6477
6490
// decode: 0 is a valid fd, so offset by 1 to distinguish from NULL
6478
6491
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 );
6479
6494
#else
6480
6495
#error "runloop support not implemented on this platform"
6481
6496
#endif
@@ -6491,6 +6506,8 @@ _dispatch_runloop_queue_set_handle(dispatch_lane_t dq,
6491
6506
#elif defined(__linux__ )
6492
6507
// encode: 0 is a valid fd, so offset by 1 to distinguish from NULL
6493
6508
dq -> do_ctxt = (void * )(uintptr_t )(handle + 1 );
6509
+ #elif defined(_WIN32 )
6510
+ dq -> do_ctxt = (void * )(uintptr_t )handle ;
6494
6511
#else
6495
6512
#error "runloop support not implemented on this platform"
6496
6513
#endif
@@ -6545,6 +6562,13 @@ _dispatch_runloop_queue_handle_init(void *ctxt)
6545
6562
}
6546
6563
}
6547
6564
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 ;
6548
6572
#else
6549
6573
#error "runloop support not implemented on this platform"
6550
6574
#endif
@@ -6571,6 +6595,9 @@ _dispatch_runloop_queue_handle_dispose(dispatch_lane_t dq)
6571
6595
#elif defined(__linux__ )
6572
6596
int rc = close (handle );
6573
6597
(void )dispatch_assume_zero (rc );
6598
+ #elif defined(_WIN32 )
6599
+ BOOL bResult = CloseHandle (handle );
6600
+ (void )dispatch_assume_zero (!bResult );
6574
6601
#else
6575
6602
#error "runloop support not implemented on this platform"
6576
6603
#endif
@@ -6603,6 +6630,9 @@ _dispatch_runloop_queue_class_poke(dispatch_lane_t dq)
6603
6630
result = eventfd_write (handle , 1 );
6604
6631
} while (result == -1 && errno == EINTR );
6605
6632
(void )dispatch_assume_zero (result );
6633
+ #elif defined(_WIN32 )
6634
+ BOOL bResult = SetEvent (handle );
6635
+ (void )dispatch_assert_zero (!bResult );
6606
6636
#else
6607
6637
#error "runloop support not implemented on this platform"
6608
6638
#endif
@@ -6900,7 +6930,8 @@ _dispatch_runloop_root_queue_get_port_4CF(dispatch_queue_t dq)
6900
6930
#endif // DISPATCH_COCOA_COMPAT
6901
6931
#pragma mark -
6902
6932
#pragma mark dispatch_main_queue
6903
- #if DISPATCH_COCOA_COMPAT
6933
+
6934
+ #if DISPATCH_COCOA_COMPAT || defined(_WIN32 )
6904
6935
6905
6936
dispatch_runloop_handle_t
6906
6937
_dispatch_get_main_queue_handle_4CF (void )
@@ -6984,7 +7015,9 @@ _dispatch_sig_thread(void *ctxt DISPATCH_UNUSED)
6984
7015
{
6985
7016
// never returns, so burn bridges behind us
6986
7017
_dispatch_clear_stack (0 );
6987
- #if !defined(_WIN32 )
7018
+ #if defined(_WIN32 )
7019
+ Sleep (INFINITE );
7020
+ #else
6988
7021
_dispatch_sigsuspend ();
6989
7022
#endif
6990
7023
}
0 commit comments