kernel: Make SMP support default (and non-optional).
[dragonfly.git] / sys / sys / serialize.h
CommitLineData
e9cb6d99
MD
1/*
2 * Provides a fast serialization facility that will serialize across blocking
3 * conditions. This facility is very similar to a lock but much faster for
4 * the common case. It utilizes the atomic_intr_*() functions to acquire
5 * and release the serializer and token functions to block.
6 *
7 * This API is designed to be used whenever low level serialization is
8 * required. Unlike tokens this serialization is not safe from deadlocks
9 * nor is it recursive, and care must be taken when using it.
e9cb6d99
MD
10 */
11
12#ifndef _SYS_SERIALIZE_H_
13#define _SYS_SERIALIZE_H_
14
aa368711 15#include <machine/stdint.h>
e9cb6d99
MD
16
17struct thread;
18
19struct lwkt_serialize {
aa368711 20 __atomic_intr_t interlock;
e9cb6d99
MD
21 struct thread *last_td;
22};
23
d9a87b93
MD
24#define LWKT_SERIALIZE_INITIALIZER { 0, NULL }
25
dcad4d19 26#ifdef INVARIANTS
dcad4d19
SZ
27/*
28 * Note that last_td is only maintained when INVARIANTS is turned on,
29 * so this check is only useful as part of a [K]KASSERT.
30 */
9db4b353 31#define IS_SERIALIZED(ss) ((ss)->last_td == curthread)
710e21de
SZ
32#endif
33
9db4b353
SZ
34#define ASSERT_SERIALIZED(ss) KKASSERT(IS_SERIALIZED((ss)))
35#define ASSERT_NOT_SERIALIZED(ss) KKASSERT(!IS_SERIALIZED((ss)))
3e086307 36
e9cb6d99
MD
37typedef struct lwkt_serialize *lwkt_serialize_t;
38
39void lwkt_serialize_init(lwkt_serialize_t);
40void lwkt_serialize_enter(lwkt_serialize_t);
d1d48a34 41void lwkt_serialize_adaptive_enter(lwkt_serialize_t);
3e086307 42int lwkt_serialize_try(lwkt_serialize_t);
e9cb6d99
MD
43void lwkt_serialize_exit(lwkt_serialize_t);
44void lwkt_serialize_handler_disable(lwkt_serialize_t);
45void lwkt_serialize_handler_enable(lwkt_serialize_t);
477d3c1c
MD
46void lwkt_serialize_handler_call(lwkt_serialize_t, void (*)(void *, void *), void *, void *);
47int lwkt_serialize_handler_try(lwkt_serialize_t, void (*)(void *, void *), void *, void *);
e9cb6d99 48
9db4b353 49#endif /* !_SYS_SERIALIZE_H_ */