Add counters for serializer enter/try
[dragonfly.git] / sys / sys / serialize.h
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. 
10  *
11  * $DragonFly: src/sys/sys/serialize.h,v 1.7 2008/04/03 12:55:15 sephe Exp $
12  */
13
14 #ifndef _SYS_SERIALIZE_H_
15 #define _SYS_SERIALIZE_H_
16
17 #ifndef _MACHINE_STDINT_H_
18 #include <machine/stdint.h>
19 #endif
20
21 struct thread;
22
23 struct lwkt_serialize {
24     __atomic_intr_t     interlock;
25     struct thread       *last_td;
26     unsigned int        sleep_cnt;
27     unsigned int        tryfail_cnt;
28     unsigned int        enter_cnt;
29     unsigned int        try_cnt;
30 };
31
32 /*
33  * Note that last_td is only maintained when INVARIANTS is turned on,
34  * so this check is only useful as part of a [K]KASSERT.
35  */
36 #define ASSERT_SERIALIZED(ss)           KKASSERT((ss)->last_td == curthread)
37 #define ASSERT_NOT_SERIALIZED(ss)       KKASSERT((ss)->last_td != curthread)
38
39 typedef struct lwkt_serialize *lwkt_serialize_t;
40
41 void lwkt_serialize_init(lwkt_serialize_t);
42 void lwkt_serialize_enter(lwkt_serialize_t);
43 int lwkt_serialize_try(lwkt_serialize_t);
44 void lwkt_serialize_exit(lwkt_serialize_t);
45 void lwkt_serialize_handler_disable(lwkt_serialize_t);
46 void lwkt_serialize_handler_enable(lwkt_serialize_t);
47 void lwkt_serialize_handler_call(lwkt_serialize_t, void (*)(void *, void *), void *, void *);
48 int lwkt_serialize_handler_try(lwkt_serialize_t, void (*)(void *, void *), void *, void *);
49
50 #endif