]> git.saurik.com Git - apple/libdispatch.git/commitdiff
libdispatch-913.30.4.tar.gz master macos-10132 macos-10133 v913.30.4
authorApple <opensource@apple.com>
Sat, 3 Feb 2018 22:20:32 +0000 (22:20 +0000)
committerApple <opensource@apple.com>
Sat, 3 Feb 2018 22:20:32 +0000 (22:20 +0000)
private/private.h
private/source_private.h
src/event/event_kevent.c
src/firehose/firehose_inline_internal.h
src/inline_internal.h
src/object.c
src/object_internal.h
src/queue.c
src/shims/atomic.h
src/source.c

index ed9f876cce6343b67fa9589a872b4ec288415817..cb51bedfed9afca198cba11fa3ca6c7dd416879c 100644 (file)
@@ -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))
index ad22e6a6a2296cde90a770362444dfda26214dd5..71d17246fc06906e8cb899b8c2597e4d60149dae 100644 (file)
@@ -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,
 };
 
index 963ff9e277e275f710d1feb8e9b0e41c3d85a12d..067142a9f57fc80173a64f10612160a18bc0f776 100644 (file)
@@ -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) {
index 3939ee25b633400a6c06318aa8f2acef74e0a3f3..1ff1c5a90d8d97186aff4876260b2ebe9c4c5909 100644 (file)
 #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); \
        })
 
index 1279874d40d543da825b5f5c77d785365c6f004c..27cdd732fe8f91d9f5f5a9c65d890ff090047683 100644 (file)
@@ -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;
index 86d100507de645de5efcb642631e812c47a96fbe..d467106c5a994ffcd556ad5964bba6ed3a347bd9 100644 (file)
@@ -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");
        }
index 4504f658713fc803735a2d3f82af170ac0f0ad4c..251886288c60103f82f7bfd3bc9d4bbbfb8ee80d 100644 (file)
@@ -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)
index 23eb63a7e5cd6fed0ef6f7368fa9c19250bccbbb..1ac8332570b0b0cc2b876e06f07c781cc8470709 100644 (file)
@@ -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);
 
index 64af8b2725879b386d84628a4fb60e476a24ed14..cb9b95f4823a714e105da57abb53b031cbc51678 100644 (file)
@@ -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)
index 6f504787d0c7b58c450e8594353d0d3d6d0890f9..a5573b6c763da1966d11e01bc2e99597de6566a1 100644 (file)
@@ -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)