FreeBSD kernel kern code
kern_rwlock.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include "opt_hwpmc_hooks.h"
#include "opt_kdtrace.h"
#include "opt_no_adaptive_rwlocks.h"
#include <sys/param.h>
#include <sys/kdb.h>
#include <sys/ktr.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/rwlock.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/turnstile.h>
#include <machine/cpu.h>
Include dependency graph for kern_rwlock.c:

Go to the source code of this file.

Macros

#define rw_wowner(rw)
 
#define rw_recursed(rw)   ((rw)->rw_recurse != 0)
 
#define rw_wlocked(rw)   (rw_wowner((rw)) == curthread)
 
#define rw_owner(rw)   rw_wowner(rw)
 
#define _rw_assert(rw, what, file, line)
 
#define RW_CAN_READ(_rw)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static void assert_rw (struct lock_object *lock, int what)
 
static void lock_rw (struct lock_object *lock, int how)
 
static int unlock_rw (struct lock_object *lock)
 
void rw_init_flags (struct rwlock *rw, const char *name, int opts)
 
void rw_destroy (struct rwlock *rw)
 
void rw_sysinit (void *arg)
 
void rw_sysinit_flags (void *arg)
 
int rw_wowned (struct rwlock *rw)
 
void _rw_wlock (struct rwlock *rw, const char *file, int line)
 
int _rw_try_wlock (struct rwlock *rw, const char *file, int line)
 
void _rw_wunlock (struct rwlock *rw, const char *file, int line)
 
void _rw_rlock (struct rwlock *rw, const char *file, int line)
 
int _rw_try_rlock (struct rwlock *rw, const char *file, int line)
 
void _rw_runlock (struct rwlock *rw, const char *file, int line)
 
void _rw_wlock_hard (struct rwlock *rw, uintptr_t tid, const char *file, int line)
 
void _rw_wunlock_hard (struct rwlock *rw, uintptr_t tid, const char *file, int line)
 
int _rw_try_upgrade (struct rwlock *rw, const char *file, int line)
 
void _rw_downgrade (struct rwlock *rw, const char *file, int line)
 

Variables

struct lock_class lock_class_rw
 

Macro Definition Documentation

#define _rw_assert (   rw,
  what,
  file,
  line 
)

Definition at line 120 of file kern_rwlock.c.

Referenced by _rw_downgrade(), _rw_runlock(), _rw_try_upgrade(), and _rw_wunlock().

#define RW_CAN_READ (   _rw)
Value:
((curthread->td_rw_rlocks && (_rw) & RW_LOCK_READ) || ((_rw) & \
(RW_LOCK_READ | RW_LOCK_WRITE_WAITERS | RW_LOCK_WRITE_SPINNER)) == \
RW_LOCK_READ)

Definition at line 309 of file kern_rwlock.c.

Referenced by _rw_rlock().

#define rw_owner (   rw)    rw_wowner(rw)

Definition at line 117 of file kern_rwlock.c.

Referenced by _rw_rlock(), and _rw_wlock_hard().

#define rw_recursed (   rw)    ((rw)->rw_recurse != 0)

Definition at line 105 of file kern_rwlock.c.

Referenced by _rw_downgrade(), _rw_try_wlock(), _rw_wunlock(), and _rw_wunlock_hard().

#define rw_wlocked (   rw)    (rw_wowner((rw)) == curthread)

Definition at line 110 of file kern_rwlock.c.

Referenced by _rw_try_wlock(), _rw_wlock_hard(), and _rw_wunlock_hard().

#define rw_wowner (   rw)
Value:
((rw)->rw_lock & RW_LOCK_READ ? NULL : \
(struct thread *)RW_OWNER((rw)->rw_lock))

Definition at line 97 of file kern_rwlock.c.

Referenced by _rw_rlock(), and rw_wowned().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
void _rw_downgrade ( struct rwlock *  rw,
const char *  file,
int  line 
)
void _rw_rlock ( struct rwlock *  rw,
const char *  file,
int  line 
)

Definition at line 315 of file kern_rwlock.c.

References kdb_active, RW_CAN_READ, rw_owner, rw_wowner, ts, turnstile_cancel(), turnstile_trywait(), turnstile_wait(), and waittime.

Here is the call graph for this function:

void _rw_runlock ( struct rwlock *  rw,
const char *  file,
int  line 
)

Definition at line 563 of file kern_rwlock.c.

References _rw_assert, ts, turnstile_broadcast(), turnstile_chain_lock(), turnstile_chain_unlock(), turnstile_lookup(), and turnstile_unpend().

Here is the call graph for this function:

int _rw_try_rlock ( struct rwlock *  rw,
const char *  file,
int  line 
)

Definition at line 529 of file kern_rwlock.c.

References kdb_active.

int _rw_try_upgrade ( struct rwlock *  rw,
const char *  file,
int  line 
)

Definition at line 934 of file kern_rwlock.c.

References _rw_assert, ts, turnstile_cancel(), turnstile_claim(), and turnstile_trywait().

Here is the call graph for this function:

int _rw_try_wlock ( struct rwlock *  rw,
const char *  file,
int  line 
)

Definition at line 252 of file kern_rwlock.c.

References kdb_active, rw_recursed, and rw_wlocked.

void _rw_wlock ( struct rwlock *  rw,
const char *  file,
int  line 
)

Definition at line 233 of file kern_rwlock.c.

References kdb_active.

void _rw_wlock_hard ( struct rwlock *  rw,
uintptr_t  tid,
const char *  file,
int  line 
)

Definition at line 677 of file kern_rwlock.c.

References rw_owner, rw_wlocked, ts, turnstile_cancel(), turnstile_claim(), turnstile_trywait(), turnstile_wait(), and waittime.

Here is the call graph for this function:

void _rw_wunlock ( struct rwlock *  rw,
const char *  file,
int  line 
)

Definition at line 286 of file kern_rwlock.c.

References _rw_assert, and rw_recursed.

void _rw_wunlock_hard ( struct rwlock *  rw,
uintptr_t  tid,
const char *  file,
int  line 
)

Definition at line 869 of file kern_rwlock.c.

References rw_recursed, rw_wlocked, ts, turnstile_broadcast(), turnstile_chain_lock(), turnstile_chain_unlock(), turnstile_lookup(), and turnstile_unpend().

Here is the call graph for this function:

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

Definition at line 124 of file kern_rwlock.c.

void lock_rw ( struct lock_object *  lock,
int  how 
)
static

Definition at line 131 of file kern_rwlock.c.

void rw_destroy ( struct rwlock *  rw)

Definition at line 200 of file kern_rwlock.c.

References lock_destroy().

Here is the call graph for this function:

void rw_init_flags ( struct rwlock *  rw,
const char *  name,
int  opts 
)

Definition at line 172 of file kern_rwlock.c.

References lock_class_rw, and lock_init().

Referenced by rw_sysinit_flags().

Here is the call graph for this function:

Here is the caller graph for this function:

void rw_sysinit ( void *  arg)

Definition at line 210 of file kern_rwlock.c.

void rw_sysinit_flags ( void *  arg)

Definition at line 218 of file kern_rwlock.c.

References rw_init_flags().

Here is the call graph for this function:

int rw_wowned ( struct rwlock *  rw)

Definition at line 226 of file kern_rwlock.c.

References rw_wowner.

int unlock_rw ( struct lock_object *  lock)
static

Definition at line 143 of file kern_rwlock.c.

Variable Documentation

struct lock_class lock_class_rw
Initial value:
= {
.lc_name = "rw",
.lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE,
.lc_assert = assert_rw,
.lc_lock = lock_rw,
.lc_unlock = unlock_rw,
}
static void lock_rw(struct lock_object *lock, int how)
Definition: kern_rwlock.c:131
static void assert_rw(struct lock_object *lock, int what)
Definition: kern_rwlock.c:124
static int unlock_rw(struct lock_object *lock)
Definition: kern_rwlock.c:143

Definition at line 79 of file kern_rwlock.c.

Referenced by rw_init_flags().