#ifndef __SYS_LOCKDEBUG_H__
#define __SYS_LOCKDEBUG_H__
#ifdef _KERNEL_OPT
#include "opt_lockdebug.h"
#endif
#if !defined(_KERNEL) && !defined(_KMEMUSER)
#error "Sorry, nothing of interest to user level programs here."
#endif
#define LOCKOPS_SLEEP 0
#define LOCKOPS_SPIN 1
typedef void (*lockop_printer_t)(const char *, ...) __printflike(1, 2);
typedef struct lockops {
const char *lo_name;
int lo_type;
void (*lo_dump)(const volatile void *, lockop_printer_t);
} lockops_t;
#define LOCKDEBUG_ABORT(f, ln, l, o, m) \
lockdebug_abort(f, ln, l, o, m)
void lockdebug_dismiss(void);
void lockdebug_abort(const char *, size_t, const volatile void *,
lockops_t *, const char *);
void lockdebug_lock_print(void *, void (*)(const char *, ...)
__printflike(1, 2));
void lockdebug_show_all_locks(void (*)(const char *, ...) __printflike(1, 2),
const char *);
void lockdebug_show_lockstats(void (*)(const char *, ...) __printflike(1, 2));
#ifdef LOCKDEBUG
bool lockdebug_alloc(const char *, size_t, volatile void *, lockops_t *,
uintptr_t);
void lockdebug_free(const char *, size_t, volatile void *);
void lockdebug_wantlock(const char *, size_t, const volatile void *,
uintptr_t, int);
void lockdebug_locked(const char *, size_t, volatile void *, void *,
uintptr_t, int);
void lockdebug_unlocked(const char *, size_t, volatile void *,
uintptr_t, int);
void lockdebug_barrier(const char *, size_t, volatile void *, int);
void lockdebug_mem_check(const char *, size_t, void *, size_t);
#define LOCKDEBUG_ALLOC(lock, ops, addr) \
lockdebug_alloc(__func__, __LINE__, lock, ops, addr)
#define LOCKDEBUG_FREE(dodebug, lock) \
if (dodebug) lockdebug_free(__func__, __LINE__, lock)
#define LOCKDEBUG_WANTLOCK(dodebug, lock, where, s) \
if (dodebug) lockdebug_wantlock(__func__, __LINE__, lock, where, s)
#define LOCKDEBUG_LOCKED(dodebug, lock, al, where, s) \
if (dodebug) lockdebug_locked(__func__, __LINE__, lock, al, where, s)
#define LOCKDEBUG_UNLOCKED(dodebug, lock, where, s) \
if (dodebug) lockdebug_unlocked(__func__, __LINE__, lock, where, s)
#define LOCKDEBUG_BARRIER(lock, slp) \
lockdebug_barrier(__func__, __LINE__, lock, slp)
#define LOCKDEBUG_MEM_CHECK(base, sz) \
lockdebug_mem_check(__func__, __LINE__, base, sz)
#else
#define LOCKDEBUG_ALLOC(lock, ops, addr) false
#define LOCKDEBUG_FREE(dodebug, lock)
#define LOCKDEBUG_WANTLOCK(dodebug, lock, where, s)
#define LOCKDEBUG_LOCKED(dodebug, lock, al, where, s)
#define LOCKDEBUG_UNLOCKED(dodebug, lock, where, s)
#define LOCKDEBUG_BARRIER(lock, slp)
#define LOCKDEBUG_MEM_CHECK(base, sz)
#endif
#endif