1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.uring;
17
18 import java.util.Arrays;
19
20 final class MsgHdrMemoryArray {
21 static final long NO_ID = 0;
22
23 private final MsgHdrMemory[] hdrs;
24 private final int capacity;
25 private final long[] ids;
26 private boolean released;
27 private int idx;
28
29 MsgHdrMemoryArray(short capacity) {
30 assert capacity >= 0;
31 this.capacity = capacity;
32 hdrs = new MsgHdrMemory[capacity];
33 ids = new long[capacity];
34 for (int i = 0; i < hdrs.length; i++) {
35 hdrs[i] = new MsgHdrMemory((short) i);
36 ids[i] = NO_ID;
37 }
38 }
39
40 MsgHdrMemory nextHdr() {
41 if (idx == hdrs.length) {
42 return null;
43 }
44 return hdrs[idx++];
45 }
46
47 MsgHdrMemory hdr(int idx) {
48 return hdrs[idx];
49 }
50
51 long id(int idx) {
52 return ids[idx];
53 }
54
55 void setId(int idx, long id) {
56 ids[idx] = id;
57 }
58
59 void clear() {
60 Arrays.fill(ids, 0, idx, NO_ID);
61 idx = 0;
62 }
63
64 int length() {
65 return idx;
66 }
67
68 void release() {
69 assert !released;
70 released = true;
71 for (MsgHdrMemory hdr: hdrs) {
72 hdr.release();
73 }
74 }
75
76 int capacity() {
77 return capacity;
78 }
79 }