#ifdef KERNEL_PRIVATE
#ifndef _KERN_SIMPLE_LOCK_H_
#define _KERN_SIMPLE_LOCK_H_
#include <sys/cdefs.h>
#include <mach/boolean.h>
#include <kern/kern_types.h>
#include <kern/lock_group.h>
#include <machine/simple_lock.h>
#ifdef MACH_KERNEL_PRIVATE
#include <machine/atomic.h>
#include <mach_ldebug.h>
extern void hw_lock_init(
hw_lock_t);
#if LOCK_STATS
extern void hw_lock_lock(
hw_lock_t,
lck_grp_t*);
extern void hw_lock_lock_nopreempt(
hw_lock_t,
lck_grp_t*);
extern unsigned int hw_lock_to(
hw_lock_t,
uint64_t,
lck_grp_t*);
extern unsigned int hw_lock_try(
hw_lock_t,
lck_grp_t*);
extern unsigned int hw_lock_try_nopreempt(
hw_lock_t,
lck_grp_t*);
#else
extern void hw_lock_lock(
hw_lock_t);
#define hw_lock_lock(lck, grp) hw_lock_lock(lck)
extern void hw_lock_lock_nopreempt(
hw_lock_t);
#define hw_lock_lock_nopreempt(lck, grp) hw_lock_lock_nopreempt(lck)
extern unsigned int hw_lock_to(
hw_lock_t,
uint64_t);
#define hw_lock_to(lck, timeout, grp) hw_lock_to(lck, timeout)
extern unsigned int hw_lock_try(
hw_lock_t);
#define hw_lock_try(lck, grp) hw_lock_try(lck)
extern unsigned int hw_lock_try_nopreempt(
hw_lock_t);
#define hw_lock_try_nopreempt(lck, grp) hw_lock_try_nopreempt(lck)
#endif
extern void hw_lock_unlock(
hw_lock_t);
extern void hw_lock_unlock_nopreempt(
hw_lock_t);
extern unsigned int hw_lock_held(
hw_lock_t);
extern boolean_t hw_atomic_test_and_set32(
uint32_t *target,
uint32_t test_mask,
uint32_t set_mask,
enum memory_order ord,
boolean_t wait);
#endif
#if XNU_KERNEL_PRIVATE
struct usimple_lock_startup_spec {
usimple_lock_t lck;
unsigned short lck_init_arg;
};
extern void usimple_lock_startup_init(
struct usimple_lock_startup_spec *spec);
#define SIMPLE_LOCK_DECLARE(var, arg) \
decl_simple_lock_data(, var); \
static __startup_data struct usimple_lock_startup_spec \
__startup_usimple_lock_spec_ ## var = { &var, arg }; \
STARTUP_ARG(LOCKS_EARLY, STARTUP_RANK_FOURTH, usimple_lock_startup_init, \
&__startup_usimple_lock_spec_ ## var)
#endif
__BEGIN_DECLS
extern void * hw_wait_while_equals(
void **address,
void *current);
extern void usimple_lock_init(
usimple_lock_t,
unsigned short);
#if LOCK_STATS
extern void usimple_lock(
usimple_lock_t,
lck_grp_t*);
extern unsigned int usimple_lock_try(
usimple_lock_t,
lck_grp_t*);
extern void usimple_lock_try_lock_loop(
usimple_lock_t,
lck_grp_t*);
#if defined(__x86_64__)
extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
usimple_lock_t,
uint64_t,
lck_grp_t*);
extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
usimple_lock_t,
uint64_t,
lck_grp_t*);
#endif
#else
extern void usimple_lock(
usimple_lock_t);
#define usimple_lock(lck, grp) usimple_lock(lck)
extern unsigned int usimple_lock_try(
usimple_lock_t);
#define usimple_lock_try(lck, grp) usimple_lock_try(lck)
extern void usimple_lock_try_lock_loop(
usimple_lock_t);
#define usimple_lock_try_lock_loop(lck, grp) usimple_lock_try_lock_loop(lck)
#if defined(__x86_64__)
extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_deadline(
usimple_lock_t,
uint64_t);
#define usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl, grp) usimple_lock_try_lock_mp_signal_safe_loop_deadline(lck, ddl)
extern unsigned int usimple_lock_try_lock_mp_signal_safe_loop_duration(
usimple_lock_t,
uint64_t);
#define usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur, grp) usimple_lock_try_lock_mp_signal_safe_loop_duration(lck, dur)
#endif
#endif
extern void usimple_unlock(
usimple_lock_t);
__END_DECLS
#define ETAP_NO_TRACE 0
#define ETAP_IO_AHA 0
#if !defined(simple_lock_init)
#define simple_lock_init(l, t) usimple_lock_init(l,t)
#define simple_lock(l, grp) usimple_lock(l, grp)
#define simple_unlock(l) usimple_unlock(l)
#define simple_lock_try(l, grp) usimple_lock_try(l, grp)
#define simple_lock_try_lock_loop(l, grp) usimple_lock_try_lock_loop(l, grp)
#define simple_lock_try_lock_mp_signal_safe_loop_deadline(l, ddl, grp) usimple_lock_try_lock_mp_signal_safe_loop_deadline(l, ddl, grp)
#define simple_lock_try_lock_mp_signal_safe_loop_duration(l, dur, grp) usimple_lock_try_lock_mp_signal_safe_loop_duration(l, dur, grp)
#define simple_lock_addr(l) (&(l))
#endif
#ifdef MACH_KERNEL_PRIVATE
typedef uint32_t hw_lock_bit_t;
#if LOCK_STATS
extern void hw_lock_bit(
hw_lock_bit_t *,
unsigned int,
lck_grp_t*);
extern void hw_lock_bit_nopreempt(
hw_lock_bit_t *,
unsigned int,
lck_grp_t*);
extern unsigned int hw_lock_bit_try(
hw_lock_bit_t *,
unsigned int,
lck_grp_t*);
extern unsigned int hw_lock_bit_to(
hw_lock_bit_t *,
unsigned int,
uint32_t,
lck_grp_t*);
#else
extern void hw_lock_bit(
hw_lock_bit_t *,
unsigned int);
#define hw_lock_bit(lck, bit, grp) hw_lock_bit(lck, bit)
extern void hw_lock_bit_nopreempt(
hw_lock_bit_t *,
unsigned int);
#define hw_lock_bit_nopreempt(lck, bit, grp) hw_lock_bit_nopreempt(lck, bit)
extern unsigned int hw_lock_bit_try(
hw_lock_bit_t *,
unsigned int);
#define hw_lock_bit_try(lck, bit, grp) hw_lock_bit_try(lck, bit)
extern unsigned int hw_lock_bit_to(
hw_lock_bit_t *,
unsigned int,
uint32_t);
#define hw_lock_bit_to(lck, bit, timeout, grp) hw_lock_bit_to(lck, bit, timeout)
#endif
extern void hw_unlock_bit(
hw_lock_bit_t *,
unsigned int);
extern void hw_unlock_bit_nopreempt(
hw_lock_bit_t *,
unsigned int);
#define hw_lock_bit_held(l, b) (((*(l))&(1<<b))!=0)
#endif
#endif
#endif