DragonFly On-Line Manual Pages
CRIT_ENTER(9) DragonFly Kernel Developer's Manual CRIT_ENTER(9)
NAME
crit_enter, crit_enter_gd, crit_enter_id, crit_exit, crit_exit_gd,
crit_exit_id -- enter and exit a critical section
SYNOPSIS
#include <sys/thread2.h>
void
crit_enter(void);
void
crit_exit(void);
void
crit_enter_gd(globaldata_t gd);
void
crit_exit_gd(globaldata_t gd);
void
crit_enter_id(const char *id);
void
crit_exit_id(const char *id);
DESCRIPTION
The crit_enter() and crit_exit() functions are used to enter and exit a
critical section of code. Entering a critical section will disallow
preemption of the currently running thread on the current CPU for the
duration of the critical section. While a critical section is active,
interrupts and IPIs are also prevented from executing on the current CPU.
Instead, the interrupt code marks the interrupt as deferred and
immediately returns (without scheduling any interrupt thread). If an
interrupt or an IPI is deferred in this way, it will be processed upon
leaving the critical section.
It is possible for a thread to sleep while holding a critical section,
however this results in the critical section being given up for the time
of the sleep and being reacquired after waking up.
If the current CPU's globaldata pointer is available, crit_enter_gd() and
crit_exit_gd() may be used to reduce the amount of generated code.
Critical sections are per-CPU entities. They are typically used to
interlock operations local to the CPU. A critical section on one CPU
will not prevent an interrupt or IPI from occurring on some other CPU.
If cross-CPU interlocks are required the more heavy weight spinlock(9) or
serializer(9) lock is recommended instead.
Unlike spinlocks and serializer locks, critical sections can be nested.
DEBUGGING CRITICAL SECTIONS
Kernels compiled with DEBUG_CRIT_SECTIONS will report any crit_exit()
calls that are made from a different function than the crit_enter() that
they are unnesting. The crit_enter_id() and crit_exit_id() functions can
be used to specify a fixed ID in cases where this is done on purpose.
Identifiers must be string pointers but the debug code only checks the
pointer address, it does not do a strcmp() to validate the ID.
FILES
The critical section implementation is in /sys/sys/thread2.h.
SEE ALSO
locking(9), serializer(9), spinlock(9)
HISTORY
These functions were introduced in DragonFly 1.0.
DragonFly 5.5 April 10, 2010 DragonFly 5.5