Virtio_Balloon implementation for DragonFly
[dragonfly.git] / sys / sys / serialize2.h
1 #ifndef _SYS_SERIALIZE2_H_
2 #define _SYS_SERIALIZE2_H_
3
4 #ifndef _KERNEL
5 #error "kernel only header file"
6 #endif
7
8 #ifndef _SYS_PARAM_H_
9 #include <sys/param.h>
10 #endif
11
12 #ifndef _SYS_SYSTM_H_
13 #include <sys/systm.h>
14 #endif
15
16 #ifndef _SYS_SERIALIZE_H_
17 #include <sys/serialize.h>
18 #endif
19
20 static __inline void
21 lwkt_serialize_array_enter(lwkt_serialize_t *_arr, int _arrcnt, int _s)
22 {
23         KASSERT(_s < _arrcnt, ("nothing to be serialized"));
24         while (_s < _arrcnt)
25                 lwkt_serialize_enter(_arr[_s++]);
26 }
27
28 static __inline int
29 lwkt_serialize_array_try(lwkt_serialize_t *_arr, int _arrcnt, int _s)
30 {
31         int _i;
32
33         KASSERT(_s < _arrcnt, ("nothing to be serialized"));
34         for (_i = _s; _i < _arrcnt; ++_i) {
35                 if (!lwkt_serialize_try(_arr[_i])) {
36                         while (--_i >= _s)
37                                 lwkt_serialize_exit(_arr[_i]);
38                         return 0;
39                 }
40         }
41         return 1;
42 }
43
44 static __inline void
45 lwkt_serialize_array_exit(lwkt_serialize_t *_arr, int _arrcnt, int _s)
46 {
47         KASSERT(_arrcnt > _s, ("nothing to be deserialized"));
48         while (--_arrcnt >= _s)
49                 lwkt_serialize_exit(_arr[_arrcnt]);
50 }
51
52 #endif  /* !_SYS_SERIALIZE2_H_ */