-
Notifications
You must be signed in to change notification settings - Fork 1
/
SegmentPool.java
62 lines (55 loc) · 1.55 KB
/
SegmentPool.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.jiuyan.infashion.lib.publish.story;
/**
* Created by Adrian on 2016/4/16.
* E-mail:[email protected]
*/
public class SegmentPool {
static final long MAX_SIZE = 65536L;
static Segment next;
static long byteCount;
private SegmentPool() {
}
static Segment take() {
Class var0 = SegmentPool.class;
synchronized (SegmentPool.class) {
if (next != null) {
Segment result = next;
next = result.next;
result.next = null;
byteCount -= 2048L;
return result;
}
}
return new Segment();
}
static void recycle(Segment segment) {
if (segment.next == null && segment.prev == null) {
if (!segment.shared) {
Class var1 = SegmentPool.class;
synchronized (SegmentPool.class) {
if (byteCount + 2048L <= 65536L) {
byteCount += 2048L;
segment.next = next;
next = segment;
}
}
}
} else {
throw new IllegalArgumentException();
}
}
static class Segment {
/**
* True if other segments or byte strings use the same byte array.
*/
boolean shared;
/**
* Next segment in a linked or circularly-linked list.
*/
Segment next;
/**
* Previous segment in a circularly-linked list.
*/
Segment prev;
}
}