48 private static final int NOT_COMPENSATING = 0;
49 private static final int COMPENSATE_IN_PROGRESS = 1;
50 private static final int COMPENSATING = 2;
51 private int compensating;
52
53 // FJP value to adjust release counts
54 private long compensateValue;
55
56 @SuppressWarnings("this-escape")
57 public CarrierThread(ForkJoinPool pool) {
58 super(CARRIER_THREADGROUP, pool, true);
59 U.putReference(this, CONTEXTCLASSLOADER, ClassLoader.getSystemClassLoader());
60 U.putReference(this, INHERITABLETHREADLOCALS, null);
61 }
62
63 /**
64 * Mark the start of a blocking operation.
65 */
66 public boolean beginBlocking() {
67 assert Thread.currentThread().isVirtual() && JLA.currentCarrierThread() == this;
68 assert compensating == NOT_COMPENSATING || compensating == COMPENSATING;
69
70 if (compensating == NOT_COMPENSATING) {
71 // don't preempt when attempting to compensate
72 Continuation.pin();
73 try {
74 compensating = COMPENSATE_IN_PROGRESS;
75
76 // Uses FJP.tryCompensate to start or re-activate a spare thread
77 compensateValue = ForkJoinPools.beginCompensatedBlock(getPool());
78 compensating = COMPENSATING;
79 return true;
80 } catch (Throwable e) {
81 // exception starting spare thread
82 compensating = NOT_COMPENSATING;
83 throw e;
84 } finally {
85 Continuation.unpin();
86 }
87 } else {
88 return false;
|
48 private static final int NOT_COMPENSATING = 0;
49 private static final int COMPENSATE_IN_PROGRESS = 1;
50 private static final int COMPENSATING = 2;
51 private int compensating;
52
53 // FJP value to adjust release counts
54 private long compensateValue;
55
56 @SuppressWarnings("this-escape")
57 public CarrierThread(ForkJoinPool pool) {
58 super(CARRIER_THREADGROUP, pool, true);
59 U.putReference(this, CONTEXTCLASSLOADER, ClassLoader.getSystemClassLoader());
60 U.putReference(this, INHERITABLETHREADLOCALS, null);
61 }
62
63 /**
64 * Mark the start of a blocking operation.
65 */
66 public boolean beginBlocking() {
67 assert Thread.currentThread().isVirtual() && JLA.currentCarrierThread() == this;
68
69 if (compensating == NOT_COMPENSATING) {
70 // don't preempt when attempting to compensate
71 Continuation.pin();
72 try {
73 compensating = COMPENSATE_IN_PROGRESS;
74
75 // Uses FJP.tryCompensate to start or re-activate a spare thread
76 compensateValue = ForkJoinPools.beginCompensatedBlock(getPool());
77 compensating = COMPENSATING;
78 return true;
79 } catch (Throwable e) {
80 // exception starting spare thread
81 compensating = NOT_COMPENSATING;
82 throw e;
83 } finally {
84 Continuation.unpin();
85 }
86 } else {
87 return false;
|