SERIALIZER(9)

NAME
lwkt_serialize_init, lwkt_serialize_enter, lwkt_serialize_adaptive_enter, lwkt_serialize_try, lwkt_serialize_exit, lwkt_serialize_handler_enable, lwkt_serialize_handler_disable, lwkt_serialize_handler_call, lwkt_serialize_handler_try, LWKT_SERIALIZE_INITIALIZER, ASSERT_SERIALIZED, ASSERT_NOT_SERIALIZED - generic low level serializer

SYNOPSIS
#include <sys/serialize.h>
void
lwkt_serialize_init(lwkt_serialize_t s);
void
lwkt_serialize_enter(lwkt_serialize_t s);
void
lwkt_serialize_adaptive_enter(lwkt_serialize_t s);
int
lwkt_serialize_try(lwkt_serialize_t s);
void
lwkt_serialize_exit(lwkt_serialize_t s);
void
lwkt_serialize_handler_enable(lwkt_serialize_t s);
void
lwkt_serialize_handler_disable(lwkt_serialize_t s);
void
lwkt_serialize_handler_call(lwkt_serialize_t s, void (*func)(void *, void *), void *arg, void *frame);
int
lwkt_serialize_handler_try(lwkt_serialize_t s, void (*func)(void *, void *), void *arg, void *frame);

LWKT_SERIALIZE_INITIALIZER;
ASSERT_SERIALIZED(s);
ASSERT_NOT_SERIALIZED(s);

DESCRIPTION
The serializer API provides a fast locked-bus-cycle-based serialization facility that will serialize across blocking conditions. It is very similar to a lock but much faster for the common case.

This API was initially designed to be a replacement for SPL calls, but may be used whenever a low level exclusive lock (serialization) and/or interrupt/device interaction is required. If it is used by interrupt, callers should enter critical section to prevent the current thread holding the serializer being preempted by interrupt thread which may try to hold the same serializer. Unlike tokens this serialization is not safe from deadlocks nor is it recursive, and care must be taken when using it. Note that tsleep(9) will not release a serializer that is being held.

There are two primary facilities — the serializer facility itself and an integrated non-stackable interrupt handler disablement facility used by drivers.

lwkt_serialize_init(), lwkt_serialize_enter() and lwkt_serialize_exit() respectively initialize, hold and release the serializer s. lwkt_serialize_try() is a non-blocking version of lwkt_serialize_enter().

lwkt_serialize_adaptive_enter() is a special version of lwkt_serialize_enter() which will try to spin a bit before the current thread is put to sleep if the serializer s is contended. By default, lwkt_serialize_adaptive_enter() favors spinning over sleeping.

lwkt_serialize_handler_disable(), lwkt_serialize_handler_enable() and lwkt_serialize_handler_call() respectively disable, enable and call an interrupt handler func for the serializer s. The arguments arg and frame will be passed to the handler. lwkt_serialize_handler_try() is a non-blocking version of lwkt_serialize_handler_call().

The macro LWKT_SERIALIZE_INITIALIZER evaluates to an initializer for the serializer.

The ASSERT_SERIALIZED() and ASSERT_NOT_SERIALIZED() macros assert that the serializer s is being held/not held.

RETURN VALUES
The lwkt_serialize_handler_try() function return 0 on success and 1 on failure. The lwkt_serialize_try() function return 1 on success and 0 on failure.

FILES
The serializer itself is implemented in /sys/kern/lwkt_serialize.c. The header file /sys/sys/serialize.h describes the public interface and the structure of a serializer.

SEE ALSO
crit_enter(9), locking(9), spinlock(9), zsleep(9)

HISTORY
The serializer API first appeared in DragonFly 1.3.

AUTHORS
-nosplit The serializer API was written by Matt Dillon. This manual page was written by Hasso Tepper.