DragonFly On-Line Manual Pages
CRIT_ENTER(9) DragonFly Kernel Developer's Manual CRIT_ENTER(9)
crit_enter, crit_enter_gd, crit_enter_id, crit_exit, crit_exit_gd,
crit_exit_id -- enter and exit a critical section
crit_enter_id(const char *id);
crit_exit_id(const char *id);
The crit_enter() and crit_exit() functions are used to enter and exit a
critical section of code. Entering a critical section will disallow pre-
emption of the currently running thread on the current CPU for the dura-
tion of the critical section. While a critical section is active, inter-
rupts and IPIs are also prevented from executing on the current CPU.
Instead, the interrupt code marks the interrupt as deferred and immedi-
ately returns (without scheduling any interrupt thread). If an interrupt
or an IPI is deferred in this way, it will be processed upon leaving the
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.
The critical section implementation is in /sys/sys/thread2.h.
locking(9), serializer(9), spinlock(9)
These functions were introduced in DragonFly 1.0.
DragonFly 4.1 April 10, 2010 DragonFly 4.1