#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
+#include <mach/port.h>
#include <os/base_private.h>
#include <os/lock.h>
* Low-level lock SPI
*/
-#define OS_LOCK_SPI_VERSION 20171006
+#define OS_LOCK_SPI_VERSION 20190424
/*!
* @typedef os_lock_t
void os_unfair_lock_lock_with_options(os_unfair_lock_t lock,
os_unfair_lock_options_t options);
-/*! @group os_unfair_lock no-TSD interfaces
+/*!
+ * @group os_unfair_lock no-TSD interfaces
*
* Like the above, but don't require being on a thread with valid TSD, so they
- * can be called from injected mach-threads. The normal routines use the TSD
- * value for mach_thread_self(), these routines use MACH_PORT_DEAD for the
- * locked value instead. As a result, they will be unable to resolve priority
- * inversions.
+ * can be called from injected mach-threads.
*
- * This should only be used by libpthread.
+ * The normal routines use the TSD value for mach_thread_self(), but mach
+ * threads do not have TSDs. Instead these functions require the value for
+ * mach_thread_self() to be passed explicitly.
*
+ * This should only be used directly by libpthread.
*/
-OS_UNFAIR_LOCK_AVAILABILITY
+__API_AVAILABLE(macos(10.16), ios(14.0), tvos(14.0), watchos(7.0))
OS_EXPORT OS_NOTHROW OS_NONNULL_ALL
-void os_unfair_lock_lock_no_tsd_4libpthread(os_unfair_lock_t lock);
+void os_unfair_lock_lock_no_tsd(os_unfair_lock_t lock,
+ os_unfair_lock_options_t options, mach_port_t mts);
-OS_UNFAIR_LOCK_AVAILABILITY
+__API_AVAILABLE(macos(10.16), ios(14.0), tvos(14.0), watchos(7.0))
OS_EXPORT OS_NOTHROW OS_NONNULL_ALL
-void os_unfair_lock_unlock_no_tsd_4libpthread(os_unfair_lock_t lock);
+void os_unfair_lock_unlock_no_tsd(os_unfair_lock_t lock, mach_port_t mts);
+
/*! @group os_unfair_recursive_lock SPI
*
#define OS_UNFAIR_LOCK_UNLOCKED {0}
#endif
+/*!
+ * @function os_unfair_lock_lock_no_tsd_inline
+ *
+ * @abstract
+ * Locks an os_unfair_lock, without requiring valid TSD.
+ *
+ * This should only be used directly by libpthread.
+ *
+ * @param lock
+ * Pointer to an os_unfair_lock.
+ */
+__API_AVAILABLE(macos(10.16), ios(14.0), tvos(14.0), watchos(7.0))
+OS_INLINE OS_ALWAYS_INLINE OS_NONNULL_ALL
+void
+os_unfair_lock_lock_no_tsd_inline(os_unfair_lock_t lock,
+ os_unfair_lock_options_t options, mach_port_t mts)
+{
+ os_unfair_lock unlocked = OS_UNFAIR_LOCK_UNLOCKED, locked = { mts };
+ if (!OSLOCK_STD(atomic_compare_exchange_strong_explicit)(
+ (_os_atomic_unfair_lock*)lock, &unlocked, locked,
+ OSLOCK_STD(memory_order_acquire),
+ OSLOCK_STD(memory_order_relaxed))) {
+ return os_unfair_lock_lock_no_tsd(lock, options, mts);
+ }
+}
+
+/*!
+ * @function os_unfair_lock_unlock_no_tsd_inline
+ *
+ * @abstract
+ * Unlocks an os_unfair_lock, without requiring valid TSD.
+ *
+ * This should only be used directly by libpthread.
+ *
+ * @param lock
+ * Pointer to an os_unfair_lock.
+ */
+__API_AVAILABLE(macos(10.16), ios(14.0), tvos(14.0), watchos(7.0))
+OS_INLINE OS_ALWAYS_INLINE OS_NONNULL_ALL
+void
+os_unfair_lock_unlock_no_tsd_inline(os_unfair_lock_t lock, mach_port_t mts)
+{
+ os_unfair_lock unlocked = OS_UNFAIR_LOCK_UNLOCKED, locked = { mts };
+ if (!OSLOCK_STD(atomic_compare_exchange_strong_explicit)(
+ (_os_atomic_unfair_lock*)lock, &locked, unlocked,
+ OSLOCK_STD(memory_order_release),
+ OSLOCK_STD(memory_order_relaxed))) {
+ return os_unfair_lock_unlock_no_tsd(lock, mts);
+ }
+}
+
/*!
* @function os_unfair_lock_lock_inline
*
}
}
-/*!
- * @function os_unfair_lock_lock_inline_no_tsd_4libpthread
- *
- * @abstract
- * Locks an os_unfair_lock, without requiring valid TSD.
- *
- * This should only be used by libpthread.
- *
- * @param lock
- * Pointer to an os_unfair_lock.
- */
-OS_UNFAIR_LOCK_AVAILABILITY
-OS_INLINE OS_ALWAYS_INLINE OS_NONNULL_ALL
-void
-os_unfair_lock_lock_inline_no_tsd_4libpthread(os_unfair_lock_t lock)
-{
- uint32_t mts = MACH_PORT_DEAD;
- os_unfair_lock unlocked = OS_UNFAIR_LOCK_UNLOCKED, locked = { mts };
- if (!OSLOCK_STD(atomic_compare_exchange_strong_explicit)(
- (_os_atomic_unfair_lock*)lock, &unlocked, locked,
- OSLOCK_STD(memory_order_acquire),
- OSLOCK_STD(memory_order_relaxed))) {
- return os_unfair_lock_lock_no_tsd_4libpthread(lock);
- }
-}
-
-/*!
- * @function os_unfair_lock_unlock_inline_no_tsd_4libpthread
- *
- * @abstract
- * Unlocks an os_unfair_lock, without requiring valid TSD.
- *
- * This should only be used by libpthread.
- *
- * @param lock
- * Pointer to an os_unfair_lock.
- */
-OS_UNFAIR_LOCK_AVAILABILITY
-OS_INLINE OS_ALWAYS_INLINE OS_NONNULL_ALL
-void
-os_unfair_lock_unlock_inline_no_tsd_4libpthread(os_unfair_lock_t lock)
-{
- uint32_t mts = MACH_PORT_DEAD;
- os_unfair_lock unlocked = OS_UNFAIR_LOCK_UNLOCKED, locked = { mts };
- if (!OSLOCK_STD(atomic_compare_exchange_strong_explicit)(
- (_os_atomic_unfair_lock*)lock, &locked, unlocked,
- OSLOCK_STD(memory_order_release),
- OSLOCK_STD(memory_order_relaxed))) {
- return os_unfair_lock_unlock_no_tsd_4libpthread(lock);
- }
-}
-
OS_ASSUME_NONNULL_END
#undef OSLOCK_STD