man.bsd.lv manual page server

Manual Page Search Parameters
CRIT_ENTER(9) Kernel Developer's Manual CRIT_ENTER(9)

crit_enter, crit_enter_gd, crit_enter_id, crit_exit, crit_exit_gd, crit_exit_identer and exit a critical section

#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);

The () 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, () and () 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.

Kernels compiled with DEBUG_CRIT_SECTIONS will report any () calls that are made from a different function than the crit_enter() that they are unnesting. The () and () 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 () 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.

April 10, 2010 DragonFly-5.6.1