1381 WNode h; // Possibly release first waiter
1382 while ((h = whead) != null) {
1383 long s; WNode q; // similar to release() but check eligibility
1384 if ((q = h.next) == null || q.status == CANCELLED) {
1385 for (WNode t = wtail; t != null && t != h; t = t.prev)
1386 if (t.status <= 0)
1387 q = t;
1388 }
1389 if (h == whead) {
1390 if (q != null && h.status == 0 &&
1391 ((s = state) & ABITS) != WBIT && // waiter is eligible
1392 (s == 0L || q.mode == RMODE))
1393 release(h);
1394 break;
1395 }
1396 }
1397 return (interrupted || Thread.interrupted()) ? INTERRUPTED : 0L;
1398 }
1399
1400 // Unsafe mechanics
1401 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
1402 private static final long STATE;
1403 private static final long WHEAD;
1404 private static final long WTAIL;
1405 private static final long WNEXT;
1406 private static final long WSTATUS;
1407 private static final long WCOWAIT;
1408 private static final long PARKBLOCKER;
1409
1410 static {
1411 try {
1412 STATE = U.objectFieldOffset
1413 (StampedLock.class.getDeclaredField("state"));
1414 WHEAD = U.objectFieldOffset
1415 (StampedLock.class.getDeclaredField("whead"));
1416 WTAIL = U.objectFieldOffset
1417 (StampedLock.class.getDeclaredField("wtail"));
1418
1419 WSTATUS = U.objectFieldOffset
1420 (WNode.class.getDeclaredField("status"));
1421 WNEXT = U.objectFieldOffset
|
1381 WNode h; // Possibly release first waiter
1382 while ((h = whead) != null) {
1383 long s; WNode q; // similar to release() but check eligibility
1384 if ((q = h.next) == null || q.status == CANCELLED) {
1385 for (WNode t = wtail; t != null && t != h; t = t.prev)
1386 if (t.status <= 0)
1387 q = t;
1388 }
1389 if (h == whead) {
1390 if (q != null && h.status == 0 &&
1391 ((s = state) & ABITS) != WBIT && // waiter is eligible
1392 (s == 0L || q.mode == RMODE))
1393 release(h);
1394 break;
1395 }
1396 }
1397 return (interrupted || Thread.interrupted()) ? INTERRUPTED : 0L;
1398 }
1399
1400 // Unsafe mechanics
1401 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
1402 private static final long STATE;
1403 private static final long WHEAD;
1404 private static final long WTAIL;
1405 private static final long WNEXT;
1406 private static final long WSTATUS;
1407 private static final long WCOWAIT;
1408 private static final long PARKBLOCKER;
1409
1410 static {
1411 try {
1412 STATE = U.objectFieldOffset
1413 (StampedLock.class.getDeclaredField("state"));
1414 WHEAD = U.objectFieldOffset
1415 (StampedLock.class.getDeclaredField("whead"));
1416 WTAIL = U.objectFieldOffset
1417 (StampedLock.class.getDeclaredField("wtail"));
1418
1419 WSTATUS = U.objectFieldOffset
1420 (WNode.class.getDeclaredField("status"));
1421 WNEXT = U.objectFieldOffset
|