From 9d9a7e41279eb3e17c326c333f21dd7cbf02cfdd Mon Sep 17 00:00:00 2001 From: Apple Date: Sat, 3 Feb 2018 22:20:32 +0000 Subject: [PATCH] libdispatch-913.30.4.tar.gz --- private/private.h | 5 +++++ private/source_private.h | 2 +- src/event/event_kevent.c | 4 +++- src/firehose/firehose_inline_internal.h | 7 ++++++- src/inline_internal.h | 4 ++-- src/object.c | 6 +++--- src/object_internal.h | 16 ++++++++-------- src/queue.c | 2 +- src/shims/atomic.h | 2 +- src/source.c | 14 ++++++++++++++ 10 files changed, 44 insertions(+), 18 deletions(-) diff --git a/private/private.h b/private/private.h index ed9f876..cb51bed 100644 --- a/private/private.h +++ b/private/private.h @@ -227,6 +227,11 @@ _dispatch_network_root_queue_create_4NW(const char *_Nullable label, const pthread_attr_t *_Nullable attrs, dispatch_block_t _Nullable configure); #endif + +API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) +DISPATCH_EXPORT DISPATCH_WARN_RESULT DISPATCH_NOTHROW +bool +_dispatch_source_will_reenable_kevent_4NW(dispatch_source_t source); #endif API_AVAILABLE(macos(10.9), ios(7.0)) diff --git a/private/source_private.h b/private/source_private.h index ad22e6a..71d1724 100644 --- a/private/source_private.h +++ b/private/source_private.h @@ -356,7 +356,7 @@ enum { DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN DISPATCH_ENUM_API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) = 0x10, DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL DISPATCH_ENUM_API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) = 0x20, - + DISPATCH_MEMORYPRESSURE_MSL_STATUS DISPATCH_ENUM_API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) = 0xf0000000, }; diff --git a/src/event/event_kevent.c b/src/event/event_kevent.c index 963ff9e..067142a 100644 --- a/src/event/event_kevent.c +++ b/src/event/event_kevent.c @@ -606,7 +606,9 @@ _dispatch_kq_poll(dispatch_wlh_t wlh, dispatch_kevent_t ke, int n, #endif retry: - if (wlh == DISPATCH_WLH_ANON) { + if (unlikely(wlh == NULL)) { + DISPATCH_INTERNAL_CRASH(wlh, "Invalid wlh"); + } else if (wlh == DISPATCH_WLH_ANON) { int kqfd = _dispatch_kq; #if DISPATCH_USE_KEVENT_QOS if (_dispatch_kevent_workqueue_enabled) { diff --git a/src/firehose/firehose_inline_internal.h b/src/firehose/firehose_inline_internal.h index 3939ee2..1ff1c5a 100644 --- a/src/firehose/firehose_inline_internal.h +++ b/src/firehose/firehose_inline_internal.h @@ -21,13 +21,18 @@ #ifndef __FIREHOSE_INLINE_INTERNAL__ #define __FIREHOSE_INLINE_INTERNAL__ +#ifndef _os_atomic_basetypeof +#define _os_atomic_basetypeof(p) \ + typeof(atomic_load_explicit(_os_atomic_c11_atomic(p), memory_order_relaxed)) +#endif + #define firehose_atomic_maxv2o(p, f, v, o, m) \ os_atomic_rmw_loop2o(p, f, *(o), (v), m, { \ if (*(o) >= (v)) os_atomic_rmw_loop_give_up(break); \ }) #define firehose_atomic_max2o(p, f, v, m) ({ \ - typeof((p)->f) _old; \ + _os_atomic_basetypeof(&(p)->f) _old; \ firehose_atomic_maxv2o(p, f, v, &_old, m); \ }) diff --git a/src/inline_internal.h b/src/inline_internal.h index 1279874..27cdd73 100644 --- a/src/inline_internal.h +++ b/src/inline_internal.h @@ -176,8 +176,8 @@ DISPATCH_ALWAYS_INLINE static inline _os_object_t _os_object_retain_internal_n_inline(_os_object_t obj, int n) { - int ref_cnt = _os_object_refcnt_add(obj, n); - if (unlikely(ref_cnt <= 0)) { + int ref_cnt = _os_object_refcnt_add_orig(obj, n); + if (unlikely(ref_cnt < 0)) { _OS_OBJECT_CLIENT_CRASH("Resurrection of an object"); } return obj; diff --git a/src/object.c b/src/object.c index 86d1005..d467106 100644 --- a/src/object.c +++ b/src/object.c @@ -65,8 +65,8 @@ DISPATCH_NOINLINE _os_object_t _os_object_retain(_os_object_t obj) { - int xref_cnt = _os_object_xrefcnt_inc(obj); - if (slowpath(xref_cnt <= 0)) { + int xref_cnt = _os_object_xrefcnt_inc_orig(obj); + if (slowpath(xref_cnt < 0)) { _OS_OBJECT_CLIENT_CRASH("Resurrection of an object"); } return obj; @@ -76,7 +76,7 @@ DISPATCH_NOINLINE _os_object_t _os_object_retain_with_resurrect(_os_object_t obj) { - int xref_cnt = _os_object_xrefcnt_inc(obj); + int xref_cnt = _os_object_xrefcnt_inc_orig(obj) + 1; if (slowpath(xref_cnt < 0)) { _OS_OBJECT_CLIENT_CRASH("Resurrection of an over-released object"); } diff --git a/src/object_internal.h b/src/object_internal.h index 4504f65..2518862 100644 --- a/src/object_internal.h +++ b/src/object_internal.h @@ -598,8 +598,8 @@ size_t _dispatch_objc_debug(dispatch_object_t dou, char* buf, size_t bufsiz); _ref_cnt; \ }) -#define _os_atomic_refcnt_add2o(o, m, n) \ - _os_atomic_refcnt_perform2o(o, m, add, n, relaxed) +#define _os_atomic_refcnt_add_orig2o(o, m, n) \ + _os_atomic_refcnt_perform2o(o, m, add_orig, n, relaxed) #define _os_atomic_refcnt_sub2o(o, m, n) \ _os_atomic_refcnt_perform2o(o, m, sub, n, release) @@ -611,9 +611,9 @@ size_t _dispatch_objc_debug(dispatch_object_t dou, char* buf, size_t bufsiz); /* * Higher level _os_object_{x,}refcnt_* actions * - * _os_atomic_{x,}refcnt_inc(o): + * _os_atomic_{x,}refcnt_inc_orig(o): * increment the external (resp. internal) refcount and - * returns the new refcount value + * returns the old refcount value * * _os_atomic_{x,}refcnt_dec(o): * decrement the external (resp. internal) refcount and @@ -624,8 +624,8 @@ size_t _dispatch_objc_debug(dispatch_object_t dou, char* buf, size_t bufsiz); * (resp. internal) refcount * */ -#define _os_object_xrefcnt_inc(o) \ - _os_atomic_refcnt_add2o(o, os_obj_xref_cnt, 1) +#define _os_object_xrefcnt_inc_orig(o) \ + _os_atomic_refcnt_add_orig2o(o, os_obj_xref_cnt, 1) #define _os_object_xrefcnt_dec(o) \ _os_atomic_refcnt_sub2o(o, os_obj_xref_cnt, 1) @@ -633,8 +633,8 @@ size_t _dispatch_objc_debug(dispatch_object_t dou, char* buf, size_t bufsiz); #define _os_object_xrefcnt_dispose_barrier(o) \ _os_atomic_refcnt_dispose_barrier2o(o, os_obj_xref_cnt) -#define _os_object_refcnt_add(o, n) \ - _os_atomic_refcnt_add2o(o, os_obj_ref_cnt, n) +#define _os_object_refcnt_add_orig(o, n) \ + _os_atomic_refcnt_add_orig2o(o, os_obj_ref_cnt, n) #define _os_object_refcnt_sub(o, n) \ _os_atomic_refcnt_sub2o(o, os_obj_ref_cnt, n) diff --git a/src/queue.c b/src/queue.c index 23eb63a..1ac8332 100644 --- a/src/queue.c +++ b/src/queue.c @@ -3737,7 +3737,7 @@ _dispatch_sync_waiter_redirect_or_wake(dispatch_queue_t dq, uint64_t owned, { dispatch_sync_context_t dsc = (dispatch_sync_context_t)dou._dc; uint64_t next_owner = 0, old_state, new_state; - dispatch_wlh_t wlh = NULL; + dispatch_wlh_t wlh = DISPATCH_WLH_ANON; _dispatch_trace_continuation_pop(dq, dsc->_as_dc); diff --git a/src/shims/atomic.h b/src/shims/atomic.h index 64af8b2..cb9b95f 100644 --- a/src/shims/atomic.h +++ b/src/shims/atomic.h @@ -67,7 +67,7 @@ #define _os_atomic_c11_op(p, v, m, o, op) \ ({ _os_atomic_basetypeof(p) _v = (v), _r = \ atomic_fetch_##o##_explicit(_os_atomic_c11_atomic(p), _v, \ - memory_order_##m); (typeof(*(p)))(_r op _v); }) + memory_order_##m); (typeof(_r))(_r op _v); }) #define _os_atomic_c11_op_orig(p, v, m, o, op) \ atomic_fetch_##o##_explicit(_os_atomic_c11_atomic(p), v, \ memory_order_##m) diff --git a/src/source.c b/src/source.c index 6f50478..a5573b6 100644 --- a/src/source.c +++ b/src/source.c @@ -453,6 +453,20 @@ dispatch_source_set_registration_handler_f(dispatch_source_t ds, #pragma mark - #pragma mark dispatch_source_invoke +bool +_dispatch_source_will_reenable_kevent_4NW(dispatch_source_t ds) +{ + uint64_t dq_state = os_atomic_load2o(ds, dq_state, relaxed); + dispatch_queue_flags_t dqf = _dispatch_queue_atomic_flags(ds->_as_dq); + + if (unlikely(!_dq_state_drain_locked_by_self(dq_state))) { + DISPATCH_CLIENT_CRASH(0, "_dispatch_source_will_reenable_kevent_4NW " + "not called from within the event handler"); + } + + return _dispatch_unote_needs_rearm(ds->ds_refs) && !(dqf & DSF_ARMED); +} + static void _dispatch_source_registration_callout(dispatch_source_t ds, dispatch_queue_t cq, dispatch_invoke_flags_t flags) -- 2.45.2