FreeBSD kernel kern code
kern_sx.c File Reference
#include "opt_ddb.h"
#include "opt_hwpmc_hooks.h"
#include "opt_kdtrace.h"
#include "opt_no_adaptive_sx.h"
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kdb.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sleepqueue.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
Include dependency graph for kern_sx.c:

Go to the source code of this file.

Macros

#define SQ_EXCLUSIVE_QUEUE   0
 
#define SQ_SHARED_QUEUE   1
 
#define GIANT_DECLARE
 
#define GIANT_SAVE()
 
#define GIANT_RESTORE()
 
#define sx_recurse   lock_object.lo_data
 
#define sx_recursed(sx)   ((sx)->sx_recurse != 0)
 
#define _sx_assert(sx, what, file, line)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 CTASSERT ((SX_NOADAPTIVE &LO_CLASSFLAGS)==SX_NOADAPTIVE)
 
static void assert_sx (struct lock_object *lock, int what)
 
static void lock_sx (struct lock_object *lock, int how)
 
static int unlock_sx (struct lock_object *lock)
 
void sx_sysinit (void *arg)
 
void sx_init_flags (struct sx *sx, const char *description, int opts)
 
void sx_destroy (struct sx *sx)
 
int _sx_slock (struct sx *sx, int opts, const char *file, int line)
 
int _sx_try_slock (struct sx *sx, const char *file, int line)
 
int _sx_xlock (struct sx *sx, int opts, const char *file, int line)
 
int _sx_try_xlock (struct sx *sx, const char *file, int line)
 
void _sx_sunlock (struct sx *sx, const char *file, int line)
 
void _sx_xunlock (struct sx *sx, const char *file, int line)
 
int _sx_try_upgrade (struct sx *sx, const char *file, int line)
 
void _sx_downgrade (struct sx *sx, const char *file, int line)
 
int _sx_xlock_hard (struct sx *sx, uintptr_t tid, int opts, const char *file, int line)
 
void _sx_xunlock_hard (struct sx *sx, uintptr_t tid, const char *file, int line)
 
int _sx_slock_hard (struct sx *sx, int opts, const char *file, int line)
 
void _sx_sunlock_hard (struct sx *sx, const char *file, int line)
 

Variables

struct lock_class lock_class_sx
 

Macro Definition Documentation

#define _sx_assert (   sx,
  what,
  file,
  line 
)

Definition at line 145 of file kern_sx.c.

Referenced by _sx_downgrade(), _sx_sunlock(), _sx_try_upgrade(), and _sx_xunlock().

#define GIANT_DECLARE
Value:
int _giantcnt = 0; \
WITNESS_SAVE_DECL(Giant) \
struct mtx Giant
Definition: kern_mutex.c:140

Definition at line 90 of file kern_sx.c.

Referenced by _sx_slock_hard(), and _sx_xlock_hard().

#define GIANT_RESTORE ( )
Value:
do { \
if (_giantcnt > 0) { \
mtx_assert(&Giant, MA_NOTOWNED); \
while (_giantcnt--) \
mtx_lock(&Giant); \
WITNESS_RESTORE(&Giant.lock_object, Giant); \
} \
} while (0)
struct mtx Giant
Definition: kern_mutex.c:140

Definition at line 104 of file kern_sx.c.

Referenced by _sx_slock_hard(), and _sx_xlock_hard().

#define GIANT_SAVE ( )
Value:
do { \
if (mtx_owned(&Giant)) { \
WITNESS_SAVE(&Giant.lock_object, Giant); \
while (mtx_owned(&Giant)) { \
_giantcnt++; \
mtx_unlock(&Giant); \
} \
} \
} while (0)
struct mtx Giant
Definition: kern_mutex.c:140

Definition at line 94 of file kern_sx.c.

Referenced by _sx_slock_hard(), and _sx_xlock_hard().

#define SQ_EXCLUSIVE_QUEUE   0

Definition at line 78 of file kern_sx.c.

Referenced by _sx_sunlock_hard(), _sx_xlock_hard(), and _sx_xunlock_hard().

#define SQ_SHARED_QUEUE   1

Definition at line 79 of file kern_sx.c.

Referenced by _sx_downgrade(), _sx_slock_hard(), and _sx_xunlock_hard().

#define sx_recurse   lock_object.lo_data

Definition at line 117 of file kern_sx.c.

#define sx_recursed (   sx)    ((sx)->sx_recurse != 0)

Definition at line 118 of file kern_sx.c.

Referenced by _sx_downgrade(), _sx_try_xlock(), _sx_xunlock(), and _sx_xunlock_hard().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
void _sx_downgrade ( struct sx *  sx,
const char *  file,
int  line 
)

Definition at line 431 of file kern_sx.c.

References _sx_assert, panic(), sleepq_broadcast(), sleepq_lock(), sleepq_release(), SQ_SHARED_QUEUE, and sx_recursed.

Here is the call graph for this function:

int _sx_slock ( struct sx *  sx,
int  opts,
const char *  file,
int  line 
)

Definition at line 244 of file kern_sx.c.

References kdb_active.

int _sx_slock_hard ( struct sx *  sx,
int  opts,
const char *  file,
int  line 
)

Definition at line 794 of file kern_sx.c.

References GIANT_DECLARE, GIANT_RESTORE, GIANT_SAVE, sleepq_add(), sleepq_lock(), sleepq_release(), sleepq_wait(), sleepq_wait_sig(), SQ_SHARED_QUEUE, and waittime.

Here is the call graph for this function:

void _sx_sunlock ( struct sx *  sx,
const char *  file,
int  line 
)

Definition at line 359 of file kern_sx.c.

References _sx_assert.

void _sx_sunlock_hard ( struct sx *  sx,
const char *  file,
int  line 
)

Definition at line 991 of file kern_sx.c.

References sleepq_broadcast(), sleepq_lock(), sleepq_release(), and SQ_EXCLUSIVE_QUEUE.

Here is the call graph for this function:

int _sx_try_slock ( struct sx *  sx,
const char *  file,
int  line 
)

Definition at line 267 of file kern_sx.c.

References kdb_active.

int _sx_try_upgrade ( struct sx *  sx,
const char *  file,
int  line 
)

Definition at line 398 of file kern_sx.c.

References _sx_assert.

int _sx_try_xlock ( struct sx *  sx,
const char *  file,
int  line 
)

Definition at line 324 of file kern_sx.c.

References kdb_active, and sx_recursed.

int _sx_xlock ( struct sx *  sx,
int  opts,
const char *  file,
int  line 
)

Definition at line 299 of file kern_sx.c.

References kdb_active.

int _sx_xlock_hard ( struct sx *  sx,
uintptr_t  tid,
int  opts,
const char *  file,
int  line 
)

Definition at line 501 of file kern_sx.c.

References GIANT_DECLARE, GIANT_RESTORE, GIANT_SAVE, sleepq_add(), sleepq_lock(), sleepq_release(), sleepq_wait(), sleepq_wait_sig(), SQ_EXCLUSIVE_QUEUE, and waittime.

Here is the call graph for this function:

void _sx_xunlock ( struct sx *  sx,
const char *  file,
int  line 
)

Definition at line 375 of file kern_sx.c.

References _sx_assert, and sx_recursed.

void _sx_xunlock_hard ( struct sx *  sx,
uintptr_t  tid,
const char *  file,
int  line 
)

Definition at line 732 of file kern_sx.c.

References sleepq_broadcast(), sleepq_lock(), sleepq_release(), sleepq_sleepcnt(), SQ_EXCLUSIVE_QUEUE, SQ_SHARED_QUEUE, and sx_recursed.

Here is the call graph for this function:

void assert_sx ( struct lock_object *  lock,
int  what 
)
static

Definition at line 149 of file kern_sx.c.

CTASSERT ( (SX_NOADAPTIVE &LO_CLASSFLAGS)  = =SX_NOADAPTIVE)
void lock_sx ( struct lock_object *  lock,
int  how 
)
static

Definition at line 156 of file kern_sx.c.

void sx_destroy ( struct sx *  sx)

Definition at line 234 of file kern_sx.c.

References lock_destroy().

Referenced by ksem_module_destroy(), lf_advlockasync(), lf_purgelocks(), mqfs_uninit(), rm_destroy(), and sodealloc().

Here is the call graph for this function:

Here is the caller graph for this function:

void sx_init_flags ( struct sx *  sx,
const char *  description,
int  opts 
)

Definition at line 205 of file kern_sx.c.

References lock_init().

Referenced by pmc_init_sx(), rm_init_flags(), and sx_sysinit().

Here is the call graph for this function:

Here is the caller graph for this function:

void sx_sysinit ( void *  arg)

Definition at line 197 of file kern_sx.c.

References sx_init_flags().

Here is the call graph for this function:

int unlock_sx ( struct lock_object *  lock)
static

Definition at line 168 of file kern_sx.c.

Variable Documentation

struct lock_class lock_class_sx
Initial value:
= {
.lc_name = "sx",
.lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE,
.lc_assert = assert_sx,
.lc_lock = lock_sx,
.lc_unlock = unlock_sx,
}
static void lock_sx(struct lock_object *lock, int how)
Definition: kern_sx.c:156
static int unlock_sx(struct lock_object *lock)
Definition: kern_sx.c:168
static void assert_sx(struct lock_object *lock, int what)
Definition: kern_sx.c:149

Definition at line 130 of file kern_sx.c.