aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0007-ConcurrentUtil.patch
blob: c2bb4af3359e2675ef4bb0fb03f316814e7cbad0 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 23 Jan 2022 22:58:11 -0800
Subject: [PATCH] ConcurrentUtil


diff --git a/src/main/java/ca/spottedleaf/concurrentutil/collection/MultiThreadedQueue.java b/src/main/java/ca/spottedleaf/concurrentutil/collection/MultiThreadedQueue.java
new file mode 100644
index 0000000000000000000000000000000000000000..f4415f782b32fed25da98e44b172f717c4d46e34
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/collection/MultiThreadedQueue.java
@@ -0,0 +1,1402 @@
+package ca.spottedleaf.concurrentutil.collection;
+
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import ca.spottedleaf.concurrentutil.util.Validate;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Queue;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Consumer;
+import java.util.function.IntFunction;
+import java.util.function.Predicate;
+
+/**
+ * MT-Safe linked first in first out ordered queue.
+ *
+ * This queue should out-perform {@link java.util.concurrent.ConcurrentLinkedQueue} in high-contention reads/writes, and is
+ * not any slower in lower contention reads/writes.
+ * <p>
+ * Note that this queue breaks the specification laid out by {@link Collection}, see {@link #preventAdds()} and {@link Collection#add(Object)}.
+ * </p>
+ * <p><b>
+ * This queue will only unlink linked nodes through the {@link #peek()} and {@link #poll()} methods, and this is only if
+ * they are at the head of the queue.
+ * </b></p>
+ * @param <E> Type of element in this queue.
+ */
+public class MultiThreadedQueue<E> implements Queue<E> {
+
+    protected volatile LinkedNode<E> head; /* Always non-null, high chance of being the actual head */
+
+    protected volatile LinkedNode<E> tail; /* Always non-null, high chance of being the actual tail */
+
+    /* Note that it is possible to reach head from tail. */
+
+    /* IMPL NOTE: Leave hashCode and equals to their defaults */
+
+    protected static final VarHandle HEAD_HANDLE = ConcurrentUtil.getVarHandle(MultiThreadedQueue.class, "head", LinkedNode.class);
+    protected static final VarHandle TAIL_HANDLE = ConcurrentUtil.getVarHandle(MultiThreadedQueue.class, "tail", LinkedNode.class);
+
+    /* head */
+
+    protected final void setHeadPlain(final LinkedNode<E> newHead) {
+        HEAD_HANDLE.set(this, newHead);
+    }
+
+    protected final void setHeadOpaque(final LinkedNode<E> newHead) {
+        HEAD_HANDLE.setOpaque(this, newHead);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final LinkedNode<E> getHeadPlain() {
+        return (LinkedNode<E>)HEAD_HANDLE.get(this);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final LinkedNode<E> getHeadOpaque() {
+        return (LinkedNode<E>)HEAD_HANDLE.getOpaque(this);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final LinkedNode<E> getHeadAcquire() {
+        return (LinkedNode<E>)HEAD_HANDLE.getAcquire(this);
+    }
+
+    /* tail */
+
+    protected final void setTailPlain(final LinkedNode<E> newTail) {
+        TAIL_HANDLE.set(this, newTail);
+    }
+
+    protected final void setTailOpaque(final LinkedNode<E> newTail) {
+        TAIL_HANDLE.setOpaque(this, newTail);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final LinkedNode<E> getTailPlain() {
+        return (LinkedNode<E>)TAIL_HANDLE.get(this);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final LinkedNode<E> getTailOpaque() {
+        return (LinkedNode<E>)TAIL_HANDLE.getOpaque(this);
+    }
+
+    /**
+     * Constructs a {@code MultiThreadedQueue}, initially empty.
+     * <p>
+     * The returned object may not be published without synchronization.
+     * </p>
+     */
+    public MultiThreadedQueue() {
+        final LinkedNode<E> value = new LinkedNode<>(null, null);
+        this.setHeadPlain(value);
+        this.setTailPlain(value);
+    }
+
+    /**
+     * Constructs a {@code MultiThreadedQueue}, initially containing all elements in the specified {@code collection}.
+     * <p>
+     * The returned object may not be published without synchronization.
+     * </p>
+     * @param collection The specified collection.
+     * @throws NullPointerException If {@code collection} is {@code null} or contains {@code null} elements.
+     */
+    public MultiThreadedQueue(final Iterable<? extends E> collection) {
+        final Iterator<? extends E> elements = collection.iterator();
+
+        if (!elements.hasNext()) {
+            final LinkedNode<E> value = new LinkedNode<>(null, null);
+            this.setHeadPlain(value);
+            this.setTailPlain(value);
+            return;
+        }
+
+        final LinkedNode<E> head = new LinkedNode<>(Validate.notNull(elements.next(), "Null element"), null);
+        LinkedNode<E> tail = head;
+
+        while (elements.hasNext()) {
+            final LinkedNode<E> next = new LinkedNode<>(Validate.notNull(elements.next(), "Null element"), null);
+            tail.setNextPlain(next);
+            tail = next;
+        }
+
+        this.setHeadPlain(head);
+        this.setTailPlain(tail);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public E remove() throws NoSuchElementException {
+        final E ret = this.poll();
+
+        if (ret == null) {
+            throw new NoSuchElementException();
+        }
+
+        return ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * Contrary to the specification of {@link Collection#add}, this method will fail to add the element to this queue
+     * and return {@code false} if this queue is add-blocked.
+     * </p>
+     */
+    @Override
+    public boolean add(final E element) {
+        return this.offer(element);
+    }
+
+    /**
+     * Adds the specified element to the tail of this queue. If this queue is currently add-locked, then the queue is
+     * released from that lock and this element is added. The unlock operation and addition of the specified
+     * element is atomic.
+     * @param element The specified element.
+     * @return {@code true} if this queue previously allowed additions
+     */
+    public boolean forceAdd(final E element) {
+        final LinkedNode<E> node = new LinkedNode<>(element, null);
+
+        return !this.forceAppendList(node, node);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public E element() throws NoSuchElementException {
+        final E ret = this.peek();
+
+        if (ret == null) {
+            throw new NoSuchElementException();
+        }
+
+        return ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * This method may also return {@code false} to indicate an element was not added if this queue is add-blocked.
+     * </p>
+     */
+    @Override
+    public boolean offer(final E element) {
+        Validate.notNull(element, "Null element");
+
+        final LinkedNode<E> node = new LinkedNode<>(element, null);
+
+        return this.appendList(node, node);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public E peek() {
+        for (LinkedNode<E> head = this.getHeadOpaque(), curr = head;;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                if (this.getHeadOpaque() == head && curr != head) {
+                    this.setHeadOpaque(curr);
+                }
+                return element;
+            }
+
+            if (next == null || curr == next) {
+                return null;
+            }
+            curr = next;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public E poll() {
+        return this.removeHead();
+    }
+
+    /**
+     * Retrieves and removes the head of this queue if it matches the specified predicate. If this queue is empty
+     * or the head does not match the predicate, this function returns {@code null}.
+     * <p>
+     * The predicate may be invoked multiple or no times in this call.
+     * </p>
+     * @param predicate The specified predicate.
+     * @return The head if it matches the predicate, or {@code null} if it did not or this queue is empty.
+     */
+    public E pollIf(final Predicate<E> predicate) {
+        return this.removeHead(Validate.notNull(predicate, "Null predicate"));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void clear() {
+        //noinspection StatementWithEmptyBody
+        while (this.poll() != null);
+    }
+
+    /**
+     * Prevents elements from being added to this queue. Once this is called, any attempt to add to this queue will fail.
+     * <p>
+     * This function is MT-Safe.
+     * </p>
+     * @return {@code true} if the queue was modified to prevent additions, {@code false} if it already prevented additions.
+     */
+    public boolean preventAdds() {
+        final LinkedNode<E> deadEnd = new LinkedNode<>(null, null);
+        deadEnd.setNextPlain(deadEnd);
+
+        if (!this.appendList(deadEnd, deadEnd)) {
+            return false;
+        }
+
+        this.setTailPlain(deadEnd); /* (try to) Ensure tail is set for the following #allowAdds call */
+        return true;
+    }
+
+    /**
+     * Allows elements to be added to this queue once again. Note that this function has undefined behaviour if
+     * {@link #preventAdds()} is not called beforehand. The benefit of this function over {@link #tryAllowAdds()}
+     * is that this function might perform better.
+     * <p>
+     * This function is not MT-Safe.
+     * </p>
+     */
+    public void allowAdds() {
+        LinkedNode<E> tail = this.getTailPlain();
+
+        /* We need to find the tail given the cas on tail isn't atomic (nor volatile) in this.appendList */
+        /* Thus it is possible for an outdated tail to be set */
+        while (tail != (tail = tail.getNextPlain())) {}
+
+        tail.setNextVolatile(null);
+    }
+
+    /**
+     * Tries to allow elements to be added to this queue. Returns {@code true} if the queue was previous add-locked,
+     * {@code false} otherwise.
+     * <p>
+     * This function is MT-Safe, however it should not be used with {@link #allowAdds()}.
+     * </p>
+     * @return {@code true} if the queue was previously add-locked, {@code false} otherwise.
+     */
+    public boolean tryAllowAdds() {
+        LinkedNode<E> tail = this.getTailPlain();
+
+        for (int failures = 0;;) {
+            /* We need to find the tail given the cas on tail isn't atomic (nor volatile) in this.appendList */
+            /* Thus it is possible for an outdated tail to be set */
+            while (tail != (tail = tail.getNextAcquire())) {
+                if (tail == null) {
+                    return false;
+                }
+            }
+
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (tail == (tail = tail.compareExchangeNextVolatile(tail, null))) {
+                return true;
+            }
+
+            if (tail == null) {
+                return false;
+            }
+            ++failures;
+        }
+    }
+
+    /**
+     * Atomically adds the specified element to this queue or allows additions to the queue. If additions
+     * are not allowed, the element is not added.
+     * <p>
+     * This function is MT-Safe.
+     * </p>
+     * @param element The specified element.
+     * @return {@code true} if the queue now allows additions, {@code false} if the element was added.
+     */
+    public boolean addOrAllowAdds(final E element) {
+        Validate.notNull(element, "Null element");
+        int failures = 0;
+
+        final LinkedNode<E> append = new LinkedNode<>(element, null);
+
+        for (LinkedNode<E> currTail = this.getTailOpaque(), curr = currTail;;) {
+            /* It has been experimentally shown that placing the read before the backoff results in significantly greater performance */
+            /* It is likely due to a cache miss caused by another write to the next field */
+            final LinkedNode<E> next = curr.getNextVolatile();
+
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (next == null) {
+                final LinkedNode<E> compared = curr.compareExchangeNextVolatile(null, append);
+
+                if (compared == null) {
+                    /* Added */
+                    /* Avoid CASing on tail more than we need to */
+                    /* CAS to avoid setting an out-of-date tail */
+                    if (this.getTailOpaque() == currTail) {
+                        this.setTailOpaque(append);
+                    }
+                    return false; // we added
+                }
+
+                ++failures;
+                curr = compared;
+                continue;
+            } else if (next == curr) {
+                final LinkedNode<E> compared = curr.compareExchangeNextVolatile(curr, null);
+
+                if (compared == curr) {
+                    return true; // we let additions through
+                }
+
+                ++failures;
+
+                if (compared != null) {
+                    curr = compared;
+                }
+                continue;
+            }
+
+            if (curr == currTail) {
+                /* Tail is likely not up-to-date */
+                curr = next;
+            } else {
+                /* Try to update to tail */
+                if (currTail == (currTail = this.getTailOpaque())) {
+                    curr = next;
+                } else {
+                    curr = currTail;
+                }
+            }
+        }
+    }
+
+    /**
+     * Atomically removes the head from this queue if it exists, otherwise prevents additions to this queue if no
+     * head is removed.
+     * <p>
+     * This function is MT-Safe.
+     * </p>
+     * If the queue is already add-blocked and empty then no operation is performed.
+     * @return {@code null} if the queue is now add-blocked or was previously add-blocked, else returns
+     * an non-null value which was the previous head of queue.
+     */
+    public E pollOrBlockAdds() {
+        int failures = 0;
+        for (LinkedNode<E> head = this.getHeadOpaque(), curr = head;;) {
+            final E currentVal = curr.getElementVolatile();
+            final LinkedNode<E> next = curr.getNextOpaque();
+
+            if (next == curr) {
+                return null; /* Additions are already blocked */
+            }
+
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (currentVal != null) {
+                if (curr.getAndSetElementVolatile(null) == null) {
+                    ++failures;
+                    continue;
+                }
+
+                /* "CAS" to avoid setting an out-of-date head */
+                if (this.getHeadOpaque() == head) {
+                    this.setHeadOpaque(next != null ? next : curr);
+                }
+
+                return currentVal;
+            }
+
+            if (next == null) {
+                /* Try to update stale head */
+                if (curr != head && this.getHeadOpaque() == head) {
+                    this.setHeadOpaque(curr);
+                }
+
+                final LinkedNode<E> compared = curr.compareExchangeNextVolatile(null, curr);
+
+                if (compared != null) {
+                    // failed to block additions
+                    curr = compared;
+                    ++failures;
+                    continue;
+                }
+
+                return null; /* We blocked additions */
+            }
+
+            if (head == curr) {
+                /* head is likely not up-to-date */
+                curr = next;
+            } else {
+                /* Try to update to head */
+                if (head == (head = this.getHeadOpaque())) {
+                    curr = next;
+                } else {
+                    curr = head;
+                }
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean remove(final Object object) {
+        Validate.notNull(object, "Null object to remove");
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                if ((element == object || element.equals(object)) && curr.getAndSetElementVolatile(null) == element) {
+                    return true;
+                }
+            }
+
+            if (next == curr || next == null) {
+                break;
+            }
+            curr = next;
+        }
+
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean removeIf(final Predicate<? super E> filter) {
+        Validate.notNull(filter, "Null filter");
+
+        boolean ret = false;
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                ret |= filter.test(element) && curr.getAndSetElementVolatile(null) == element;
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean removeAll(final Collection<?> collection) {
+        Validate.notNull(collection, "Null collection");
+
+        boolean ret = false;
+
+        /* Volatile is required to synchronize with the write to the first element */
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                ret |= collection.contains(element) && curr.getAndSetElementVolatile(null) == element;
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean retainAll(final Collection<?> collection) {
+        Validate.notNull(collection, "Null collection");
+
+        boolean ret = false;
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                ret |= !collection.contains(element) && curr.getAndSetElementVolatile(null) == element;
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object[] toArray() {
+        final List<E> ret = new ArrayList<>();
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                ret.add(element);
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return ret.toArray();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public <T> T[] toArray(final T[] array) {
+        final List<T> ret = new ArrayList<>();
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                //noinspection unchecked
+                ret.add((T)element);
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return ret.toArray(array);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public <T> T[] toArray(final IntFunction<T[]> generator) {
+        Validate.notNull(generator, "Null generator");
+
+        final List<T> ret = new ArrayList<>();
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                //noinspection unchecked
+                ret.add((T)element);
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return ret.toArray(generator);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder();
+
+        builder.append("MultiThreadedQueue: {elements: {");
+
+        int deadEntries = 0;
+        int totalEntries = 0;
+        int aliveEntries = 0;
+
+        boolean addLocked = false;
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();; ++totalEntries) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element == null) {
+                ++deadEntries;
+            } else {
+                ++aliveEntries;
+            }
+
+            if (totalEntries != 0) {
+                builder.append(", ");
+            }
+
+            builder.append(totalEntries).append(": \"").append(element).append('"');
+
+            if (next == null) {
+                break;
+            }
+            if (curr == next) {
+                addLocked = true;
+                break;
+            }
+            curr = next;
+        }
+
+        builder.append("}, total_entries: \"").append(totalEntries).append("\", alive_entries: \"").append(aliveEntries)
+            .append("\", dead_entries:").append(deadEntries).append("\", add_locked: \"").append(addLocked)
+            .append("\"}");
+
+        return builder.toString();
+    }
+
+    /**
+     * Adds all elements from the specified collection to this queue. The addition is atomic.
+     * @param collection The specified collection.
+     * @return {@code true} if all elements were added successfully, or {@code false} if this queue is add-blocked, or
+     * {@code false} if the specified collection contains no elements.
+     */
+    @Override
+    public boolean addAll(final Collection<? extends E> collection) {
+        return this.addAll((Iterable<? extends E>)collection);
+    }
+
+    /**
+     * Adds all elements from the specified iterable object to this queue. The addition is atomic.
+     * @param iterable The specified iterable object.
+     * @return {@code true} if all elements were added successfully, or {@code false} if this queue is add-blocked, or
+     * {@code false} if the specified iterable contains no elements.
+     */
+    public boolean addAll(final Iterable<? extends E> iterable) {
+        Validate.notNull(iterable, "Null iterable");
+
+        final Iterator<? extends E> elements = iterable.iterator();
+        if (!elements.hasNext()) {
+            return false;
+        }
+
+        /* Build a list of nodes to append */
+        /* This is an much faster due to the fact that zero additional synchronization is performed */
+
+        final LinkedNode<E> head = new LinkedNode<>(Validate.notNull(elements.next(), "Null element"), null);
+        LinkedNode<E> tail = head;
+
+        while (elements.hasNext()) {
+            final LinkedNode<E> next = new LinkedNode<>(Validate.notNull(elements.next(), "Null element"), null);
+            tail.setNextPlain(next);
+            tail = next;
+        }
+
+        return this.appendList(head, tail);
+    }
+
+    /**
+     * Adds all of the elements from the specified array to this queue.
+     * @param items The specified array.
+     * @return {@code true} if all elements were added successfully, or {@code false} if this queue is add-blocked, or
+     * {@code false} if the specified array has a length of 0.
+     */
+    public boolean addAll(final E[] items) {
+        return this.addAll(items, 0, items.length);
+    }
+
+    /**
+     * Adds all of the elements from the specified array to this queue.
+     * @param items The specified array.
+     * @param off The offset in the array.
+     * @param len The number of items.
+     * @return {@code true} if all elements were added successfully, or {@code false} if this queue is add-blocked, or
+     * {@code false} if the specified array has a length of 0.
+     */
+    public boolean addAll(final E[] items, final int off, final int len) {
+        Validate.notNull(items, "Items may not be null");
+        Validate.arrayBounds(off, len, items.length, "Items array indices out of bounds");
+
+        if (len == 0) {
+            return false;
+        }
+
+        final LinkedNode<E> head = new LinkedNode<>(Validate.notNull(items[off], "Null element"), null);
+        LinkedNode<E> tail = head;
+
+        for (int i = 1; i < len; ++i) {
+            final LinkedNode<E> next = new LinkedNode<>(Validate.notNull(items[off + i], "Null element"), null);
+            tail.setNextPlain(next);
+            tail = next;
+        }
+
+        return this.appendList(head, tail);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean containsAll(final Collection<?> collection) {
+        Validate.notNull(collection, "Null collection");
+
+        for (final Object element : collection) {
+            if (!this.contains(element)) {
+                return false;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Iterator<E> iterator() {
+        return new LinkedIterator<>(this.getHeadOpaque());
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * Note that this function is computed non-atomically and in O(n) time. The value returned may not be representative of
+     * the queue in its current state.
+     * </p>
+     */
+    @Override
+    public int size() {
+        int size = 0;
+
+        /* Volatile is required to synchronize with the write to the first element */
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                ++size;
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return size;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isEmpty() {
+        return this.peek() == null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean contains(final Object object) {
+        Validate.notNull(object, "Null object");
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null && (element == object || element.equals(object))) {
+                return true;
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return false;
+    }
+
+    /**
+     * Finds the first element in this queue that matches the predicate.
+     * @param predicate The predicate to test elements against.
+     * @return The first element that matched the predicate, {@code null} if none matched.
+     */
+    public E find(final Predicate<E> predicate) {
+        Validate.notNull(predicate, "Null predicate");
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null && predicate.test(element)) {
+                return element;
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void forEach(final Consumer<? super E> action) {
+        Validate.notNull(action, "Null action");
+
+        for (LinkedNode<E> curr = this.getHeadOpaque();;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E element = curr.getElementPlain(); /* Likely in sync */
+
+            if (element != null) {
+                action.accept(element);
+            }
+
+            if (next == null || next == curr) {
+                break;
+            }
+            curr = next;
+        }
+    }
+
+    // return true if normal addition, false if the queue previously disallowed additions
+    protected final boolean forceAppendList(final LinkedNode<E> head, final LinkedNode<E> tail) {
+        int failures = 0;
+
+        for (LinkedNode<E> currTail = this.getTailOpaque(), curr = currTail;;) {
+            /* It has been experimentally shown that placing the read before the backoff results in significantly greater performance */
+            /* It is likely due to a cache miss caused by another write to the next field */
+            final LinkedNode<E> next = curr.getNextVolatile();
+
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (next == null || next == curr) {
+                final LinkedNode<E> compared = curr.compareExchangeNextVolatile(next, head);
+
+                if (compared == next) {
+                    /* Added */
+                    /* Avoid CASing on tail more than we need to */
+                    /* "CAS" to avoid setting an out-of-date tail */
+                    if (this.getTailOpaque() == currTail) {
+                        this.setTailOpaque(tail);
+                    }
+                    return next != curr;
+                }
+
+                ++failures;
+                curr = compared;
+                continue;
+            }
+
+            if (curr == currTail) {
+                /* Tail is likely not up-to-date */
+                curr = next;
+            } else {
+                /* Try to update to tail */
+                if (currTail == (currTail = this.getTailOpaque())) {
+                    curr = next;
+                } else {
+                    curr = currTail;
+                }
+            }
+        }
+    }
+
+    // return true if successful, false otherwise
+    protected final boolean appendList(final LinkedNode<E> head, final LinkedNode<E> tail) {
+        int failures = 0;
+
+        for (LinkedNode<E> currTail = this.getTailOpaque(), curr = currTail;;) {
+            /* It has been experimentally shown that placing the read before the backoff results in significantly greater performance */
+            /* It is likely due to a cache miss caused by another write to the next field */
+            final LinkedNode<E> next = curr.getNextVolatile();
+
+            if (next == curr) {
+                /* Additions are stopped */
+                return false;
+            }
+
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (next == null) {
+                final LinkedNode<E> compared = curr.compareExchangeNextVolatile(null, head);
+
+                if (compared == null) {
+                    /* Added */
+                    /* Avoid CASing on tail more than we need to */
+                    /* CAS to avoid setting an out-of-date tail */
+                    if (this.getTailOpaque() == currTail) {
+                        this.setTailOpaque(tail);
+                    }
+                    return true;
+                }
+
+                ++failures;
+                curr = compared;
+                continue;
+            }
+
+            if (curr == currTail) {
+                /* Tail is likely not up-to-date */
+                curr = next;
+            } else {
+                /* Try to update to tail */
+                if (currTail == (currTail = this.getTailOpaque())) {
+                    curr = next;
+                } else {
+                    curr = currTail;
+                }
+            }
+        }
+    }
+
+    protected final E removeHead(final Predicate<E> predicate) {
+        int failures = 0;
+        for (LinkedNode<E> head = this.getHeadOpaque(), curr = head;;) {
+            // volatile here synchronizes-with writes to element
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E currentVal = curr.getElementPlain();
+
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (currentVal != null) {
+                if (!predicate.test(currentVal)) {
+                    /* Try to update stale head */
+                    if (curr != head && this.getHeadOpaque() == head) {
+                        this.setHeadOpaque(curr);
+                    }
+                    return null;
+                }
+                if (curr.getAndSetElementVolatile(null) == null) {
+                    /* Failed to get head */
+                    if (curr == (curr = next) || next == null) {
+                        return null;
+                    }
+                    ++failures;
+                    continue;
+                }
+
+                /* "CAS" to avoid setting an out-of-date head */
+                if (this.getHeadOpaque() == head) {
+                    this.setHeadOpaque(next != null ? next : curr);
+                }
+
+                return currentVal;
+            }
+
+            if (curr == next || next == null) {
+                /* Try to update stale head */
+                if (curr != head && this.getHeadOpaque() == head) {
+                    this.setHeadOpaque(curr);
+                }
+                return null; /* End of queue */
+            }
+
+            if (head == curr) {
+                /* head is likely not up-to-date */
+                curr = next;
+            } else {
+                /* Try to update to head */
+                if (head == (head = this.getHeadOpaque())) {
+                    curr = next;
+                } else {
+                    curr = head;
+                }
+            }
+        }
+    }
+
+    protected final E removeHead() {
+        int failures = 0;
+        for (LinkedNode<E> head = this.getHeadOpaque(), curr = head;;) {
+            final LinkedNode<E> next = curr.getNextVolatile();
+            final E currentVal = curr.getElementPlain();
+
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (currentVal != null) {
+                if (curr.getAndSetElementVolatile(null) == null) {
+                    /* Failed to get head */
+                    if (curr == (curr = next) || next == null) {
+                        return null;
+                    }
+                    ++failures;
+                    continue;
+                }
+
+                /* "CAS" to avoid setting an out-of-date head */
+                if (this.getHeadOpaque() == head) {
+                    this.setHeadOpaque(next != null ? next : curr);
+                }
+
+                return currentVal;
+            }
+
+            if (curr == next || next == null) {
+                /* Try to update stale head */
+                if (curr != head && this.getHeadOpaque() == head) {
+                    this.setHeadOpaque(curr);
+                }
+                return null; /* End of queue */
+            }
+
+            if (head == curr) {
+                /* head is likely not up-to-date */
+                curr = next;
+            } else {
+                /* Try to update to head */
+                if (head == (head = this.getHeadOpaque())) {
+                    curr = next;
+                } else {
+                    curr = head;
+                }
+            }
+        }
+    }
+
+    /**
+     * Empties the queue into the specified consumer. This function is optimized for single-threaded reads, and should
+     * be faster than a loop on {@link #poll()}.
+     * <p>
+     * This function is not MT-Safe. This function cannot be called with other read operations ({@link #peek()}, {@link #poll()},
+     * {@link #clear()}, etc).
+     * Write operations are safe to be called concurrently.
+     * </p>
+     * @param consumer The consumer to accept the elements.
+     * @return The total number of elements drained.
+     */
+    public int drain(final Consumer<E> consumer) {
+        return this.drain(consumer, false, ConcurrentUtil::rethrow);
+    }
+
+    /**
+     * Empties the queue into the specified consumer. This function is optimized for single-threaded reads, and should
+     * be faster than a loop on {@link #poll()}.
+     * <p>
+     * If {@code preventAdds} is {@code true}, then after this function returns the queue is guaranteed to be empty and
+     * additions to the queue will fail.
+     * </p>
+     * <p>
+     * This function is not MT-Safe. This function cannot be called with other read operations ({@link #peek()}, {@link #poll()},
+     * {@link #clear()}, etc).
+     * Write operations are safe to be called concurrently.
+     * </p>
+     * @param consumer The consumer to accept the elements.
+     * @param preventAdds Whether to prevent additions to this queue after draining.
+     * @return The total number of elements drained.
+     */
+    public int drain(final Consumer<E> consumer, final boolean preventAdds) {
+        return this.drain(consumer, preventAdds, ConcurrentUtil::rethrow);
+    }
+
+    /**
+     * Empties the queue into the specified consumer. This function is optimized for single-threaded reads, and should
+     * be faster than a loop on {@link #poll()}.
+     * <p>
+     * If {@code preventAdds} is {@code true}, then after this function returns the queue is guaranteed to be empty and
+     * additions to the queue will fail.
+     * </p>
+     * <p>
+     * This function is not MT-Safe. This function cannot be called with other read operations ({@link #peek()}, {@link #poll()},
+     * {@link #clear()}, {@link #remove(Object)} etc).
+     * Only write operations are safe to be called concurrently.
+     * </p>
+     * @param consumer The consumer to accept the elements.
+     * @param preventAdds Whether to prevent additions to this queue after draining.
+     * @param exceptionHandler Invoked when the consumer raises an exception.
+     * @return The total number of elements drained.
+     */
+    public int drain(final Consumer<E> consumer, final boolean preventAdds, final Consumer<Throwable> exceptionHandler) {
+        Validate.notNull(consumer, "Null consumer");
+        Validate.notNull(exceptionHandler, "Null exception handler");
+
+        /* This function assumes proper synchronization is made to ensure drain and no other read function are called concurrently */
+        /* This allows plain write usages instead of opaque or higher */
+        int total = 0;
+
+        final LinkedNode<E> head = this.getHeadAcquire(); /* Required to synchronize with the write to the first element field */
+        LinkedNode<E> curr = head;
+
+        for (;;) {
+            /* Volatile acquires with the write to the element field */
+            final E currentVal = curr.getElementPlain();
+            LinkedNode<E> next = curr.getNextVolatile();
+
+            if (next == curr) {
+                /* Add-locked nodes always have a null value */
+                break;
+            }
+
+            if (currentVal == null) {
+                if (next == null) {
+                    if (preventAdds && (next = curr.compareExchangeNextVolatile(null, curr)) != null) {
+                        // failed to prevent adds, continue
+                        curr = next;
+                        continue;
+                    } else {
+                        // we're done here
+                        break;
+                    }
+                }
+                curr = next;
+                continue;
+            }
+
+            try {
+                consumer.accept(currentVal);
+            } catch (final Exception ex) {
+                this.setHeadOpaque(next != null ? next : curr); /* Avoid perf penalty (of reiterating) if the exception handler decides to re-throw */
+                curr.setElementOpaque(null); /* set here, we might re-throw */
+
+                exceptionHandler.accept(ex);
+            }
+
+            curr.setElementOpaque(null);
+
+            ++total;
+
+            if (next == null) {
+                if (preventAdds && (next = curr.compareExchangeNextVolatile(null, curr)) != null) {
+                    /* Retry with next value */
+                    curr = next;
+                    continue;
+                }
+                break;
+            }
+
+            curr = next;
+        }
+        if (curr != head) {
+            this.setHeadOpaque(curr); /* While this may be a plain write, eventually publish it for methods such as find. */
+        }
+        return total;
+    }
+
+    @Override
+    public Spliterator<E> spliterator() { // TODO implement
+        return Spliterators.spliterator(this, Spliterator.CONCURRENT |
+            Spliterator.NONNULL | Spliterator.ORDERED);
+    }
+
+    protected static final class LinkedNode<E> {
+
+        protected volatile Object element;
+        protected volatile LinkedNode<E> next;
+
+        protected static final VarHandle ELEMENT_HANDLE = ConcurrentUtil.getVarHandle(LinkedNode.class, "element", Object.class);
+        protected static final VarHandle NEXT_HANDLE = ConcurrentUtil.getVarHandle(LinkedNode.class, "next", LinkedNode.class);
+
+        protected LinkedNode(final Object element, final LinkedNode<E> next) {
+            ELEMENT_HANDLE.set(this, element);
+            NEXT_HANDLE.set(this, next);
+        }
+
+        /* element */
+
+        @SuppressWarnings("unchecked")
+        protected final E getElementPlain() {
+            return (E)ELEMENT_HANDLE.get(this);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final E getElementVolatile() {
+            return (E)ELEMENT_HANDLE.getVolatile(this);
+        }
+
+        protected final void setElementPlain(final E update) {
+            ELEMENT_HANDLE.set(this, (Object)update);
+        }
+
+        protected final void setElementOpaque(final E update) {
+            ELEMENT_HANDLE.setOpaque(this, (Object)update);
+        }
+
+        protected final void setElementVolatile(final E update) {
+            ELEMENT_HANDLE.setVolatile(this, (Object)update);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final E getAndSetElementVolatile(final E update) {
+            return (E)ELEMENT_HANDLE.getAndSet(this, update);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final E compareExchangeElementVolatile(final E expect, final E update) {
+            return (E)ELEMENT_HANDLE.compareAndExchange(this, expect, update);
+        }
+
+        /* next */
+
+        @SuppressWarnings("unchecked")
+        protected final LinkedNode<E> getNextPlain() {
+            return (LinkedNode<E>)NEXT_HANDLE.get(this);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final LinkedNode<E> getNextOpaque() {
+            return (LinkedNode<E>)NEXT_HANDLE.getOpaque(this);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final LinkedNode<E> getNextAcquire() {
+            return (LinkedNode<E>)NEXT_HANDLE.getAcquire(this);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final LinkedNode<E> getNextVolatile() {
+            return (LinkedNode<E>)NEXT_HANDLE.getVolatile(this);
+        }
+
+        protected final void setNextPlain(final LinkedNode<E> next) {
+            NEXT_HANDLE.set(this, next);
+        }
+
+        protected final void setNextVolatile(final LinkedNode<E> next) {
+            NEXT_HANDLE.setVolatile(this, next);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final LinkedNode<E> compareExchangeNextVolatile(final LinkedNode<E> expect, final LinkedNode<E> set) {
+            return (LinkedNode<E>)NEXT_HANDLE.compareAndExchange(this, expect, set);
+        }
+    }
+
+    protected static final class LinkedIterator<E> implements Iterator<E> {
+
+        protected LinkedNode<E> curr; /* last returned by next() */
+        protected LinkedNode<E> next; /* next to return from next() */
+        protected E nextElement; /* cached to avoid a race condition with removing or polling */
+
+        protected LinkedIterator(final LinkedNode<E> start) {
+            /* setup nextElement and next */
+            for (LinkedNode<E> curr = start;;) {
+                final LinkedNode<E> next = curr.getNextVolatile();
+
+                final E element = curr.getElementPlain();
+
+                if (element != null) {
+                    this.nextElement = element;
+                    this.next = curr;
+                    break;
+                }
+
+                if (next == null || next == curr) {
+                    break;
+                }
+                curr = next;
+            }
+        }
+
+        protected final void findNext() {
+            /* only called if this.nextElement != null, which means this.next != null */
+            for (LinkedNode<E> curr = this.next;;) {
+                final LinkedNode<E> next = curr.getNextVolatile();
+
+                if (next == null || next == curr) {
+                    break;
+                }
+
+                final E element = next.getElementPlain();
+
+                if (element != null) {
+                    this.nextElement = element;
+                    this.curr = this.next; /* this.next will be the value returned from next(), set this.curr for remove() */
+                    this.next = next;
+                    return;
+                }
+                curr = next;
+            }
+
+            /* out of nodes to iterate */
+            /* keep curr for remove() calls */
+            this.next = null;
+            this.nextElement = null;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public boolean hasNext() {
+            return this.nextElement != null;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public E next() {
+            final E element = this.nextElement;
+
+            if (element == null) {
+                throw new NoSuchElementException();
+            }
+
+            this.findNext();
+
+            return element;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public void remove() {
+            if (this.curr == null) {
+                throw new IllegalStateException();
+            }
+
+            this.curr.setElementVolatile(null);
+            this.curr = null;
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/collection/SRSWLinkedQueue.java b/src/main/java/ca/spottedleaf/concurrentutil/collection/SRSWLinkedQueue.java
new file mode 100644
index 0000000000000000000000000000000000000000..597659f38aa816646dcda4ca39c002b6d9f9a792
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/collection/SRSWLinkedQueue.java
@@ -0,0 +1,148 @@
+package ca.spottedleaf.concurrentutil.collection;
+
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import ca.spottedleaf.concurrentutil.util.Validate;
+import java.lang.invoke.VarHandle;
+import java.util.ConcurrentModificationException;
+
+/**
+ * Single reader thread single writer thread queue. The reader side of the queue is ordered by acquire semantics,
+ * and the writer side of the queue is ordered by release semantics.
+ */
+// TODO test
+public class SRSWLinkedQueue<E> {
+
+    // always non-null
+    protected LinkedNode<E> head;
+
+    // always non-null
+    protected LinkedNode<E> tail;
+
+    /* IMPL NOTE: Leave hashCode and equals to their defaults */
+
+    public SRSWLinkedQueue() {
+        final LinkedNode<E> dummy = new LinkedNode<>(null, null);
+        this.head = this.tail = dummy;
+    }
+
+    /**
+     * Must be the reader thread.
+     *
+     * <p>
+     * Returns, without removing, the first element of this queue.
+     * </p>
+     * @return Returns, without removing, the first element of this queue.
+     */
+    public E peekFirst() {
+        LinkedNode<E> head = this.head;
+        E ret = head.getElementPlain();
+        if (ret == null) {
+            head = head.getNextAcquire();
+            if (head == null) {
+                // empty
+                return null;
+            }
+            // update head reference for next poll() call
+            this.head = head;
+            // guaranteed to be non-null
+            ret = head.getElementPlain();
+            if (ret == null) {
+                throw new ConcurrentModificationException("Multiple reader threads");
+            }
+        }
+
+        return ret;
+    }
+
+    /**
+     * Must be the reader thread.
+     *
+     * <p>
+     * Returns and removes the first element of this queue.
+     * </p>
+     * @return Returns and removes the first element of this queue.
+     */
+    public E poll() {
+        LinkedNode<E> head = this.head;
+        E ret = head.getElementPlain();
+        if (ret == null) {
+            head = head.getNextAcquire();
+            if (head == null) {
+                // empty
+                return null;
+            }
+            // guaranteed to be non-null
+            ret = head.getElementPlain();
+            if (ret == null) {
+                throw new ConcurrentModificationException("Multiple reader threads");
+            }
+        }
+
+        head.setElementPlain(null);
+        LinkedNode<E> next = head.getNextAcquire();
+        this.head = next == null ? head : next;
+
+        return ret;
+    }
+
+    /**
+     * Must be the writer thread.
+     *
+     * <p>
+     * Adds the element to the end of the queue.
+     * </p>
+     *
+     * @throws NullPointerException If the provided element is null
+     */
+    public void addLast(final E element) {
+        Validate.notNull(element, "Provided element cannot be null");
+        final LinkedNode<E> append = new LinkedNode<>(element, null);
+
+        this.tail.setNextRelease(append);
+        this.tail = append;
+    }
+
+    protected static final class LinkedNode<E> {
+
+        protected volatile Object element;
+        protected volatile LinkedNode<E> next;
+
+        protected static final VarHandle ELEMENT_HANDLE = ConcurrentUtil.getVarHandle(LinkedNode.class, "element", Object.class);
+        protected static final VarHandle NEXT_HANDLE = ConcurrentUtil.getVarHandle(LinkedNode.class, "next", LinkedNode.class);
+
+        protected LinkedNode(final Object element, final LinkedNode<E> next) {
+            ELEMENT_HANDLE.set(this, element);
+            NEXT_HANDLE.set(this, next);
+        }
+
+        /* element */
+
+        @SuppressWarnings("unchecked")
+        protected final E getElementPlain() {
+            return (E)ELEMENT_HANDLE.get(this);
+        }
+
+        protected final void setElementPlain(final E update) {
+            ELEMENT_HANDLE.set(this, (Object)update);
+        }
+        /* next */
+
+        @SuppressWarnings("unchecked")
+        protected final LinkedNode<E> getNextPlain() {
+            return (LinkedNode<E>)NEXT_HANDLE.get(this);
+        }
+
+        @SuppressWarnings("unchecked")
+        protected final LinkedNode<E> getNextAcquire() {
+            return (LinkedNode<E>)NEXT_HANDLE.getAcquire(this);
+        }
+
+        protected final void setNextPlain(final LinkedNode<E> next) {
+            NEXT_HANDLE.set(this, next);
+        }
+
+        protected final void setNextRelease(final LinkedNode<E> next) {
+            NEXT_HANDLE.setRelease(this, next);
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/completable/Completable.java b/src/main/java/ca/spottedleaf/concurrentutil/completable/Completable.java
new file mode 100644
index 0000000000000000000000000000000000000000..a1ad3308f9c3545a604b635896259a1cd3382b2a
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/completable/Completable.java
@@ -0,0 +1,98 @@
+package ca.spottedleaf.concurrentutil.completable;
+
+import ca.spottedleaf.concurrentutil.collection.MultiThreadedQueue;
+import ca.spottedleaf.concurrentutil.executor.Cancellable;
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import com.mojang.logging.LogUtils;
+import org.slf4j.Logger;
+import java.util.function.BiConsumer;
+
+public final class Completable<T> {
+
+    private static final Logger LOGGER = LogUtils.getLogger();
+
+    private final MultiThreadedQueue<BiConsumer<T, Throwable>> waiters = new MultiThreadedQueue<>();
+    private T result;
+    private Throwable throwable;
+    private volatile boolean completed;
+
+    public boolean isCompleted() {
+        return this.completed;
+    }
+
+    /**
+     * Note: Can only use after calling {@link #addAsynchronousWaiter(BiConsumer)}, as this function performs zero
+     * synchronisation
+     */
+    public T getResult() {
+        return this.result;
+    }
+
+    /**
+     * Note: Can only use after calling {@link #addAsynchronousWaiter(BiConsumer)}, as this function performs zero
+     * synchronisation
+     */
+    public Throwable getThrowable() {
+        return this.throwable;
+    }
+
+    public Cancellable addAsynchronousWaiter(final BiConsumer<T, Throwable> consumer) {
+        if (this.waiters.add(consumer)) {
+            return new CancellableImpl(consumer);
+        }
+        return null;
+    }
+
+    private void completeAllWaiters(final T result, final Throwable throwable) {
+        this.completed = true;
+        BiConsumer<T, Throwable> waiter;
+        while ((waiter = this.waiters.pollOrBlockAdds()) != null) {
+            this.completeWaiter(waiter, result, throwable);
+        }
+    }
+
+    private void completeWaiter(final BiConsumer<T, Throwable> consumer, final T result, final Throwable throwable) {
+        try {
+            consumer.accept(result, throwable);
+        } catch (final ThreadDeath death) {
+            throw death;
+        } catch (final Throwable throwable2) {
+            LOGGER.error("Failed to complete callback " + ConcurrentUtil.genericToString(consumer), throwable2);
+        }
+    }
+
+    public Cancellable addWaiter(final BiConsumer<T, Throwable> consumer) {
+        if (this.waiters.add(consumer)) {
+            return new CancellableImpl(consumer);
+        }
+        this.completeWaiter(consumer, this.result, this.throwable);
+        return new CancellableImpl(consumer);
+    }
+
+    public void complete(final T result) {
+        this.result = result;
+        this.completeAllWaiters(result, null);
+    }
+
+    public void completeWithThrowable(final Throwable throwable) {
+        if (throwable == null) {
+            throw new NullPointerException("Throwable cannot be null");
+        }
+        this.throwable = throwable;
+        this.completeAllWaiters(null, throwable);
+    }
+
+    private final class CancellableImpl implements Cancellable {
+
+        private final BiConsumer<T, Throwable> waiter;
+
+        private CancellableImpl(final BiConsumer<T, Throwable> waiter) {
+            this.waiter = waiter;
+        }
+
+        @Override
+        public boolean cancel() {
+            return Completable.this.waiters.remove(this.waiter);
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/executor/BaseExecutor.java b/src/main/java/ca/spottedleaf/concurrentutil/executor/BaseExecutor.java
new file mode 100644
index 0000000000000000000000000000000000000000..8c452b0988da4725762d543f6bee09915c328ae6
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/executor/BaseExecutor.java
@@ -0,0 +1,198 @@
+package ca.spottedleaf.concurrentutil.executor;
+
+import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor;
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import java.util.function.BooleanSupplier;
+
+public interface BaseExecutor {
+
+    /**
+     * Returns whether every task scheduled to this queue has been removed and executed or cancelled. If no tasks have been queued,
+     * returns {@code true}.
+     *
+     * @return {@code true} if all tasks that have been queued have finished executing or no tasks have been queued, {@code false} otherwise.
+     */
+    public default boolean haveAllTasksExecuted() {
+        // order is important
+        // if new tasks are scheduled between the reading of these variables, scheduled is guaranteed to be higher -
+        // so our check fails, and we try again
+        final long completed = this.getTotalTasksExecuted();
+        final long scheduled = this.getTotalTasksScheduled();
+
+        return completed == scheduled;
+    }
+
+    /**
+     * Returns the number of tasks that have been scheduled or execute or are pending to be scheduled.
+     */
+    public long getTotalTasksScheduled();
+
+    /**
+     * Returns the number of tasks that have fully been executed.
+     */
+    public long getTotalTasksExecuted();
+
+
+    /**
+     * Waits until this queue has had all of its tasks executed (NOT removed). See {@link #haveAllTasksExecuted()}
+     * <p>
+     *     This call is most effective after a {@link #shutdown()} call, as the shutdown call guarantees no tasks can
+     *     be executed and the waitUntilAllExecuted call makes sure the queue is empty. Effectively, using shutdown then using
+     *     waitUntilAllExecuted ensures this queue is empty - and most importantly, will remain empty.
+     * </p>
+     * <p>
+     *     This method is not guaranteed to be immediately responsive to queue state, so calls may take significantly more
+     *     time than expected. Effectively, do not rely on this call being fast - even if there are few tasks scheduled.
+     * </p>
+     * <p>
+     *     Note: Interruptions to the the current thread have no effect. Interrupt status is also not affected by this cal.
+     * </p>
+     *
+     * @throws IllegalStateException If the current thread is not allowed to wait
+     */
+    public default void waitUntilAllExecuted() throws IllegalStateException {
+        long failures = 1L; // start at 0.25ms
+
+        while (!this.haveAllTasksExecuted()) {
+            Thread.yield();
+            failures = ConcurrentUtil.linearLongBackoff(failures, 250_000L, 5_000_000L); // 500us, 5ms
+        }
+    }
+
+    /**
+     * Executes the next available task.
+     * <p>
+     *     If there is a task with priority {@link PrioritisedExecutor.Priority#BLOCKING} available, then that such task is executed.
+     * </p>
+     * <p>
+     *     If there is a task with priority {@link PrioritisedExecutor.Priority#IDLE} available then that task is only executed
+     *     when there are no other tasks available with a higher priority.
+     * </p>
+     * <p>
+     *     If there are no tasks that have priority {@link PrioritisedExecutor.Priority#BLOCKING} or {@link PrioritisedExecutor.Priority#IDLE}, then
+     *     this function will be biased to execute tasks that have higher priorities.
+     * </p>
+     *
+     * @return {@code true} if a task was executed, {@code false} otherwise
+     * @throws IllegalStateException If the current thread is not allowed to execute a task
+     */
+    public boolean executeTask() throws IllegalStateException;
+
+    /**
+     * Executes all queued tasks.
+     *
+     * @return {@code true} if a task was executed, {@code false} otherwise
+     * @throws IllegalStateException If the current thread is not allowed to execute a task
+     */
+    public default boolean executeAll() {
+        if (!this.executeTask()) {
+            return false;
+        }
+
+        while (this.executeTask());
+
+        return true;
+    }
+
+    /**
+     * Waits and executes tasks until the condition returns {@code true}.
+     * <p>
+     *     WARNING: This function is <i>not</i> suitable for waiting until a deadline!
+     *     Use {@link #executeUntil(long)} or {@link #executeConditionally(BooleanSupplier, long)} instead.
+     * </p>
+     */
+    public default void executeConditionally(final BooleanSupplier condition) {
+        long failures = 0;
+        while (!condition.getAsBoolean()) {
+            if (this.executeTask()) {
+                failures = failures >>> 2;
+            } else {
+                failures = ConcurrentUtil.linearLongBackoff(failures, 100_000L, 10_000_000L); // 100us, 10ms
+            }
+        }
+    }
+
+    /**
+     * Waits and executes tasks until the condition returns {@code true} or {@code System.nanoTime() >= deadline}.
+     */
+    public default void executeConditionally(final BooleanSupplier condition, final long deadline) {
+        long failures = 0;
+        // double check deadline; we don't know how expensive the condition is
+        while ((System.nanoTime() < deadline) && !condition.getAsBoolean() && (System.nanoTime() < deadline)) {
+            if (this.executeTask()) {
+                failures = failures >>> 2;
+            } else {
+                failures = ConcurrentUtil.linearLongBackoffDeadline(failures, 100_000L, 10_000_000L, deadline); // 100us, 10ms
+            }
+        }
+    }
+
+    /**
+     * Waits and executes tasks until {@code System.nanoTime() >= deadline}.
+     */
+    public default void executeUntil(final long deadline) {
+        long failures = 0;
+        while (System.nanoTime() < deadline) {
+            if (this.executeTask()) {
+                failures = failures >>> 2;
+            } else {
+                failures = ConcurrentUtil.linearLongBackoffDeadline(failures, 100_000L, 10_000_000L, deadline); // 100us, 10ms
+            }
+        }
+    }
+
+    /**
+     * Prevent further additions to this queue. Attempts to add after this call has completed (potentially during) will
+     * result in {@link IllegalStateException} being thrown.
+     * <p>
+     *     This operation is atomic with respect to other shutdown calls
+     * </p>
+     * <p>
+     *     After this call has completed, regardless of return value, this queue will be shutdown.
+     * </p>
+     *
+     * @return {@code true} if the queue was shutdown, {@code false} if it has shut down already
+     * @throws UnsupportedOperationException If this queue does not support shutdown
+     */
+    public default boolean shutdown() throws UnsupportedOperationException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Returns whether this queue has shut down. Effectively, whether new tasks will be rejected - this method
+     * does not indicate whether all of the tasks scheduled have been executed.
+     * @return Returns whether this queue has shut down.
+     */
+    public default boolean isShutdown() {
+        return false;
+    }
+
+    public static interface BaseTask extends Cancellable {
+
+        /**
+         * Causes a lazily queued task to become queued or executed
+         *
+         * @throws IllegalStateException If the backing queue has shutdown
+         * @return {@code true} If the task was queued, {@code false} if the task was already queued/cancelled/executed
+         */
+        public boolean queue();
+
+        /**
+         * Forces this task to be marked as completed.
+         *
+         * @return {@code true} if the task was cancelled, {@code false} if the task has already completed or is being completed.
+         */
+        @Override
+        public boolean cancel();
+
+        /**
+         * Executes this task. This will also mark the task as completing.
+         * <p>
+         *     Exceptions thrown from the runnable will be rethrown.
+         * </p>
+         *
+         * @return {@code true} if this task was executed, {@code false} if it was already marked as completed.
+         */
+        public boolean execute();
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/executor/Cancellable.java b/src/main/java/ca/spottedleaf/concurrentutil/executor/Cancellable.java
new file mode 100644
index 0000000000000000000000000000000000000000..11449056361bb6c5a055f543cdd135c4113757c6
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/executor/Cancellable.java
@@ -0,0 +1,14 @@
+package ca.spottedleaf.concurrentutil.executor;
+
+/**
+ * Interface specifying that something can be cancelled.
+ */
+public interface Cancellable {
+
+    /**
+     * Tries to cancel this task. If the task is in a stage that is too late to be cancelled, then this function
+     * will return {@code false}. If the task is already cancelled, then this function returns {@code false}. Only
+     * when this function successfully stops this task from being completed will it return {@code true}.
+     */
+    public boolean cancel();
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/DelayedPrioritisedTask.java b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/DelayedPrioritisedTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ce10053d4ec51855ad7012abb5d97df1c0e557a
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/DelayedPrioritisedTask.java
@@ -0,0 +1,170 @@
+package ca.spottedleaf.concurrentutil.executor.standard;
+
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import java.lang.invoke.VarHandle;
+
+public class DelayedPrioritisedTask {
+
+    protected volatile int priority;
+    protected static final VarHandle PRIORITY_HANDLE = ConcurrentUtil.getVarHandle(DelayedPrioritisedTask.class, "priority", int.class);
+
+    protected static final int PRIORITY_SET = Integer.MIN_VALUE >>> 0;
+
+    protected final int getPriorityVolatile() {
+        return (int)PRIORITY_HANDLE.getVolatile((DelayedPrioritisedTask)this);
+    }
+
+    protected final int compareAndExchangePriorityVolatile(final int expect, final int update) {
+        return (int)PRIORITY_HANDLE.compareAndExchange((DelayedPrioritisedTask)this, (int)expect, (int)update);
+    }
+
+    protected final int getAndOrPriorityVolatile(final int val) {
+        return (int)PRIORITY_HANDLE.getAndBitwiseOr((DelayedPrioritisedTask)this, (int)val);
+    }
+
+    protected final void setPriorityPlain(final int val) {
+        PRIORITY_HANDLE.set((DelayedPrioritisedTask)this, (int)val);
+    }
+
+    protected volatile PrioritisedExecutor.PrioritisedTask task;
+    protected static final VarHandle TASK_HANDLE = ConcurrentUtil.getVarHandle(DelayedPrioritisedTask.class, "task", PrioritisedExecutor.PrioritisedTask.class);
+
+    protected PrioritisedExecutor.PrioritisedTask getTaskPlain() {
+        return (PrioritisedExecutor.PrioritisedTask)TASK_HANDLE.get((DelayedPrioritisedTask)this);
+    }
+
+    protected PrioritisedExecutor.PrioritisedTask getTaskVolatile() {
+        return (PrioritisedExecutor.PrioritisedTask)TASK_HANDLE.getVolatile((DelayedPrioritisedTask)this);
+    }
+
+    protected final PrioritisedExecutor.PrioritisedTask compareAndExchangeTaskVolatile(final PrioritisedExecutor.PrioritisedTask expect, final PrioritisedExecutor.PrioritisedTask update) {
+        return (PrioritisedExecutor.PrioritisedTask)TASK_HANDLE.compareAndExchange((DelayedPrioritisedTask)this, (PrioritisedExecutor.PrioritisedTask)expect, (PrioritisedExecutor.PrioritisedTask)update);
+    }
+
+    public DelayedPrioritisedTask(final PrioritisedExecutor.Priority priority) {
+        this.setPriorityPlain(priority.priority);
+    }
+
+    // only public for debugging
+    public int getPriorityInternal() {
+        return this.getPriorityVolatile();
+    }
+
+    public PrioritisedExecutor.PrioritisedTask getTask() {
+        return this.getTaskVolatile();
+    }
+
+    public void setTask(final PrioritisedExecutor.PrioritisedTask task) {
+        int priority = this.getPriorityVolatile();
+
+        if (this.compareAndExchangeTaskVolatile(null, task) != null) {
+            throw new IllegalStateException("setTask() called twice");
+        }
+
+        int failures = 0;
+        for (;;) {
+            task.setPriority(PrioritisedExecutor.Priority.getPriority(priority));
+
+            if (priority == (priority = this.compareAndExchangePriorityVolatile(priority, priority | PRIORITY_SET))) {
+                return;
+            }
+
+            ++failures;
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+        }
+    }
+
+    public PrioritisedExecutor.Priority getPriority() {
+        final int priority = this.getPriorityVolatile();
+        if ((priority & PRIORITY_SET) != 0) {
+            return this.task.getPriority();
+        }
+
+        return PrioritisedExecutor.Priority.getPriority(priority);
+    }
+
+    public void raisePriority(final PrioritisedExecutor.Priority priority) {
+        if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+            throw new IllegalArgumentException("Invalid priority " + priority);
+        }
+
+        int failures = 0;
+        for (int curr = this.getPriorityVolatile();;) {
+            if ((curr & PRIORITY_SET) != 0) {
+                this.getTaskPlain().raisePriority(priority);
+                return;
+            }
+
+            if (!priority.isLowerPriority(curr)) {
+                return;
+            }
+
+            if (curr == (curr = this.compareAndExchangePriorityVolatile(curr, priority.priority))) {
+                return;
+            }
+
+            // failed, retry
+
+            ++failures;
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+        }
+    }
+
+    public void setPriority(final PrioritisedExecutor.Priority priority) {
+        if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+            throw new IllegalArgumentException("Invalid priority " + priority);
+        }
+
+        int failures = 0;
+        for (int curr = this.getPriorityVolatile();;) {
+            if ((curr & PRIORITY_SET) != 0) {
+                this.getTaskPlain().setPriority(priority);
+                return;
+            }
+
+            if (curr == (curr = this.compareAndExchangePriorityVolatile(curr, priority.priority))) {
+                return;
+            }
+
+            // failed, retry
+
+            ++failures;
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+        }
+    }
+
+    public void lowerPriority(final PrioritisedExecutor.Priority priority) {
+        if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+            throw new IllegalArgumentException("Invalid priority " + priority);
+        }
+
+        int failures = 0;
+        for (int curr = this.getPriorityVolatile();;) {
+            if ((curr & PRIORITY_SET) != 0) {
+                this.getTaskPlain().lowerPriority(priority);
+                return;
+            }
+
+            if (!priority.isHigherPriority(curr)) {
+                return;
+            }
+
+            if (curr == (curr = this.compareAndExchangePriorityVolatile(curr, priority.priority))) {
+                return;
+            }
+
+            // failed, retry
+
+            ++failures;
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedExecutor.java b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedExecutor.java
new file mode 100644
index 0000000000000000000000000000000000000000..e5d8ff730ba9d83efc2d80782de313a718bf55b3
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedExecutor.java
@@ -0,0 +1,246 @@
+package ca.spottedleaf.concurrentutil.executor.standard;
+
+import ca.spottedleaf.concurrentutil.executor.BaseExecutor;
+
+public interface PrioritisedExecutor extends BaseExecutor {
+
+    public static enum Priority {
+
+        /**
+         * Priority value indicating the task has completed or is being completed.
+         * This priority cannot be used to schedule tasks.
+         */
+        COMPLETING(-1),
+
+        /**
+         * Absolute highest priority, should only be used for when a task is blocking a time-critical thread.
+         */
+        BLOCKING(),
+
+        /**
+         * Should only be used for urgent but not time-critical tasks.
+         */
+        HIGHEST(),
+
+        /**
+         * Two priorities above normal.
+         */
+        HIGHER(),
+
+        /**
+         * One priority above normal.
+         */
+        HIGH(),
+
+        /**
+         * Default priority.
+         */
+        NORMAL(),
+
+        /**
+         * One priority below normal.
+         */
+        LOW(),
+
+        /**
+         * Two priorities below normal.
+         */
+        LOWER(),
+
+        /**
+         * Use for tasks that should eventually execute, but are not needed to.
+         */
+        LOWEST(),
+
+        /**
+         * Use for tasks that can be delayed indefinitely.
+         */
+        IDLE();
+
+        // returns whether the priority can be scheduled
+        public static boolean isValidPriority(final Priority priority) {
+            return priority != null && priority != Priority.COMPLETING;
+        }
+
+        // returns the higher priority of the two
+        public static PrioritisedExecutor.Priority max(final Priority p1, final Priority p2) {
+            return p1.isHigherOrEqualPriority(p2) ? p1 : p2;
+        }
+
+        // returns the lower priroity of the two
+        public static PrioritisedExecutor.Priority min(final Priority p1, final Priority p2) {
+            return p1.isLowerOrEqualPriority(p2) ? p1 : p2;
+        }
+
+        public boolean isHigherOrEqualPriority(final Priority than) {
+            return this.priority <= than.priority;
+        }
+
+        public boolean isHigherPriority(final Priority than) {
+            return this.priority < than.priority;
+        }
+
+        public boolean isLowerOrEqualPriority(final Priority than) {
+            return this.priority >= than.priority;
+        }
+
+        public boolean isLowerPriority(final Priority than) {
+            return this.priority > than.priority;
+        }
+
+        public boolean isHigherOrEqualPriority(final int than) {
+            return this.priority <= than;
+        }
+
+        public boolean isHigherPriority(final int than) {
+            return this.priority < than;
+        }
+
+        public boolean isLowerOrEqualPriority(final int than) {
+            return this.priority >= than;
+        }
+
+        public boolean isLowerPriority(final int than) {
+            return this.priority > than;
+        }
+
+        public static boolean isHigherOrEqualPriority(final int priority, final int than) {
+            return priority <= than;
+        }
+
+        public static boolean isHigherPriority(final int priority, final int than) {
+            return priority < than;
+        }
+
+        public static boolean isLowerOrEqualPriority(final int priority, final int than) {
+            return priority >= than;
+        }
+
+        public static boolean isLowerPriority(final int priority, final int than) {
+            return priority > than;
+        }
+
+        static final PrioritisedExecutor.Priority[] PRIORITIES = PrioritisedExecutor.Priority.values();
+
+        /** includes special priorities */
+        public static final int TOTAL_PRIORITIES = PRIORITIES.length;
+
+        public static final int TOTAL_SCHEDULABLE_PRIORITIES = TOTAL_PRIORITIES - 1;
+
+        public static PrioritisedExecutor.Priority getPriority(final int priority) {
+            return PRIORITIES[priority + 1];
+        }
+
+        private static int priorityCounter;
+
+        private static int nextCounter() {
+            return priorityCounter++;
+        }
+
+        public final int priority;
+
+        Priority() {
+            this(nextCounter());
+        }
+
+        Priority(final int priority) {
+            this.priority = priority;
+        }
+    }
+
+    /**
+     * Queues or executes a task at {@link Priority#NORMAL} priority.
+     * @param task The task to run.
+     *
+     * @throws IllegalStateException If this queue has shutdown.
+     * @throws NullPointerException If the task is null
+     * @return {@code null} if the current thread immediately executed the task, else returns the prioritised task
+     * associated with the parameter
+     */
+    public default PrioritisedTask queueRunnable(final Runnable task) {
+        return this.queueRunnable(task, PrioritisedExecutor.Priority.NORMAL);
+    }
+
+    /**
+     * Queues or executes a task.
+     *
+     * @param task The task to run.
+     * @param priority The priority for the task.
+     *
+     * @throws IllegalStateException If this queue has shutdown.
+     * @throws NullPointerException If the task is null
+     * @throws IllegalArgumentException If the priority is invalid.
+     * @return {@code null} if the current thread immediately executed the task, else returns the prioritised task
+     * associated with the parameter
+     */
+    public PrioritisedTask queueRunnable(final Runnable task, final PrioritisedExecutor.Priority priority);
+
+    /**
+     * Creates, but does not execute or queue the task. The task must later be queued via {@link BaseExecutor.BaseTask#queue()}.
+     *
+     * @param task The task to run.
+     *
+     * @throws IllegalStateException If this queue has shutdown.
+     * @throws NullPointerException If the task is null
+     * @throws IllegalArgumentException If the priority is invalid.
+     * @throws UnsupportedOperationException If this executor does not support lazily queueing tasks
+     * @return The prioritised task associated with the parameters
+     */
+    public default PrioritisedExecutor.PrioritisedTask createTask(final Runnable task) {
+        return this.createTask(task, PrioritisedExecutor.Priority.NORMAL);
+    }
+
+    /**
+     * Creates, but does not execute or queue the task. The task must later be queued via {@link BaseExecutor.BaseTask#queue()}.
+     *
+     * @param task The task to run.
+     * @param priority The priority for the task.
+     *
+     * @throws IllegalStateException If this queue has shutdown.
+     * @throws NullPointerException If the task is null
+     * @throws IllegalArgumentException If the priority is invalid.
+     * @throws UnsupportedOperationException If this executor does not support lazily queueing tasks
+     * @return The prioritised task associated with the parameters
+     */
+    public PrioritisedExecutor.PrioritisedTask createTask(final Runnable task, final PrioritisedExecutor.Priority priority);
+
+    public static interface PrioritisedTask extends BaseTask {
+
+        /**
+         * Returns the current priority. Note that {@link PrioritisedExecutor.Priority#COMPLETING} will be returned
+         * if this task is completing or has completed.
+         */
+        public PrioritisedExecutor.Priority getPriority();
+
+        /**
+         * Attempts to set this task's priority level to the level specified.
+         *
+         * @param priority Specified priority level.
+         *
+         * @throws IllegalArgumentException If the priority is invalid
+         * @return {@code true} if successful, {@code false} if this task is completing or has completed or the queue
+         * this task was scheduled on was shutdown, or if the priority was already at the specified level.
+         */
+        public boolean setPriority(final PrioritisedExecutor.Priority priority);
+
+        /**
+         * Attempts to raise the priority to the priority level specified.
+         *
+         * @param priority Priority specified
+         *
+         * @throws IllegalArgumentException If the priority is invalid
+         * @return {@code false} if the current task is completing, {@code true} if the priority was raised to the specified level or was already at the specified level or higher.
+         */
+        public boolean raisePriority(final PrioritisedExecutor.Priority priority);
+
+        /**
+         * Attempts to lower the priority to the priority level specified.
+         *
+         * @param priority Priority specified
+         *
+         * @throws IllegalArgumentException If the priority is invalid
+         * @return {@code false} if the current task is completing, {@code true} if the priority was lowered to the specified level or was already at the specified level or lower.
+         */
+        public boolean lowerPriority(final PrioritisedExecutor.Priority priority);
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedQueueExecutorThread.java b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedQueueExecutorThread.java
new file mode 100644
index 0000000000000000000000000000000000000000..91fe0f7049122f62f05ba09c24cba5d758340cff
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedQueueExecutorThread.java
@@ -0,0 +1,297 @@
+package ca.spottedleaf.concurrentutil.executor.standard;
+
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import com.mojang.logging.LogUtils;
+import org.slf4j.Logger;
+import java.lang.invoke.VarHandle;
+import java.util.concurrent.locks.LockSupport;
+
+/**
+ * Thread which will continuously drain from a specified queue.
+ * <p>
+ *     Note: When using this thread, queue additions to the underlying {@link #queue} are not sufficient to get this thread
+ *     to execute the task. The function {@link #notifyTasks()} must be used after scheduling a task. For expected behaviour
+ *     of task scheduling (thread wakes up after tasks are scheduled), use the methods provided on {@link PrioritisedExecutor}
+ *     methods.
+ * </p>
+ */
+public class PrioritisedQueueExecutorThread extends Thread implements PrioritisedExecutor {
+
+    private static final Logger LOGGER = LogUtils.getLogger();
+
+    protected final PrioritisedExecutor queue;
+
+    protected volatile boolean threadShutdown;
+
+    protected static final VarHandle THREAD_PARKED_HANDLE = ConcurrentUtil.getVarHandle(PrioritisedQueueExecutorThread.class, "threadParked", boolean.class);
+    protected volatile boolean threadParked;
+
+    protected volatile boolean halted;
+
+    protected final long spinWaitTime;
+
+    static final long DEFAULT_SPINWAIT_TIME = (long)(0.1e6);// 0.1ms
+
+    public PrioritisedQueueExecutorThread(final PrioritisedExecutor queue) {
+        this(queue, DEFAULT_SPINWAIT_TIME); // 0.1ms
+    }
+
+    public PrioritisedQueueExecutorThread(final PrioritisedExecutor queue, final long spinWaitTime) { // in ns
+        this.queue = queue;
+        this.spinWaitTime = spinWaitTime;
+    }
+
+    @Override
+    public void run() {
+        final long spinWaitTime = this.spinWaitTime;
+
+        main_loop:
+        for (;;) {
+            this.pollTasks();
+
+            // spinwait
+
+            final long start = System.nanoTime();
+
+            for (;;) {
+                // If we are interrupted for any reason, park() will always return immediately. Clear so that we don't needlessly use cpu in such an event.
+                Thread.interrupted();
+                Thread.yield();
+                LockSupport.parkNanos("Spinwaiting on tasks", 10_000L); // 10us
+
+                if (this.pollTasks()) {
+                    // restart loop, found tasks
+                    continue main_loop;
+                }
+
+                if (this.handleClose()) {
+                    return; // we're done
+                }
+
+                if ((System.nanoTime() - start) >= spinWaitTime) {
+                    break;
+                }
+            }
+
+            if (this.handleClose()) {
+                return;
+            }
+
+            this.setThreadParkedVolatile(true);
+
+            // We need to parse here to avoid a race condition where a thread queues a task before we set parked to true
+            // (i.e it will not notify us)
+            if (this.pollTasks()) {
+                this.setThreadParkedVolatile(false);
+                continue;
+            }
+
+            if (this.handleClose()) {
+                return;
+            }
+
+            // we don't need to check parked before sleeping, but we do need to check parked in a do-while loop
+            // LockSupport.park() can fail for any reason
+            while (this.getThreadParkedVolatile()) {
+                Thread.interrupted();
+                LockSupport.park("Waiting on tasks");
+            }
+        }
+    }
+
+    protected boolean pollTasks() {
+        boolean ret = false;
+
+        for (;;) {
+            if (this.halted) {
+                break;
+            }
+            try {
+                if (!this.queue.executeTask()) {
+                    break;
+                }
+                ret = true;
+            } catch (final ThreadDeath death) {
+                throw death; // goodbye world...
+            } catch (final Throwable throwable) {
+                LOGGER.error("Exception thrown from prioritized runnable task in thread '" + this.getName() + "'", throwable);
+            }
+        }
+
+        return ret;
+    }
+
+    protected boolean handleClose() {
+        if (this.threadShutdown) {
+            this.pollTasks(); // this ensures we've emptied the queue
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Notify this thread that a task has been added to its queue
+     * @return {@code true} if this thread was waiting for tasks, {@code false} if it is executing tasks
+     */
+    public boolean notifyTasks() {
+        if (this.getThreadParkedVolatile() && this.exchangeThreadParkedVolatile(false)) {
+            LockSupport.unpark(this);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public PrioritisedTask createTask(final Runnable task, final Priority priority) {
+        final PrioritisedExecutor.PrioritisedTask queueTask = this.queue.createTask(task, priority);
+
+        // need to override queue() to notify us of tasks
+        return new PrioritisedTask() {
+            @Override
+            public Priority getPriority() {
+                return queueTask.getPriority();
+            }
+
+            @Override
+            public boolean setPriority(final Priority priority) {
+                return queueTask.setPriority(priority);
+            }
+
+            @Override
+            public boolean raisePriority(final Priority priority) {
+                return queueTask.raisePriority(priority);
+            }
+
+            @Override
+            public boolean lowerPriority(final Priority priority) {
+                return queueTask.lowerPriority(priority);
+            }
+
+            @Override
+            public boolean queue() {
+                final boolean ret = queueTask.queue();
+                if (ret) {
+                    PrioritisedQueueExecutorThread.this.notifyTasks();
+                }
+                return ret;
+            }
+
+            @Override
+            public boolean cancel() {
+                return queueTask.cancel();
+            }
+
+            @Override
+            public boolean execute() {
+                return queueTask.execute();
+            }
+        };
+    }
+
+    @Override
+    public PrioritisedExecutor.PrioritisedTask queueRunnable(final Runnable task, final PrioritisedExecutor.Priority priority) {
+        final PrioritisedExecutor.PrioritisedTask ret = this.queue.queueRunnable(task, priority);
+
+        this.notifyTasks();
+
+        return ret;
+    }
+
+    @Override
+    public boolean haveAllTasksExecuted() {
+        return this.queue.haveAllTasksExecuted();
+    }
+
+    @Override
+    public long getTotalTasksExecuted() {
+        return this.queue.getTotalTasksExecuted();
+    }
+
+    @Override
+    public long getTotalTasksScheduled() {
+        return this.queue.getTotalTasksScheduled();
+    }
+
+    /**
+     * {@inheritDoc}
+     * @throws IllegalStateException If the current thread is {@code this} thread, or the underlying queue throws this exception.
+     */
+    @Override
+    public void waitUntilAllExecuted() throws IllegalStateException {
+        if (Thread.currentThread() == this) {
+            throw new IllegalStateException("Cannot block on our own queue");
+        }
+        this.queue.waitUntilAllExecuted();
+    }
+
+    /**
+     * {@inheritDoc}
+     * @throws IllegalStateException Always
+     */
+    @Override
+    public boolean executeTask() throws IllegalStateException {
+        throw new IllegalStateException();
+    }
+
+    /**
+     * Closes this queue executor's queue. Optionally waits for all tasks in queue to be executed if {@code wait} is true.
+     * <p>
+     *     This function is MT-Safe.
+     * </p>
+     * @param wait If this call is to wait until the queue is empty and there are no tasks executing in the queue.
+     * @param killQueue Whether to shutdown this thread's queue
+     * @return whether this thread shut down the queue
+     * @see #halt(boolean)
+     */
+    public boolean close(final boolean wait, final boolean killQueue) {
+        final boolean ret = killQueue && this.queue.shutdown();
+        this.threadShutdown = true;
+
+        // force thread to respond to the shutdown
+        this.setThreadParkedVolatile(false);
+        LockSupport.unpark(this);
+
+        if (wait) {
+            this.waitUntilAllExecuted();
+        }
+
+        return ret;
+    }
+
+
+    /**
+     * Causes this thread to exit without draining the queue. To ensure tasks are completed, use {@link #close(boolean, boolean)}.
+     * <p>
+     *     This is not safe to call with {@link #close(boolean, boolean)} if <code>wait = true</code>, in which case
+     *     the waiting thread may block indefinitely.
+     * </p>
+     * <p>
+     *     This function is MT-Safe.
+     * </p>
+     * @param killQueue Whether to shutdown this thread's queue
+     * @see #close(boolean, boolean)
+     */
+    public void halt(final boolean killQueue) {
+        if (killQueue) {
+            this.queue.shutdown();
+        }
+        this.threadShutdown = true;
+        this.halted = true;
+
+        // force thread to respond to the shutdown
+        this.setThreadParkedVolatile(false);
+        LockSupport.unpark(this);
+    }
+
+    protected final boolean getThreadParkedVolatile() {
+        return (boolean)THREAD_PARKED_HANDLE.getVolatile(this);
+    }
+
+    protected final boolean exchangeThreadParkedVolatile(final boolean value) {
+        return (boolean)THREAD_PARKED_HANDLE.getAndSet(this, value);
+    }
+
+    protected final void setThreadParkedVolatile(final boolean value) {
+        THREAD_PARKED_HANDLE.setVolatile(this, value);
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedThreadPool.java b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedThreadPool.java
new file mode 100644
index 0000000000000000000000000000000000000000..26fa2caa18a9194e57574a4a7fa9f7a4265740e0
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedThreadPool.java
@@ -0,0 +1,579 @@
+package ca.spottedleaf.concurrentutil.executor.standard;
+
+import com.mojang.logging.LogUtils;
+import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
+import org.slf4j.Logger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiConsumer;
+
+public final class PrioritisedThreadPool {
+
+    private static final Logger LOGGER = LogUtils.getLogger();
+
+    protected final PrioritisedThread[] threads;
+    protected final TreeSet<PrioritisedPoolExecutorImpl> queues = new TreeSet<>(PrioritisedPoolExecutorImpl.comparator());
+    protected final String name;
+    protected final long queueMaxHoldTime;
+
+    protected final ReferenceOpenHashSet<PrioritisedPoolExecutorImpl> nonShutdownQueues = new ReferenceOpenHashSet<>();
+    protected final ReferenceOpenHashSet<PrioritisedPoolExecutorImpl> activeQueues = new ReferenceOpenHashSet<>();
+
+    protected boolean shutdown;
+
+    protected long schedulingIdGenerator;
+
+    protected static final long DEFAULT_QUEUE_HOLD_TIME = (long)(5.0e6);
+
+    public PrioritisedThreadPool(final String name, final int threads) {
+        this(name, threads, null);
+    }
+
+    public PrioritisedThreadPool(final String name, final int threads, final BiConsumer<Thread, Integer> threadModifier) {
+        this(name, threads, threadModifier, DEFAULT_QUEUE_HOLD_TIME); // 5ms
+    }
+
+    public PrioritisedThreadPool(final String name, final int threads, final BiConsumer<Thread, Integer> threadModifier,
+                                 final long queueHoldTime) { // in ns
+        if (threads <= 0) {
+            throw new IllegalArgumentException("Thread count must be > 0, not " + threads);
+        }
+        if (name == null) {
+            throw new IllegalArgumentException("Name cannot be null");
+        }
+        this.name = name;
+        this.queueMaxHoldTime = queueHoldTime;
+
+        this.threads = new PrioritisedThread[threads];
+        for (int i = 0; i < threads; ++i) {
+            this.threads[i] = new PrioritisedThread(this);
+
+            // set default attributes
+            this.threads[i].setName("Prioritised thread for pool '" + name + "' #" + i);
+            this.threads[i].setUncaughtExceptionHandler((final Thread thread, final Throwable throwable) -> {
+                LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable);
+            });
+
+            // let thread modifier override defaults
+            if (threadModifier != null) {
+                threadModifier.accept(this.threads[i], Integer.valueOf(i));
+            }
+
+            // now the thread can start
+            this.threads[i].start();
+        }
+    }
+
+    public Thread[] getThreads() {
+        return Arrays.copyOf(this.threads, this.threads.length, Thread[].class);
+    }
+
+    public PrioritisedPoolExecutor createExecutor(final String name, final int parallelism) {
+        synchronized (this.nonShutdownQueues) {
+            if (this.shutdown) {
+                throw new IllegalStateException("Queue is shutdown: " + this.toString());
+            }
+            final PrioritisedPoolExecutorImpl ret = new PrioritisedPoolExecutorImpl(this, name, Math.min(Math.max(1, parallelism), this.threads.length));
+
+            this.nonShutdownQueues.add(ret);
+
+            synchronized (this.activeQueues) {
+                this.activeQueues.add(ret);
+            }
+
+            return ret;
+        }
+    }
+
+    /**
+     * Prevents creation of new queues, shutdowns all non-shutdown queues if specified
+     */
+    public void halt(final boolean shutdownQueues) {
+        synchronized (this.nonShutdownQueues) {
+            this.shutdown = true;
+        }
+        if (shutdownQueues) {
+            final ArrayList<PrioritisedPoolExecutorImpl> queuesToShutdown;
+            synchronized (this.nonShutdownQueues) {
+                this.shutdown = true;
+                queuesToShutdown = new ArrayList<>(this.nonShutdownQueues);
+            }
+
+            for (final PrioritisedPoolExecutorImpl queue : queuesToShutdown) {
+                queue.shutdown();
+            }
+        }
+
+
+        for (final PrioritisedThread thread : this.threads) {
+            // can't kill queue, queue is null
+            thread.halt(false);
+        }
+    }
+
+    /**
+     * Waits until all threads in this pool have shutdown, or until the specified time has passed.
+     * @param msToWait Maximum time to wait.
+     * @return {@code false} if the maximum time passed, {@code true} otherwise.
+     */
+    public boolean join(final long msToWait) {
+        try {
+            return this.join(msToWait, false);
+        } catch (final InterruptedException ex) {
+            throw new IllegalStateException(ex);
+        }
+    }
+
+    /**
+     * Waits until all threads in this pool have shutdown, or until the specified time has passed.
+     * @param msToWait Maximum time to wait.
+     * @return {@code false} if the maximum time passed, {@code true} otherwise.
+     * @throws InterruptedException If this thread is interrupted.
+     */
+    public boolean joinInterruptable(final long msToWait) throws InterruptedException {
+        return this.join(msToWait, true);
+    }
+
+    protected final boolean join(final long msToWait, final boolean interruptable) throws InterruptedException {
+        final long nsToWait = msToWait * (1000 * 1000);
+        final long start = System.nanoTime();
+        final long deadline = start + nsToWait;
+        boolean interrupted = false;
+        try {
+            for (final PrioritisedThread thread : this.threads) {
+                for (;;) {
+                    if (!thread.isAlive()) {
+                        break;
+                    }
+                    final long current = System.nanoTime();
+                    if (current >= deadline) {
+                        return false;
+                    }
+
+                    try {
+                        thread.join(Math.max(1L, (deadline - current) / (1000 * 1000)));
+                    } catch (final InterruptedException ex) {
+                        if (interruptable) {
+                            throw ex;
+                        }
+                        interrupted = true;
+                    }
+                }
+            }
+
+            return true;
+        } finally {
+            if (interrupted) {
+                Thread.currentThread().interrupt();
+            }
+        }
+    }
+
+    public void shutdown(final boolean wait) {
+        final ArrayList<PrioritisedPoolExecutorImpl> queuesToShutdown;
+        synchronized (this.nonShutdownQueues) {
+            this.shutdown = true;
+            queuesToShutdown = new ArrayList<>(this.nonShutdownQueues);
+        }
+
+        for (final PrioritisedPoolExecutorImpl queue : queuesToShutdown) {
+            queue.shutdown();
+        }
+
+        for (final PrioritisedThread thread : this.threads) {
+            // none of these can be true or else NPE
+            thread.close(false, false);
+        }
+
+        if (wait) {
+            final ArrayList<PrioritisedPoolExecutorImpl> queues;
+            synchronized (this.activeQueues) {
+                queues = new ArrayList<>(this.activeQueues);
+            }
+            for (final PrioritisedPoolExecutorImpl queue : queues) {
+                queue.waitUntilAllExecuted();
+            }
+        }
+    }
+
+    protected static final class PrioritisedThread extends PrioritisedQueueExecutorThread {
+
+        protected final PrioritisedThreadPool pool;
+        protected final AtomicBoolean alertedHighPriority = new AtomicBoolean();
+
+        public PrioritisedThread(final PrioritisedThreadPool pool) {
+            super(null);
+            this.pool = pool;
+        }
+
+        public boolean alertHighPriorityExecutor() {
+            if (!this.notifyTasks()) {
+                if (!this.alertedHighPriority.get()) {
+                    this.alertedHighPriority.set(true);
+                }
+                return false;
+            }
+
+            return true;
+        }
+
+        private boolean isAlertedHighPriority() {
+            return this.alertedHighPriority.get() && this.alertedHighPriority.getAndSet(false);
+        }
+
+        @Override
+        protected boolean pollTasks() {
+            final PrioritisedThreadPool pool = this.pool;
+            final TreeSet<PrioritisedPoolExecutorImpl> queues = this.pool.queues;
+
+            boolean ret = false;
+            for (;;) {
+                if (this.halted) {
+                    break;
+                }
+                // try to find a queue
+                // note that if and ONLY IF the queues set is empty, this means there are no tasks for us to execute.
+                // so we can only break when it's empty
+                final PrioritisedPoolExecutorImpl queue;
+                // select queue
+                synchronized (queues) {
+                    queue = queues.pollFirst();
+                    if (queue == null) {
+                        // no tasks to execute
+                        break;
+                    }
+
+                    queue.schedulingId = ++pool.schedulingIdGenerator;
+                    // we own this queue now, so increment the executor count
+                    // do we also need to push this queue up for grabs for another executor?
+                    if (++queue.concurrentExecutors < queue.maximumExecutors) {
+                        // re-add to queues
+                        // it's very important this is done in the same synchronised block for polling, as this prevents
+                        // us from possibly later adding a queue that should not exist in the set
+                        queues.add(queue);
+                        queue.isQueued = true;
+                    } else {
+                        queue.isQueued = false;
+                    }
+                    // note: we cannot drain entries from the queue while holding this lock, as it will cause deadlock
+                    // the queue addition holds the per-queue lock first then acquires the lock we have now, but if we
+                    // try to poll now we don't hold the per queue lock but we do hold the global lock...
+                }
+
+                // parse tasks as long as we are allowed
+                final long start = System.nanoTime();
+                final long deadline = start + pool.queueMaxHoldTime;
+                do {
+                    try {
+                        if (this.halted) {
+                            break;
+                        }
+                        if (!queue.executeTask()) {
+                            // no more tasks, try next queue
+                            break;
+                        }
+                        ret = true;
+                    } catch (final ThreadDeath death) {
+                        throw death; // goodbye world...
+                    } catch (final Throwable throwable) {
+                        LOGGER.error("Exception thrown from thread '" + this.getName() + "' in queue '" + queue.toString() + "'", throwable);
+                    }
+                } while (!this.isAlertedHighPriority() && System.nanoTime() <= deadline);
+
+                synchronized (queues) {
+                    // decrement executors, we are no longer executing
+                    if (queue.isQueued) {
+                        queues.remove(queue);
+                        queue.isQueued = false;
+                    }
+                    if (--queue.concurrentExecutors == 0 && queue.scheduledPriority == null) {
+                        // reset scheduling id once the queue is empty again
+                        // this will ensure empty queues are not prioritised suddenly over active queues once tasks are
+                        // queued
+                        queue.schedulingId = 0L;
+                    }
+
+                    // ensure the executor is queued for execution again
+                    if (!queue.isHalted && queue.scheduledPriority != null) { // make sure it actually has tasks
+                        queues.add(queue);
+                        queue.isQueued = true;
+                    }
+                }
+            }
+
+            return ret;
+        }
+    }
+
+    public interface PrioritisedPoolExecutor extends PrioritisedExecutor {
+
+        /**
+         * Removes this queue from the thread pool without shutting the queue down or waiting for queued tasks to be executed
+         */
+        public void halt();
+
+        /**
+         * Returns whether this executor is scheduled to run tasks or is running tasks, otherwise it returns whether
+         * this queue is not halted and not shutdown.
+         */
+        public boolean isActive();
+    }
+
+    protected static final class PrioritisedPoolExecutorImpl extends PrioritisedThreadedTaskQueue implements PrioritisedPoolExecutor {
+
+        protected final PrioritisedThreadPool pool;
+        protected final long[] priorityCounts = new long[Priority.TOTAL_SCHEDULABLE_PRIORITIES];
+        protected long schedulingId;
+        protected int concurrentExecutors;
+        protected Priority scheduledPriority;
+
+        protected final String name;
+        protected final int maximumExecutors;
+        protected boolean isQueued;
+
+        public PrioritisedPoolExecutorImpl(final PrioritisedThreadPool pool, final String name, final int maximumExecutors) {
+            this.pool = pool;
+            this.name = name;
+            this.maximumExecutors = maximumExecutors;
+        }
+
+        public static Comparator<PrioritisedPoolExecutorImpl> comparator() {
+            return (final PrioritisedPoolExecutorImpl p1, final PrioritisedPoolExecutorImpl p2) -> {
+                if (p1 == p2) {
+                    return 0;
+                }
+
+                // prefer higher priority
+                final int priorityCompare = p1.scheduledPriority.ordinal() - p2.scheduledPriority.ordinal();
+                if (priorityCompare != 0) {
+                    return priorityCompare;
+                }
+
+                // try to spread out the executors so that each can have threads executing
+                final int executorCompare = p1.concurrentExecutors - p2.concurrentExecutors;
+                if (executorCompare != 0) {
+                    return executorCompare;
+                }
+
+                // if all else fails here we just choose whichever executor was queued first
+                return Long.compare(p1.schedulingId, p2.schedulingId);
+            };
+        }
+
+        private boolean isHalted;
+
+        @Override
+        public void halt() {
+            final PrioritisedThreadPool pool = this.pool;
+            final TreeSet<PrioritisedPoolExecutorImpl> queues = pool.queues;
+            synchronized (queues) {
+                if (this.isHalted) {
+                    return;
+                }
+                this.isHalted = true;
+                if (this.isQueued) {
+                    queues.remove(this);
+                    this.isQueued = false;
+                }
+            }
+            synchronized (pool.nonShutdownQueues) {
+                pool.nonShutdownQueues.remove(this);
+            }
+            synchronized (pool.activeQueues) {
+                pool.activeQueues.remove(this);
+            }
+        }
+
+        @Override
+        public boolean isActive() {
+            final PrioritisedThreadPool pool = this.pool;
+            final TreeSet<PrioritisedPoolExecutorImpl> queues = pool.queues;
+
+            synchronized (queues) {
+                if (this.concurrentExecutors != 0) {
+                    return true;
+                }
+                synchronized (pool.activeQueues) {
+                    if (pool.activeQueues.contains(this)) {
+                        return true;
+                    }
+                }
+            }
+
+            return false;
+        }
+
+        private long totalQueuedTasks = 0L;
+
+        @Override
+        protected void priorityChange(final PrioritisedThreadedTaskQueue.PrioritisedTask task, final Priority from, final Priority to) {
+            // Note: The superclass' queue lock is ALWAYS held when inside this method. So we do NOT need to do any additional synchronisation
+            // for accessing this queue's state.
+            final long[] priorityCounts = this.priorityCounts;
+            final boolean shutdown = this.isShutdown();
+
+            if (from == null && to == Priority.COMPLETING) {
+                throw new IllegalStateException("Cannot complete task without queueing it first");
+            }
+
+            // we should only notify for queueing of tasks, not changing priorities
+            final boolean shouldNotifyTasks = from == null;
+
+            final Priority scheduledPriority = this.scheduledPriority;
+            if (from != null) {
+                --priorityCounts[from.priority];
+            }
+            if (to != Priority.COMPLETING) {
+                ++priorityCounts[to.priority];
+            }
+            final long totalQueuedTasks;
+            if (to == Priority.COMPLETING) {
+                totalQueuedTasks = --this.totalQueuedTasks;
+            } else if (from == null) {
+                totalQueuedTasks = ++this.totalQueuedTasks;
+            } else {
+                totalQueuedTasks = this.totalQueuedTasks;
+            }
+
+            // find new highest priority
+            int highest = Math.min(to == Priority.COMPLETING ? Priority.IDLE.priority : to.priority, scheduledPriority == null ? Priority.IDLE.priority : scheduledPriority.priority);
+            int lowestPriority = priorityCounts.length; // exclusive
+            for (;highest < lowestPriority; ++highest) {
+                final long count = priorityCounts[highest];
+                if (count < 0) {
+                    throw new IllegalStateException("Priority " + highest + " has " + count + " scheduled tasks");
+                }
+
+                if (count != 0) {
+                    break;
+                }
+            }
+
+            final Priority newPriority;
+            if (highest == lowestPriority) {
+                // no tasks left
+                newPriority = null;
+            } else if (shutdown) {
+                // whichever is lower, the actual greatest priority or simply HIGHEST
+                // this is so shutdown automatically gets priority
+                newPriority = Priority.getPriority(Math.min(highest, Priority.HIGHEST.priority));
+            } else {
+                newPriority = Priority.getPriority(highest);
+            }
+
+            final int executorsWanted;
+            boolean shouldNotifyHighPriority = false;
+
+            final PrioritisedThreadPool pool = this.pool;
+            final TreeSet<PrioritisedPoolExecutorImpl> queues = pool.queues;
+
+            synchronized (queues) {
+                if (!this.isQueued) {
+                    // see if we need to be queued
+                    if (newPriority != null) {
+                        if (this.schedulingId == 0L) {
+                            this.schedulingId = ++pool.schedulingIdGenerator;
+                        }
+                        this.scheduledPriority = newPriority; // must be updated before queue add
+                        if (!this.isHalted && this.concurrentExecutors < this.maximumExecutors) {
+                            shouldNotifyHighPriority = newPriority.isHigherOrEqualPriority(Priority.HIGH);
+                            queues.add(this);
+                            this.isQueued = true;
+                        }
+                    } else {
+                        // do not queue
+                        this.scheduledPriority = null;
+                    }
+                } else {
+                    // see if we need to NOT be queued
+                    if (newPriority == null) {
+                        queues.remove(this);
+                        this.scheduledPriority = null;
+                        this.isQueued = false;
+                    } else if (scheduledPriority != newPriority) {
+                        // if our priority changed, we need to update it - which means removing and re-adding into the queue
+                        queues.remove(this);
+                        // only now can we update scheduledPriority, since we are no longer in queue
+                        this.scheduledPriority = newPriority;
+                        queues.add(this);
+                        shouldNotifyHighPriority = (scheduledPriority == null || scheduledPriority.isLowerPriority(Priority.HIGH)) && newPriority.isHigherOrEqualPriority(Priority.HIGH);
+                    }
+                }
+
+                if (this.isQueued) {
+                    executorsWanted = Math.min(this.maximumExecutors - this.concurrentExecutors, (int)totalQueuedTasks);
+                } else {
+                    executorsWanted = 0;
+                }
+            }
+
+            if (newPriority == null && shutdown) {
+                synchronized (pool.activeQueues) {
+                    pool.activeQueues.remove(this);
+                }
+            }
+
+            // Wake up the number of executors we want
+            if (executorsWanted > 0 || (shouldNotifyTasks | shouldNotifyHighPriority)) {
+                int notified = 0;
+                for (final PrioritisedThread thread : pool.threads) {
+                    if ((shouldNotifyHighPriority ? thread.alertHighPriorityExecutor() : thread.notifyTasks())
+                            && (++notified >= executorsWanted)) {
+                        break;
+                    }
+                }
+            }
+        }
+
+        @Override
+        public boolean shutdown() {
+            final boolean ret = super.shutdown();
+            if (!ret) {
+                return ret;
+            }
+
+            final PrioritisedThreadPool pool = this.pool;
+
+            // remove from active queues
+            synchronized (pool.nonShutdownQueues) {
+                pool.nonShutdownQueues.remove(this);
+            }
+
+            final TreeSet<PrioritisedPoolExecutorImpl> queues = pool.queues;
+
+            // try and shift around our priority
+            synchronized (queues) {
+                if (this.scheduledPriority == null) {
+                    // no tasks are queued, ensure we aren't in activeQueues
+                    synchronized (pool.activeQueues) {
+                        pool.activeQueues.remove(this);
+                    }
+
+                    return ret;
+                }
+
+                // try to set scheduled priority to HIGHEST so it drains faster
+
+                if (this.scheduledPriority.isHigherOrEqualPriority(Priority.HIGHEST)) {
+                    // already at target priority (highest or above)
+                    return ret;
+                }
+
+                // shift priority to HIGHEST
+
+                if (this.isQueued) {
+                    queues.remove(this);
+                    this.scheduledPriority = Priority.HIGHEST;
+                    queues.add(this);
+                } else {
+                    this.scheduledPriority = Priority.HIGHEST;
+                }
+            }
+
+            return ret;
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedThreadedTaskQueue.java b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedThreadedTaskQueue.java
new file mode 100644
index 0000000000000000000000000000000000000000..b71404be2c82f7db35272b367af861e94d6c73d3
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/executor/standard/PrioritisedThreadedTaskQueue.java
@@ -0,0 +1,378 @@
+package ca.spottedleaf.concurrentutil.executor.standard;
+
+import java.util.ArrayDeque;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class PrioritisedThreadedTaskQueue implements PrioritisedExecutor {
+
+    protected final ArrayDeque<PrioritisedTask>[] queues = new ArrayDeque[Priority.TOTAL_SCHEDULABLE_PRIORITIES]; {
+        for (int i = 0; i < Priority.TOTAL_SCHEDULABLE_PRIORITIES; ++i) {
+            this.queues[i] = new ArrayDeque<>();
+        }
+    }
+
+    // Use AtomicLong to separate from the queue field, we don't want false sharing here.
+    protected final AtomicLong totalScheduledTasks = new AtomicLong();
+    protected final AtomicLong totalCompletedTasks = new AtomicLong();
+
+    // this is here to prevent failures to queue stalling flush() calls (as the schedule calls would increment totalScheduledTasks without this check)
+    protected volatile boolean hasShutdown;
+
+    protected long taskIdGenerator = 0;
+
+    @Override
+    public PrioritisedExecutor.PrioritisedTask queueRunnable(final Runnable task, final PrioritisedExecutor.Priority priority) throws IllegalStateException, IllegalArgumentException {
+        if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+            throw new IllegalArgumentException("Priority " + priority + " is invalid");
+        }
+        if (task == null) {
+            throw new NullPointerException("Task cannot be null");
+        }
+
+        if (this.hasShutdown) {
+            // prevent us from stalling flush() calls by incrementing scheduled tasks when we really didn't schedule something
+            throw new IllegalStateException("Queue has shutdown");
+        }
+
+        final PrioritisedTask ret;
+
+        synchronized (this.queues) {
+            if (this.hasShutdown) {
+                throw new IllegalStateException("Queue has shutdown");
+            }
+            this.getAndAddTotalScheduledTasksVolatile(1L);
+
+            ret = new PrioritisedTask(this.taskIdGenerator++, task, priority, this);
+
+            this.queues[ret.priority.priority].add(ret);
+
+            // call priority change callback (note: only after we successfully queue!)
+            this.priorityChange(ret, null, priority);
+        }
+
+        return ret;
+    }
+
+    @Override
+    public PrioritisedExecutor.PrioritisedTask createTask(final Runnable task, final Priority priority) {
+        if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+            throw new IllegalArgumentException("Priority " + priority + " is invalid");
+        }
+        if (task == null) {
+            throw new NullPointerException("Task cannot be null");
+        }
+
+        return new PrioritisedTask(task, priority, this);
+    }
+
+    @Override
+    public long getTotalTasksScheduled() {
+        return this.totalScheduledTasks.get();
+    }
+
+    @Override
+    public long getTotalTasksExecuted() {
+        return this.totalCompletedTasks.get();
+    }
+
+    // callback method for subclasses to override
+    // from is null when a task is immediately created
+    protected void priorityChange(final PrioritisedTask task, final Priority from, final Priority to) {}
+
+    /**
+     * Polls the highest priority task currently available. {@code null} if none. This will mark the
+     * returned task as completed.
+     */
+    protected PrioritisedTask poll() {
+        return this.poll(Priority.IDLE);
+    }
+
+    protected PrioritisedTask poll(final PrioritisedExecutor.Priority minPriority) {
+        final ArrayDeque<PrioritisedTask>[] queues = this.queues;
+        synchronized (queues) {
+            final int max = minPriority.priority;
+            for (int i = 0; i <= max; ++i) {
+                final ArrayDeque<PrioritisedTask> queue = queues[i];
+                PrioritisedTask task;
+                while ((task = queue.pollFirst()) != null) {
+                    if (task.trySetCompleting(i)) {
+                        return task;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Polls and executes the highest priority task currently available. Exceptions thrown during task execution will
+     * be rethrown.
+     * @return {@code true} if a task was executed, {@code false} otherwise.
+     */
+    @Override
+    public boolean executeTask() {
+        final PrioritisedTask task = this.poll();
+
+        if (task != null) {
+            task.executeInternal();
+            return true;
+        }
+
+        return false;
+    }
+
+    @Override
+    public boolean shutdown() {
+        synchronized (this.queues) {
+            if (this.hasShutdown) {
+                return false;
+            }
+            this.hasShutdown = true;
+        }
+        return true;
+    }
+
+    @Override
+    public boolean isShutdown() {
+        return this.hasShutdown;
+    }
+
+    /* totalScheduledTasks */
+
+    protected final long getTotalScheduledTasksVolatile() {
+        return this.totalScheduledTasks.get();
+    }
+
+    protected final long getAndAddTotalScheduledTasksVolatile(final long value) {
+        return this.totalScheduledTasks.getAndAdd(value);
+    }
+
+    /* totalCompletedTasks */
+
+    protected final long getTotalCompletedTasksVolatile() {
+        return this.totalCompletedTasks.get();
+    }
+
+    protected final long getAndAddTotalCompletedTasksVolatile(final long value) {
+        return this.totalCompletedTasks.getAndAdd(value);
+    }
+
+    protected static final class PrioritisedTask implements PrioritisedExecutor.PrioritisedTask {
+        protected final PrioritisedThreadedTaskQueue queue;
+        protected long id;
+        protected static final long NOT_SCHEDULED_ID = -1L;
+
+        protected Runnable runnable;
+        protected volatile PrioritisedExecutor.Priority priority;
+
+        protected PrioritisedTask(final long id, final Runnable runnable, final PrioritisedExecutor.Priority priority, final PrioritisedThreadedTaskQueue queue) {
+            if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+                throw new IllegalArgumentException("Invalid priority " + priority);
+            }
+
+            this.priority = priority;
+            this.runnable = runnable;
+            this.queue = queue;
+            this.id = id;
+        }
+
+        protected PrioritisedTask(final Runnable runnable, final PrioritisedExecutor.Priority priority, final PrioritisedThreadedTaskQueue queue) {
+            if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+                throw new IllegalArgumentException("Invalid priority " + priority);
+            }
+
+            this.priority = priority;
+            this.runnable = runnable;
+            this.queue = queue;
+            this.id = NOT_SCHEDULED_ID;
+        }
+
+        @Override
+        public boolean queue() {
+            if (this.queue.hasShutdown) {
+                throw new IllegalStateException("Queue has shutdown");
+            }
+
+            synchronized (this.queue.queues) {
+                if (this.queue.hasShutdown) {
+                    throw new IllegalStateException("Queue has shutdown");
+                }
+
+                final PrioritisedExecutor.Priority priority = this.priority;
+                if (priority == PrioritisedExecutor.Priority.COMPLETING) {
+                    return false;
+                }
+
+                if (this.id != NOT_SCHEDULED_ID) {
+                    return false;
+                }
+
+                this.queue.getAndAddTotalScheduledTasksVolatile(1L);
+                this.id = this.queue.taskIdGenerator++;
+                this.queue.queues[priority.priority].add(this);
+
+                this.queue.priorityChange(this, null, priority);
+
+                return true;
+            }
+        }
+
+        protected boolean trySetCompleting(final int minPriority) {
+            final PrioritisedExecutor.Priority oldPriority = this.priority;
+            if (oldPriority != PrioritisedExecutor.Priority.COMPLETING && oldPriority.isHigherOrEqualPriority(minPriority)) {
+                this.priority = PrioritisedExecutor.Priority.COMPLETING;
+                if (this.id != NOT_SCHEDULED_ID) {
+                    this.queue.priorityChange(this, oldPriority, PrioritisedExecutor.Priority.COMPLETING);
+                }
+                return true;
+            }
+
+            return false;
+        }
+
+        @Override
+        public PrioritisedExecutor.Priority getPriority() {
+            return this.priority;
+        }
+
+        @Override
+        public boolean setPriority(final PrioritisedExecutor.Priority priority) {
+            if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+                throw new IllegalArgumentException("Invalid priority " + priority);
+            }
+            synchronized (this.queue.queues) {
+                final PrioritisedExecutor.Priority curr = this.priority;
+
+                if (curr == PrioritisedExecutor.Priority.COMPLETING) {
+                    return false;
+                }
+
+                if (curr == priority) {
+                    return true;
+                }
+
+                this.priority = priority;
+                if (this.id != NOT_SCHEDULED_ID) {
+                    this.queue.queues[priority.priority].add(this);
+
+                    // call priority change callback
+                    this.queue.priorityChange(this, curr, priority);
+                }
+            }
+
+            return true;
+        }
+
+        @Override
+        public boolean raisePriority(final PrioritisedExecutor.Priority priority) {
+            if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+                throw new IllegalArgumentException("Invalid priority " + priority);
+            }
+
+            synchronized (this.queue.queues) {
+                final PrioritisedExecutor.Priority curr = this.priority;
+
+                if (curr == PrioritisedExecutor.Priority.COMPLETING) {
+                    return false;
+                }
+
+                if (curr.isHigherOrEqualPriority(priority)) {
+                    return true;
+                }
+
+                this.priority = priority;
+                if (this.id != NOT_SCHEDULED_ID) {
+                    this.queue.queues[priority.priority].add(this);
+
+                    // call priority change callback
+                    this.queue.priorityChange(this, curr, priority);
+                }
+            }
+
+            return true;
+        }
+
+        @Override
+        public boolean lowerPriority(final PrioritisedExecutor.Priority priority) {
+            if (!PrioritisedExecutor.Priority.isValidPriority(priority)) {
+                throw new IllegalArgumentException("Invalid priority " + priority);
+            }
+
+            synchronized (this.queue.queues) {
+                final PrioritisedExecutor.Priority curr = this.priority;
+
+                if (curr == PrioritisedExecutor.Priority.COMPLETING) {
+                    return false;
+                }
+
+                if (curr.isLowerOrEqualPriority(priority)) {
+                    return true;
+                }
+
+                this.priority = priority;
+                if (this.id != NOT_SCHEDULED_ID) {
+                    this.queue.queues[priority.priority].add(this);
+
+                    // call priority change callback
+                    this.queue.priorityChange(this, curr, priority);
+                }
+            }
+
+            return true;
+        }
+
+        @Override
+        public boolean cancel() {
+            final long id;
+            synchronized (this.queue.queues) {
+                final Priority oldPriority = this.priority;
+                if (oldPriority == PrioritisedExecutor.Priority.COMPLETING) {
+                    return false;
+                }
+
+                this.priority = PrioritisedExecutor.Priority.COMPLETING;
+                // call priority change callback
+                if ((id = this.id) != NOT_SCHEDULED_ID) {
+                    this.queue.priorityChange(this, oldPriority, PrioritisedExecutor.Priority.COMPLETING);
+                }
+            }
+            this.runnable = null;
+            if (id != NOT_SCHEDULED_ID) {
+                this.queue.getAndAddTotalCompletedTasksVolatile(1L);
+            }
+            return true;
+        }
+
+        protected void executeInternal() {
+            try {
+                final Runnable execute = this.runnable;
+                this.runnable = null;
+                execute.run();
+            } finally {
+                if (this.id != NOT_SCHEDULED_ID) {
+                    this.queue.getAndAddTotalCompletedTasksVolatile(1L);
+                }
+            }
+        }
+
+        @Override
+        public boolean execute() {
+            synchronized (this.queue.queues) {
+                final Priority oldPriority = this.priority;
+                if (oldPriority == PrioritisedExecutor.Priority.COMPLETING) {
+                    return false;
+                }
+
+                this.priority = PrioritisedExecutor.Priority.COMPLETING;
+                // call priority change callback
+                if (this.id != NOT_SCHEDULED_ID) {
+                    this.queue.priorityChange(this, oldPriority, PrioritisedExecutor.Priority.COMPLETING);
+                }
+            }
+
+            this.executeInternal();
+            return true;
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/map/SWMRHashTable.java b/src/main/java/ca/spottedleaf/concurrentutil/map/SWMRHashTable.java
new file mode 100644
index 0000000000000000000000000000000000000000..a037bb57bedc0cde6b979f5c1f9669678fa7bd16
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/map/SWMRHashTable.java
@@ -0,0 +1,1673 @@
+package ca.spottedleaf.concurrentutil.map;
+
+import ca.spottedleaf.concurrentutil.util.ArrayUtil;
+import ca.spottedleaf.concurrentutil.util.CollectionUtil;
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import ca.spottedleaf.concurrentutil.util.Validate;
+import io.papermc.paper.util.IntegerUtil;
+import java.lang.invoke.VarHandle;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.IntFunction;
+import java.util.function.Predicate;
+
+/**
+ * <p>
+ * Note: Not really tested, use at your own risk.
+ * </p>
+ * This map is safe for reading from multiple threads, however it is only safe to write from a single thread.
+ * {@code null} keys or values are not permitted. Writes to values in this map are guaranteed to be ordered by release semantics,
+ * however immediate visibility to other threads is not guaranteed. However, writes are guaranteed to be made visible eventually.
+ * Reads are ordered by acquire semantics.
+ * <p>
+ * Iterators cannot be modified concurrently, and its backing map cannot be modified concurrently. There is no
+ * fast-fail attempt made by iterators, thus modifying the iterator's backing map while iterating will have undefined
+ * behaviour.
+ * </p>
+ * <p>
+ * Subclasses should override {@link #clone()} to return correct instances of this class.
+ * </p>
+ * @param <K> {@inheritDoc}
+ * @param <V> {@inheritDoc}
+ */
+public class SWMRHashTable<K, V> implements Map<K, V>, Iterable<Map.Entry<K, V>> {
+
+    protected int size;
+
+    protected TableEntry<K, V>[] table;
+
+    protected final float loadFactor;
+
+    protected static final VarHandle SIZE_HANDLE = ConcurrentUtil.getVarHandle(SWMRHashTable.class, "size", int.class);
+    protected static final VarHandle TABLE_HANDLE = ConcurrentUtil.getVarHandle(SWMRHashTable.class, "table", TableEntry[].class);
+
+    /* size */
+
+    protected final int getSizePlain() {
+        return (int)SIZE_HANDLE.get(this);
+    }
+
+    protected final int getSizeOpaque() {
+        return (int)SIZE_HANDLE.getOpaque(this);
+    }
+
+    protected final int getSizeAcquire() {
+        return (int)SIZE_HANDLE.getAcquire(this);
+    }
+
+    protected final void setSizePlain(final int value) {
+        SIZE_HANDLE.set(this, value);
+    }
+
+    protected final void setSizeOpaque(final int value) {
+        SIZE_HANDLE.setOpaque(this, value);
+    }
+
+    protected final void setSizeRelease(final int value) {
+        SIZE_HANDLE.setRelease(this, value);
+    }
+
+    /* table */
+
+    protected final TableEntry<K, V>[] getTablePlain() {
+        //noinspection unchecked
+        return (TableEntry<K, V>[])TABLE_HANDLE.get(this);
+    }
+
+    protected final TableEntry<K, V>[] getTableAcquire() {
+        //noinspection unchecked
+        return (TableEntry<K, V>[])TABLE_HANDLE.getAcquire(this);
+    }
+
+    protected final void setTablePlain(final TableEntry<K, V>[] table) {
+        TABLE_HANDLE.set(this, table);
+    }
+
+    protected final void setTableRelease(final TableEntry<K, V>[] table) {
+        TABLE_HANDLE.setRelease(this, table);
+    }
+
+    protected static final int DEFAULT_CAPACITY = 16;
+    protected static final float DEFAULT_LOAD_FACTOR = 0.75f;
+    protected static final int MAXIMUM_CAPACITY = Integer.MIN_VALUE >>> 1;
+
+    /**
+     * Constructs this map with a capacity of {@code 16} and load factor of {@code 0.75f}.
+     */
+    public SWMRHashTable() {
+        this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR);
+    }
+
+    /**
+     * Constructs this map with the specified capacity and load factor of {@code 0.75f}.
+     * @param capacity specified initial capacity, > 0
+     */
+    public SWMRHashTable(final int capacity) {
+        this(capacity, DEFAULT_LOAD_FACTOR);
+    }
+
+    /**
+     * Constructs this map with the specified capacity and load factor.
+     * @param capacity specified capacity, > 0
+     * @param loadFactor specified load factor, > 0 && finite
+     */
+    public SWMRHashTable(final int capacity, final float loadFactor) {
+        final int tableSize = getCapacityFor(capacity);
+
+        if (loadFactor <= 0.0 || !Float.isFinite(loadFactor)) {
+            throw new IllegalArgumentException("Invalid load factor: " + loadFactor);
+        }
+
+        //noinspection unchecked
+        final TableEntry<K, V>[] table = new TableEntry[tableSize];
+        this.setTablePlain(table);
+
+        if (tableSize == MAXIMUM_CAPACITY) {
+            this.threshold = -1;
+        } else {
+            this.threshold = getTargetCapacity(tableSize, loadFactor);
+        }
+
+        this.loadFactor = loadFactor;
+    }
+
+    /**
+     * Constructs this map with a capacity of {@code 16} or the specified map's size, whichever is larger, and
+     * with a load factor of {@code 0.75f}.
+     * All of the specified map's entries are copied into this map.
+     * @param other The specified map.
+     */
+    public SWMRHashTable(final Map<K, V> other) {
+        this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, other);
+    }
+
+    /**
+     * Constructs this map with a minimum capacity of the specified capacity or the specified map's size, whichever is larger, and
+     * with a load factor of {@code 0.75f}.
+     * All of the specified map's entries are copied into this map.
+     * @param capacity specified capacity, > 0
+     * @param other The specified map.
+     */
+    public SWMRHashTable(final int capacity, final Map<K, V> other) {
+        this(capacity, DEFAULT_LOAD_FACTOR, other);
+    }
+
+    /**
+     * Constructs this map with a min capacity of the specified capacity or the specified map's size, whichever is larger, and
+     * with the specified load factor.
+     * All of the specified map's entries are copied into this map.
+     * @param capacity specified capacity, > 0
+     * @param loadFactor specified load factor, > 0 && finite
+     * @param other The specified map.
+     */
+    public SWMRHashTable(final int capacity, final float loadFactor, final Map<K, V> other) {
+        this(Math.max(Validate.notNull(other, "Null map").size(), capacity), loadFactor);
+        this.putAll(other);
+    }
+
+    public final float getLoadFactor() {
+        return this.loadFactor;
+    }
+
+    protected static int getCapacityFor(final int capacity) {
+        if (capacity <= 0) {
+            throw new IllegalArgumentException("Invalid capacity: " + capacity);
+        }
+        if (capacity >= MAXIMUM_CAPACITY) {
+            return MAXIMUM_CAPACITY;
+        }
+        return IntegerUtil.roundCeilLog2(capacity);
+    }
+
+    /** Callers must still use acquire when reading the value of the entry. */
+    protected final TableEntry<K, V> getEntryForOpaque(final K key) {
+        final int hash = SWMRHashTable.getHash(key);
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+
+        for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, hash & (table.length - 1)); curr != null; curr = curr.getNextOpaque()) {
+            if (hash == curr.hash && (key == curr.key || curr.key.equals(key))) {
+                return curr;
+            }
+        }
+
+        return null;
+    }
+
+    protected final TableEntry<K, V> getEntryForPlain(final K key) {
+        final int hash = SWMRHashTable.getHash(key);
+        final TableEntry<K, V>[] table = this.getTablePlain();
+
+        for (TableEntry<K, V> curr = table[hash & (table.length - 1)]; curr != null; curr = curr.getNextPlain()) {
+            if (hash == curr.hash && (key == curr.key || curr.key.equals(key))) {
+                return curr;
+            }
+        }
+
+        return null;
+    }
+
+    /* MT-Safe */
+
+    /** must be deterministic given a key */
+    private static int getHash(final Object key) {
+        int hash = key == null ? 0 : key.hashCode();
+        // inlined IntegerUtil#hash0
+        hash *= 0x36935555;
+        hash ^= hash >>> 16;
+        return hash;
+    }
+
+    static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash
+    static final int spread(int h) {
+        return (h ^ (h >>> 16)) & HASH_BITS;
+    }
+
+    // rets -1 if capacity*loadFactor is too large
+    protected static int getTargetCapacity(final int capacity, final float loadFactor) {
+        final double ret = (double)capacity * (double)loadFactor;
+        if (Double.isInfinite(ret) || ret >= ((double)Integer.MAX_VALUE)) {
+            return -1;
+        }
+
+        return (int)ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        /* Make no attempt to deal with concurrent modifications */
+        if (!(obj instanceof Map)) {
+            return false;
+        }
+        final Map<?, ?> other = (Map<?, ?>)obj;
+
+        if (this.size() != other.size()) {
+            return false;
+        }
+
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                final V value = curr.getValueAcquire();
+
+                final Object otherValue = other.get(curr.key);
+                if (otherValue == null || (value != otherValue && value.equals(otherValue))) {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        /* Make no attempt to deal with concurrent modifications */
+        int hash = 0;
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                hash += curr.hashCode();
+            }
+        }
+
+        return hash;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder(64);
+        builder.append("SingleWriterMultiReaderHashMap:{");
+
+        this.forEach((final K key, final V value) -> {
+            builder.append("{key: \"").append(key).append("\", value: \"").append(value).append("\"}");
+        });
+
+        return builder.append('}').toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public SWMRHashTable<K, V> clone() {
+        return new SWMRHashTable<>(this.getTableAcquire().length, this.loadFactor, this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Iterator<Entry<K, V>> iterator() {
+        return new EntryIterator<>(this.getTableAcquire(), this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void forEach(final Consumer<? super Entry<K, V>> action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                action.accept(curr);
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void forEach(final BiConsumer<? super K, ? super V> action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                final V value = curr.getValueAcquire();
+
+                action.accept(curr.key, value);
+            }
+        }
+    }
+
+    /**
+     * Provides the specified consumer with all keys contained within this map.
+     * @param action The specified consumer.
+     */
+    public void forEachKey(final Consumer<? super K> action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                action.accept(curr.key);
+            }
+        }
+    }
+
+    /**
+     * Provides the specified consumer with all values contained within this map. Equivalent to {@code map.values().forEach(Consumer)}.
+     * @param action The specified consumer.
+     */
+    public void forEachValue(final Consumer<? super V> action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                final V value = curr.getValueAcquire();
+
+                action.accept(value);
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V get(final Object key) {
+        Validate.notNull(key, "Null key");
+
+        //noinspection unchecked
+        final TableEntry<K, V> entry = this.getEntryForOpaque((K)key);
+        return entry == null ? null : entry.getValueAcquire();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean containsKey(final Object key) {
+        Validate.notNull(key, "Null key");
+
+        // note: we need to use getValueAcquire, so that the reads from this map are ordered by acquire semantics
+        return this.get(key) != null;
+    }
+
+    /**
+     * Returns {@code true} if this map contains an entry with the specified key and value at some point during this call.
+     * @param key The specified key.
+     * @param value The specified value.
+     * @return {@code true} if this map contains an entry with the specified key and value.
+     */
+    public boolean contains(final Object key, final Object value) {
+        Validate.notNull(key, "Null key");
+
+        //noinspection unchecked
+        final TableEntry<K, V> entry = this.getEntryForOpaque((K)key);
+
+        if (entry == null) {
+            return false;
+        }
+
+        final V entryVal = entry.getValueAcquire();
+        return entryVal == value || entryVal.equals(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean containsValue(final Object value) {
+        Validate.notNull(value, "Null value");
+
+        final TableEntry<K, V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                final V currVal = curr.getValueAcquire();
+                if (currVal == value || currVal.equals(value)) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V getOrDefault(final Object key, final V defaultValue) {
+        Validate.notNull(key, "Null key");
+
+        //noinspection unchecked
+        final TableEntry<K, V> entry = this.getEntryForOpaque((K)key);
+
+        return entry == null ? defaultValue : entry.getValueAcquire();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int size() {
+        return this.getSizeAcquire();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isEmpty() {
+        return this.getSizeAcquire() == 0;
+    }
+
+    protected Set<K> keyset;
+    protected Collection<V> values;
+    protected Set<Map.Entry<K, V>> entrySet;
+
+    @Override
+    public Set<K> keySet() {
+        return this.keyset == null ? this.keyset = new KeySet<>(this) : this.keyset;
+    }
+
+    @Override
+    public Collection<V> values() {
+        return this.values == null ? this.values = new ValueCollection<>(this) : this.values;
+    }
+
+    @Override
+    public Set<Map.Entry<K, V>> entrySet() {
+        return this.entrySet == null ? this.entrySet = new EntrySet<>(this) : this.entrySet;
+    }
+
+    /* Non-MT-Safe */
+
+    protected int threshold;
+
+    protected final void checkResize(final int minCapacity) {
+        if (minCapacity <= this.threshold || this.threshold < 0) {
+            return;
+        }
+
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        int newCapacity = minCapacity >= MAXIMUM_CAPACITY ? MAXIMUM_CAPACITY : IntegerUtil.roundCeilLog2(minCapacity);
+        if (newCapacity < 0) {
+            newCapacity = MAXIMUM_CAPACITY;
+        }
+        if (newCapacity <= table.length) {
+            if (newCapacity == MAXIMUM_CAPACITY) {
+                return;
+            }
+            newCapacity = table.length << 1;
+        }
+
+        //noinspection unchecked
+        final TableEntry<K, V>[] newTable = new TableEntry[newCapacity];
+        final int indexMask = newCapacity - 1;
+
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> entry = table[i]; entry != null; entry = entry.getNextPlain()) {
+                final int hash = entry.hash;
+                final int index = hash & indexMask;
+
+                /* we need to create a new entry since there could be reading threads */
+                final TableEntry<K, V> insert = new TableEntry<>(hash, entry.key, entry.getValuePlain());
+
+                final TableEntry<K, V> prev = newTable[index];
+
+                newTable[index] = insert;
+                insert.setNextPlain(prev);
+            }
+        }
+
+        if (newCapacity == MAXIMUM_CAPACITY) {
+            this.threshold = -1; /* No more resizing */
+        } else {
+            this.threshold = getTargetCapacity(newCapacity, this.loadFactor);
+        }
+        this.setTableRelease(newTable); /* use release to publish entries in table */
+    }
+
+    protected final int addToSize(final int num) {
+        final int newSize = this.getSizePlain() + num;
+
+        this.setSizeOpaque(newSize);
+        this.checkResize(newSize);
+
+        return newSize;
+    }
+
+    protected final int removeFromSize(final int num) {
+        final int newSize = this.getSizePlain() - num;
+
+        this.setSizeOpaque(newSize);
+
+        return newSize;
+    }
+
+    /* Cannot be used to perform downsizing */
+    protected final int removeFromSizePlain(final int num) {
+        final int newSize = this.getSizePlain() - num;
+
+        this.setSizePlain(newSize);
+
+        return newSize;
+    }
+
+    protected final V put(final K key, final V value, final boolean onlyIfAbsent) {
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        final int hash = SWMRHashTable.getHash(key);
+        final int index = hash & (table.length - 1);
+
+        final TableEntry<K, V> head = table[index];
+        if (head == null) {
+            final TableEntry<K, V> insert = new TableEntry<>(hash, key, value);
+            ArrayUtil.setRelease(table, index, insert);
+            this.addToSize(1);
+            return null;
+        }
+
+        for (TableEntry<K, V> curr = head;;) {
+            if (curr.hash == hash && (key == curr.key || curr.key.equals(key))) {
+                if (onlyIfAbsent) {
+                    return curr.getValuePlain();
+                }
+
+                final V currVal = curr.getValuePlain();
+                curr.setValueRelease(value);
+                return currVal;
+            }
+
+            final TableEntry<K, V> next = curr.getNextPlain();
+            if (next != null) {
+                curr = next;
+                continue;
+            }
+
+            final TableEntry<K, V> insert = new TableEntry<>(hash, key, value);
+
+            curr.setNextRelease(insert);
+            this.addToSize(1);
+            return null;
+        }
+    }
+
+    /**
+     * Removes a key-value pair from this map if the specified predicate returns true. The specified predicate is
+     * tested with every entry in this map. Returns the number of key-value pairs removed.
+     * @param predicate The predicate to test key-value pairs against.
+     * @return The total number of key-value pairs removed from this map.
+     */
+    public int removeIf(final BiPredicate<K, V> predicate) {
+        Validate.notNull(predicate, "Null predicate");
+
+        int removed = 0;
+
+        final TableEntry<K, V>[] table = this.getTablePlain();
+
+        bin_iteration_loop:
+        for (int i = 0, len = table.length; i < len; ++i) {
+            TableEntry<K, V> curr = table[i];
+            if (curr == null) {
+                continue;
+            }
+
+            /* Handle bin nodes first */
+            while (predicate.test(curr.key, curr.getValuePlain())) {
+                ++removed;
+                this.removeFromSizePlain(1); /* required in case predicate throws an exception */
+
+                ArrayUtil.setRelease(table, i, curr = curr.getNextPlain());
+
+                if (curr == null) {
+                    continue bin_iteration_loop;
+                }
+            }
+
+            TableEntry<K, V> prev;
+
+            /* curr at this point is the bin node */
+
+            for (prev = curr, curr = curr.getNextPlain(); curr != null;) {
+                /* If we want to remove, then we should hold prev, as it will be a valid entry to link on */
+                if (predicate.test(curr.key, curr.getValuePlain())) {
+                    ++removed;
+                    this.removeFromSizePlain(1); /* required in case predicate throws an exception */
+
+                    prev.setNextRelease(curr = curr.getNextPlain());
+                } else {
+                    prev = curr;
+                    curr = curr.getNextPlain();
+                }
+            }
+        }
+
+        return removed;
+    }
+
+    /**
+     * Removes a key-value pair from this map if the specified predicate returns true. The specified predicate is
+     * tested with every entry in this map. Returns the number of key-value pairs removed.
+     * @param predicate The predicate to test key-value pairs against.
+     * @return The total number of key-value pairs removed from this map.
+     */
+    public int removeEntryIf(final Predicate<? super Entry<K, V>> predicate) {
+        Validate.notNull(predicate, "Null predicate");
+
+        int removed = 0;
+
+        final TableEntry<K, V>[] table = this.getTablePlain();
+
+        bin_iteration_loop:
+        for (int i = 0, len = table.length; i < len; ++i) {
+            TableEntry<K, V> curr = table[i];
+            if (curr == null) {
+                continue;
+            }
+
+            /* Handle bin nodes first */
+            while (predicate.test(curr)) {
+                ++removed;
+                this.removeFromSizePlain(1); /* required in case predicate throws an exception */
+
+                ArrayUtil.setRelease(table, i, curr = curr.getNextPlain());
+
+                if (curr == null) {
+                    continue bin_iteration_loop;
+                }
+            }
+
+            TableEntry<K, V> prev;
+
+            /* curr at this point is the bin node */
+
+            for (prev = curr, curr = curr.getNextPlain(); curr != null;) {
+                /* If we want to remove, then we should hold prev, as it will be a valid entry to link on */
+                if (predicate.test(curr)) {
+                    ++removed;
+                    this.removeFromSizePlain(1); /* required in case predicate throws an exception */
+
+                    prev.setNextRelease(curr = curr.getNextPlain());
+                } else {
+                    prev = curr;
+                    curr = curr.getNextPlain();
+                }
+            }
+        }
+
+        return removed;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V put(final K key, final V value) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(value, "Null value");
+
+        return this.put(key, value, false);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V putIfAbsent(final K key, final V value) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(value, "Null value");
+
+        return this.put(key, value, true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean remove(final Object key, final Object value) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(value, "Null value");
+
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        final int hash = SWMRHashTable.getHash(key);
+        final int index = hash & (table.length - 1);
+
+        final TableEntry<K, V> head = table[index];
+        if (head == null) {
+            return false;
+        }
+
+        if (head.hash == hash && (head.key == key || head.key.equals(key))) {
+            final V currVal = head.getValuePlain();
+
+            if (currVal != value && !currVal.equals(value)) {
+                return false;
+            }
+
+            ArrayUtil.setRelease(table, index, head.getNextPlain());
+            this.removeFromSize(1);
+
+            return true;
+        }
+
+        for (TableEntry<K, V> curr = head.getNextPlain(), prev = head; curr != null; prev = curr, curr = curr.getNextPlain()) {
+            if (curr.hash == hash && (curr.key == key || curr.key.equals(key))) {
+                final V currVal = curr.getValuePlain();
+
+                if (currVal != value && !currVal.equals(value)) {
+                    return false;
+                }
+
+                prev.setNextRelease(curr.getNextPlain());
+                this.removeFromSize(1);
+
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    protected final V remove(final Object key, final int hash) {
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        final int index = (table.length - 1) & hash;
+
+        final TableEntry<K, V> head = table[index];
+        if (head == null) {
+            return null;
+        }
+
+        if (hash == head.hash && (head.key == key || head.key.equals(key))) {
+            ArrayUtil.setRelease(table, index, head.getNextPlain());
+            this.removeFromSize(1);
+
+            return head.getValuePlain();
+        }
+
+        for (TableEntry<K, V> curr = head.getNextPlain(), prev = head; curr != null; prev = curr, curr = curr.getNextPlain()) {
+            if (curr.hash == hash && (key == curr.key || curr.key.equals(key))) {
+                prev.setNextRelease(curr.getNextPlain());
+                this.removeFromSize(1);
+
+                return curr.getValuePlain();
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V remove(final Object key) {
+        Validate.notNull(key, "Null key");
+
+        return this.remove(key, SWMRHashTable.getHash(key));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean replace(final K key, final V oldValue, final V newValue) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(oldValue, "Null oldValue");
+        Validate.notNull(newValue, "Null newValue");
+
+        final TableEntry<K, V> entry = this.getEntryForPlain(key);
+        if (entry == null) {
+            return false;
+        }
+
+        final V currValue = entry.getValuePlain();
+        if (currValue == oldValue || currValue.equals(oldValue)) {
+            entry.setValueRelease(newValue);
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V replace(final K key, final V value) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(value, "Null value");
+
+        final TableEntry<K, V> entry = this.getEntryForPlain(key);
+        if (entry == null) {
+            return null;
+        }
+
+        final V prev = entry.getValuePlain();
+        entry.setValueRelease(value);
+        return prev;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void replaceAll(final BiFunction<? super K, ? super V, ? extends V> function) {
+        Validate.notNull(function, "Null function");
+
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<K, V> curr = table[i]; curr != null; curr = curr.getNextPlain()) {
+                final V value = curr.getValuePlain();
+
+                final V newValue = function.apply(curr.key, value);
+                if (newValue == null) {
+                    throw new NullPointerException();
+                }
+
+                curr.setValueRelease(newValue);
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void putAll(final Map<? extends K, ? extends V> map) {
+        Validate.notNull(map, "Null map");
+
+        final int size = map.size();
+        this.checkResize(Math.max(this.getSizePlain() + size/2, size)); /* preemptively resize */
+        map.forEach(this::put);
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * This call is non-atomic and the order that which entries are removed is undefined. The clear operation itself
+     * is release ordered, that is, after the clear operation is performed a release fence is performed.
+     * </p>
+     */
+    @Override
+    public void clear() {
+        Arrays.fill(this.getTablePlain(), null);
+        this.setSizeRelease(0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V compute(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(remappingFunction, "Null remappingFunction");
+
+        final int hash = SWMRHashTable.getHash(key);
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        final int index = hash & (table.length - 1);
+
+        for (TableEntry<K, V> curr = table[index], prev = null;;prev = curr, curr = curr.getNextPlain()) {
+            if (curr == null) {
+                final V newVal = remappingFunction.apply(key ,null);
+
+                if (newVal == null) {
+                    return null;
+                }
+
+                final TableEntry<K, V> insert = new TableEntry<>(hash, key, newVal);
+                if (prev == null) {
+                    ArrayUtil.setRelease(table, index, insert);
+                } else {
+                    prev.setNextRelease(insert);
+                }
+
+                this.addToSize(1);
+
+                return newVal;
+            }
+
+            if (curr.hash == hash && (curr.key == key || curr.key.equals(key))) {
+                final V newVal = remappingFunction.apply(key, curr.getValuePlain());
+
+                if (newVal != null) {
+                    curr.setValueRelease(newVal);
+                    return newVal;
+                }
+
+                if (prev == null) {
+                    ArrayUtil.setRelease(table, index, curr.getNextPlain());
+                } else {
+                    prev.setNextRelease(curr.getNextPlain());
+                }
+
+                this.removeFromSize(1);
+
+                return null;
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V computeIfPresent(final K key, final BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(remappingFunction, "Null remappingFunction");
+
+        final int hash = SWMRHashTable.getHash(key);
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        final int index = hash & (table.length - 1);
+
+        for (TableEntry<K, V> curr = table[index], prev = null; curr != null; prev = curr, curr = curr.getNextPlain()) {
+            if (curr.hash != hash || (curr.key != key && !curr.key.equals(key))) {
+                continue;
+            }
+
+            final V newVal = remappingFunction.apply(key, curr.getValuePlain());
+            if (newVal != null) {
+                curr.setValueRelease(newVal);
+                return newVal;
+            }
+
+            if (prev == null) {
+                ArrayUtil.setRelease(table, index, curr.getNextPlain());
+            } else {
+                prev.setNextRelease(curr.getNextPlain());
+            }
+
+            this.removeFromSize(1);
+
+            return null;
+        }
+
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V computeIfAbsent(final K key, final Function<? super K, ? extends V> mappingFunction) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(mappingFunction, "Null mappingFunction");
+
+        final int hash = SWMRHashTable.getHash(key);
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        final int index = hash & (table.length - 1);
+
+        for (TableEntry<K, V> curr = table[index], prev = null;;prev = curr, curr = curr.getNextPlain()) {
+            if (curr != null) {
+                if (curr.hash == hash && (curr.key == key || curr.key.equals(key))) {
+                    return curr.getValuePlain();
+                }
+                continue;
+            }
+
+            final V newVal = mappingFunction.apply(key);
+
+            if (newVal == null) {
+                return null;
+            }
+
+            final TableEntry<K, V> insert = new TableEntry<>(hash, key, newVal);
+            if (prev == null) {
+                ArrayUtil.setRelease(table, index, insert);
+            } else {
+                prev.setNextRelease(insert);
+            }
+
+            this.addToSize(1);
+
+            return newVal;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public V merge(final K key, final V value, final BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
+        Validate.notNull(key, "Null key");
+        Validate.notNull(value, "Null value");
+        Validate.notNull(remappingFunction, "Null remappingFunction");
+
+        final int hash = SWMRHashTable.getHash(key);
+        final TableEntry<K, V>[] table = this.getTablePlain();
+        final int index = hash & (table.length - 1);
+
+        for (TableEntry<K, V> curr = table[index], prev = null;;prev = curr, curr = curr.getNextPlain()) {
+            if (curr == null) {
+                final TableEntry<K, V> insert = new TableEntry<>(hash, key, value);
+                if (prev == null) {
+                    ArrayUtil.setRelease(table, index, insert);
+                } else {
+                    prev.setNextRelease(insert);
+                }
+
+                this.addToSize(1);
+
+                return value;
+            }
+
+            if (curr.hash == hash && (curr.key == key || curr.key.equals(key))) {
+                final V newVal = remappingFunction.apply(curr.getValuePlain(), value);
+
+                if (newVal != null) {
+                    curr.setValueRelease(newVal);
+                    return newVal;
+                }
+
+                if (prev == null) {
+                    ArrayUtil.setRelease(table, index, curr.getNextPlain());
+                } else {
+                    prev.setNextRelease(curr.getNextPlain());
+                }
+
+                this.removeFromSize(1);
+
+                return null;
+            }
+        }
+    }
+
+    protected static final class TableEntry<K, V> implements Map.Entry<K, V> {
+
+        protected final int hash;
+        protected final K key;
+        protected V value;
+
+        protected TableEntry<K, V> next;
+
+        protected static final VarHandle VALUE_HANDLE = ConcurrentUtil.getVarHandle(TableEntry.class, "value", Object.class);
+        protected static final VarHandle NEXT_HANDLE = ConcurrentUtil.getVarHandle(TableEntry.class, "next", TableEntry.class);
+
+        /* value */
+
+        protected final V getValuePlain() {
+            //noinspection unchecked
+            return (V)VALUE_HANDLE.get(this);
+        }
+
+        protected final V getValueAcquire() {
+            //noinspection unchecked
+            return (V)VALUE_HANDLE.getAcquire(this);
+        }
+
+        protected final void setValueRelease(final V to) {
+            VALUE_HANDLE.setRelease(this, to);
+        }
+
+        /* next */
+
+        protected final TableEntry<K, V> getNextPlain() {
+            //noinspection unchecked
+            return (TableEntry<K, V>)NEXT_HANDLE.get(this);
+        }
+
+        protected final TableEntry<K, V> getNextOpaque() {
+            //noinspection unchecked
+            return (TableEntry<K, V>)NEXT_HANDLE.getOpaque(this);
+        }
+
+        protected final void setNextPlain(final TableEntry<K, V> next) {
+            NEXT_HANDLE.set(this, next);
+        }
+
+        protected final void setNextRelease(final TableEntry<K, V> next) {
+            NEXT_HANDLE.setRelease(this, next);
+        }
+
+        protected TableEntry(final int hash, final K key, final V value) {
+            this.hash = hash;
+            this.key = key;
+            this.value = value;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public K getKey() {
+            return this.key;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public V getValue() {
+            return this.getValueAcquire();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public V setValue(final V value) {
+            if (value == null) {
+                throw new NullPointerException();
+            }
+
+            final V curr = this.getValuePlain();
+
+            this.setValueRelease(value);
+            return curr;
+        }
+
+        protected static int hash(final Object key, final Object value) {
+            return key.hashCode() ^ (value == null ? 0 : value.hashCode());
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public int hashCode() {
+            return hash(this.key, this.getValueAcquire());
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public boolean equals(final Object obj) {
+            if (this == obj) {
+                return true;
+            }
+
+            if (!(obj instanceof Map.Entry)) {
+                return false;
+            }
+            final Map.Entry<?, ?> other = (Map.Entry<?, ?>)obj;
+            final Object otherKey = other.getKey();
+            final Object otherValue = other.getValue();
+
+            final K thisKey = this.getKey();
+            final V thisVal = this.getValueAcquire();
+            return (thisKey == otherKey || thisKey.equals(otherKey)) &&
+                (thisVal == otherValue || thisVal.equals(otherValue));
+        }
+    }
+
+
+    protected static abstract class TableEntryIterator<K, V, T> implements Iterator<T> {
+
+        protected final TableEntry<K, V>[] table;
+        protected final SWMRHashTable<K, V> map;
+
+        /* bin which our current element resides on */
+        protected int tableIndex;
+
+        protected TableEntry<K, V> currEntry; /* curr entry, null if no more to iterate or if curr was removed or if we've just init'd */
+        protected TableEntry<K, V> nextEntry; /* may not be on the same bin as currEntry */
+
+        protected TableEntryIterator(final TableEntry<K, V>[] table, final SWMRHashTable<K, V> map) {
+            this.table = table;
+            this.map = map;
+            int tableIndex = 0;
+            for (int len = table.length; tableIndex < len; ++tableIndex) {
+                final TableEntry<K, V> entry = ArrayUtil.getOpaque(table, tableIndex);
+                if (entry != null) {
+                    this.nextEntry = entry;
+                    this.tableIndex = tableIndex + 1;
+                    return;
+                }
+            }
+            this.tableIndex = tableIndex;
+        }
+
+        @Override
+        public boolean hasNext() {
+            return this.nextEntry != null;
+        }
+
+        protected final TableEntry<K, V> advanceEntry() {
+            final TableEntry<K, V>[] table = this.table;
+            final int tableLength = table.length;
+            int tableIndex = this.tableIndex;
+            final TableEntry<K, V> curr = this.nextEntry;
+            if (curr == null) {
+                return null;
+            }
+
+            this.currEntry = curr;
+
+            // set up nextEntry
+
+            // find next in chain
+            TableEntry<K, V> next = curr.getNextOpaque();
+
+            if (next != null) {
+                this.nextEntry = next;
+                return curr;
+            }
+
+            // nothing in chain, so find next available bin
+            for (;tableIndex < tableLength; ++tableIndex) {
+                next = ArrayUtil.getOpaque(table, tableIndex);
+                if (next != null) {
+                    this.nextEntry = next;
+                    this.tableIndex = tableIndex + 1;
+                    return curr;
+                }
+            }
+
+            this.nextEntry = null;
+            this.tableIndex = tableIndex;
+            return curr;
+        }
+
+        @Override
+        public void remove() {
+            final TableEntry<K, V> curr = this.currEntry;
+            if (curr == null) {
+                throw new IllegalStateException();
+            }
+
+            this.map.remove(curr.key, curr.hash);
+
+            this.currEntry = null;
+        }
+    }
+
+    protected static final class ValueIterator<K, V> extends TableEntryIterator<K, V, V> {
+
+        protected ValueIterator(final TableEntry<K, V>[] table, final SWMRHashTable<K, V> map) {
+            super(table, map);
+        }
+
+        @Override
+        public V next() {
+            final TableEntry<K, V> entry = this.advanceEntry();
+
+            if (entry == null) {
+                throw new NoSuchElementException();
+            }
+
+            return entry.getValueAcquire();
+        }
+    }
+
+    protected static final class KeyIterator<K, V> extends TableEntryIterator<K, V, K> {
+
+        protected KeyIterator(final TableEntry<K, V>[] table, final SWMRHashTable<K, V> map) {
+            super(table, map);
+        }
+
+        @Override
+        public K next() {
+            final TableEntry<K, V> curr = this.advanceEntry();
+
+            if (curr == null) {
+                throw new NoSuchElementException();
+            }
+
+            return curr.key;
+        }
+    }
+
+    protected static final class EntryIterator<K, V> extends TableEntryIterator<K, V, Map.Entry<K, V>> {
+
+        protected EntryIterator(final TableEntry<K, V>[] table, final SWMRHashTable<K, V> map) {
+            super(table, map);
+        }
+
+        @Override
+        public Map.Entry<K, V> next() {
+            final TableEntry<K, V> curr = this.advanceEntry();
+
+            if (curr == null) {
+                throw new NoSuchElementException();
+            }
+
+            return curr;
+        }
+    }
+
+    protected static abstract class ViewCollection<K, V, T> implements Collection<T> {
+
+        protected final SWMRHashTable<K, V> map;
+
+        protected ViewCollection(final SWMRHashTable<K, V> map) {
+            this.map = map;
+        }
+
+        @Override
+        public boolean add(final T element) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public boolean addAll(final Collection<? extends T> collections) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public boolean removeAll(final Collection<?> collection) {
+            Validate.notNull(collection, "Null collection");
+
+            boolean modified = false;
+            for (final Object element : collection) {
+                modified |= this.remove(element);
+            }
+            return modified;
+        }
+
+        @Override
+        public int size() {
+            return this.map.size();
+        }
+
+        @Override
+        public boolean isEmpty() {
+            return this.size() == 0;
+        }
+
+        @Override
+        public void clear() {
+            this.map.clear();
+        }
+
+        @Override
+        public boolean containsAll(final Collection<?> collection) {
+            Validate.notNull(collection, "Null collection");
+
+            for (final Object element : collection) {
+                if (!this.contains(element)) {
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
+        @Override
+        public Object[] toArray() {
+            final List<T> list = new ArrayList<>(this.size());
+
+            this.forEach(list::add);
+
+            return list.toArray();
+        }
+
+        @Override
+        public <E> E[] toArray(final E[] array) {
+            final List<T> list = new ArrayList<>(this.size());
+
+            this.forEach(list::add);
+
+            return list.toArray(array);
+        }
+
+        @Override
+        public <E> E[] toArray(final IntFunction<E[]> generator) {
+            final List<T> list = new ArrayList<>(this.size());
+
+            this.forEach(list::add);
+
+            return list.toArray(generator);
+        }
+
+        @Override
+        public int hashCode() {
+            int hash = 0;
+            for (final T element : this) {
+                hash += element == null ? 0 : element.hashCode();
+            }
+            return hash;
+        }
+
+        @Override
+        public Spliterator<T> spliterator() { // TODO implement
+            return Spliterators.spliterator(this, Spliterator.NONNULL);
+        }
+    }
+
+    protected static abstract class ViewSet<K, V, T> extends ViewCollection<K, V, T> implements Set<T> {
+
+        protected ViewSet(final SWMRHashTable<K, V> map) {
+            super(map);
+        }
+
+        @Override
+        public boolean equals(final Object obj) {
+            if (this == obj) {
+                return true;
+            }
+
+            if (!(obj instanceof Set)) {
+                return false;
+            }
+
+            final Set<?> other = (Set<?>)obj;
+            if (other.size() != this.size()) {
+                return false;
+            }
+
+            return this.containsAll(other);
+        }
+    }
+
+    protected static final class EntrySet<K, V> extends ViewSet<K, V, Map.Entry<K, V>> implements Set<Map.Entry<K, V>> {
+
+        protected EntrySet(final SWMRHashTable<K, V> map) {
+            super(map);
+        }
+
+        @Override
+        public boolean remove(final Object object) {
+            if (!(object instanceof Map.Entry<?, ?>)) {
+                return false;
+            }
+            final Map.Entry<?, ?> entry = (Map.Entry<?, ?>)object;
+
+            final Object key;
+            final Object value;
+
+            try {
+                key = entry.getKey();
+                value = entry.getValue();
+            } catch (final IllegalStateException ex) {
+                return false;
+            }
+
+            return this.map.remove(key, value);
+        }
+
+        @Override
+        public boolean removeIf(final Predicate<? super Map.Entry<K, V>> filter) {
+            Validate.notNull(filter, "Null filter");
+
+            return this.map.removeEntryIf(filter) != 0;
+        }
+
+        @Override
+        public boolean retainAll(final Collection<?> collection) {
+            Validate.notNull(collection, "Null collection");
+
+            return this.map.removeEntryIf((final Map.Entry<K, V> entry) -> {
+                return !collection.contains(entry);
+            }) != 0;
+        }
+
+        @Override
+        public Iterator<Entry<K, V>> iterator() {
+            return new EntryIterator<>(this.map.getTableAcquire(), this.map);
+        }
+
+        @Override
+        public void forEach(final Consumer<? super Entry<K, V>> action) {
+            this.map.forEach(action);
+        }
+
+        @Override
+        public boolean contains(final Object object) {
+            if (!(object instanceof Map.Entry)) {
+                return false;
+            }
+            final Map.Entry<?, ?> entry = (Map.Entry<?, ?>)object;
+
+            final Object key;
+            final Object value;
+
+            try {
+                key = entry.getKey();
+                value = entry.getValue();
+            } catch (final IllegalStateException ex) {
+                return false;
+            }
+
+            return this.map.contains(key, value);
+        }
+
+        @Override
+        public String toString() {
+            return CollectionUtil.toString(this, "SWMRHashTableEntrySet");
+        }
+    }
+
+    protected static final class KeySet<K, V> extends ViewSet<K, V, K> {
+
+        protected KeySet(final SWMRHashTable<K, V> map) {
+            super(map);
+        }
+
+        @Override
+        public Iterator<K> iterator() {
+            return new KeyIterator<>(this.map.getTableAcquire(), this.map);
+        }
+
+        @Override
+        public void forEach(final Consumer<? super K> action) {
+            Validate.notNull(action, "Null action");
+
+            this.map.forEachKey(action);
+        }
+
+        @Override
+        public boolean contains(final Object key) {
+            Validate.notNull(key, "Null key");
+
+            return this.map.containsKey(key);
+        }
+
+        @Override
+        public boolean remove(final Object key) {
+            Validate.notNull(key, "Null key");
+
+            return this.map.remove(key) != null;
+        }
+
+        @Override
+        public boolean retainAll(final Collection<?> collection) {
+            Validate.notNull(collection, "Null collection");
+
+            return this.map.removeIf((final K key, final V value) -> {
+                return !collection.contains(key);
+            }) != 0;
+        }
+
+        @Override
+        public boolean removeIf(final Predicate<? super K> filter) {
+            Validate.notNull(filter, "Null filter");
+
+            return this.map.removeIf((final K key, final V value) -> {
+                return filter.test(key);
+            }) != 0;
+        }
+
+        @Override
+        public String toString() {
+            return CollectionUtil.toString(this, "SWMRHashTableKeySet");
+        }
+    }
+
+    protected static final class ValueCollection<K, V> extends ViewSet<K, V, V> implements Collection<V> {
+
+        protected ValueCollection(final SWMRHashTable<K, V> map) {
+            super(map);
+        }
+
+        @Override
+        public Iterator<V> iterator() {
+            return new ValueIterator<>(this.map.getTableAcquire(), this.map);
+        }
+
+        @Override
+        public void forEach(final Consumer<? super V> action) {
+            Validate.notNull(action, "Null action");
+
+            this.map.forEachValue(action);
+        }
+
+        @Override
+        public boolean contains(final Object object) {
+            Validate.notNull(object, "Null object");
+
+            return this.map.containsValue(object);
+        }
+
+        @Override
+        public boolean remove(final Object object) {
+            Validate.notNull(object, "Null object");
+
+            final Iterator<V> itr = this.iterator();
+            while (itr.hasNext()) {
+                final V val = itr.next();
+                if (val == object || val.equals(object)) {
+                    itr.remove();
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        @Override
+        public boolean removeIf(final Predicate<? super V> filter) {
+            Validate.notNull(filter, "Null filter");
+
+            return this.map.removeIf((final K key, final V value) -> {
+                return filter.test(value);
+            }) != 0;
+        }
+
+        @Override
+        public boolean retainAll(final Collection<?> collection) {
+            Validate.notNull(collection, "Null collection");
+
+            return this.map.removeIf((final K key, final V value) -> {
+                return !collection.contains(value);
+            }) != 0;
+        }
+
+        @Override
+        public String toString() {
+            return CollectionUtil.toString(this, "SWMRHashTableValues");
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/map/SWMRLong2ObjectHashTable.java b/src/main/java/ca/spottedleaf/concurrentutil/map/SWMRLong2ObjectHashTable.java
new file mode 100644
index 0000000000000000000000000000000000000000..1e98f778ffa0a7bb00ebccaaa8bde075183e41f0
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/map/SWMRLong2ObjectHashTable.java
@@ -0,0 +1,672 @@
+package ca.spottedleaf.concurrentutil.map;
+
+import ca.spottedleaf.concurrentutil.util.ArrayUtil;
+import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
+import ca.spottedleaf.concurrentutil.util.Validate;
+import io.papermc.paper.util.IntegerUtil;
+import java.lang.invoke.VarHandle;
+import java.util.Arrays;
+import java.util.function.Consumer;
+import java.util.function.LongConsumer;
+
+// trimmed down version of SWMRHashTable
+public class SWMRLong2ObjectHashTable<V> {
+
+    protected int size;
+
+    protected TableEntry<V>[] table;
+
+    protected final float loadFactor;
+
+    protected static final VarHandle SIZE_HANDLE = ConcurrentUtil.getVarHandle(SWMRLong2ObjectHashTable.class, "size", int.class);
+    protected static final VarHandle TABLE_HANDLE = ConcurrentUtil.getVarHandle(SWMRLong2ObjectHashTable.class, "table", TableEntry[].class);
+
+    /* size */
+
+    protected final int getSizePlain() {
+        return (int)SIZE_HANDLE.get(this);
+    }
+
+    protected final int getSizeOpaque() {
+        return (int)SIZE_HANDLE.getOpaque(this);
+    }
+
+    protected final int getSizeAcquire() {
+        return (int)SIZE_HANDLE.getAcquire(this);
+    }
+
+    protected final void setSizePlain(final int value) {
+        SIZE_HANDLE.set(this, value);
+    }
+
+    protected final void setSizeOpaque(final int value) {
+        SIZE_HANDLE.setOpaque(this, value);
+    }
+
+    protected final void setSizeRelease(final int value) {
+        SIZE_HANDLE.setRelease(this, value);
+    }
+
+    /* table */
+
+    protected final TableEntry<V>[] getTablePlain() {
+        //noinspection unchecked
+        return (TableEntry<V>[])TABLE_HANDLE.get(this);
+    }
+
+    protected final TableEntry<V>[] getTableAcquire() {
+        //noinspection unchecked
+        return (TableEntry<V>[])TABLE_HANDLE.getAcquire(this);
+    }
+
+    protected final void setTablePlain(final TableEntry<V>[] table) {
+        TABLE_HANDLE.set(this, table);
+    }
+
+    protected final void setTableRelease(final TableEntry<V>[] table) {
+        TABLE_HANDLE.setRelease(this, table);
+    }
+
+    protected static final int DEFAULT_CAPACITY = 16;
+    protected static final float DEFAULT_LOAD_FACTOR = 0.75f;
+    protected static final int MAXIMUM_CAPACITY = Integer.MIN_VALUE >>> 1;
+
+    /**
+     * Constructs this map with a capacity of {@code 16} and load factor of {@code 0.75f}.
+     */
+    public SWMRLong2ObjectHashTable() {
+        this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR);
+    }
+
+    /**
+     * Constructs this map with the specified capacity and load factor of {@code 0.75f}.
+     * @param capacity specified initial capacity, > 0
+     */
+    public SWMRLong2ObjectHashTable(final int capacity) {
+        this(capacity, DEFAULT_LOAD_FACTOR);
+    }
+
+    /**
+     * Constructs this map with the specified capacity and load factor.
+     * @param capacity specified capacity, > 0
+     * @param loadFactor specified load factor, > 0 && finite
+     */
+    public SWMRLong2ObjectHashTable(final int capacity, final float loadFactor) {
+        final int tableSize = getCapacityFor(capacity);
+
+        if (loadFactor <= 0.0 || !Float.isFinite(loadFactor)) {
+            throw new IllegalArgumentException("Invalid load factor: " + loadFactor);
+        }
+
+        //noinspection unchecked
+        final TableEntry<V>[] table = new TableEntry[tableSize];
+        this.setTablePlain(table);
+
+        if (tableSize == MAXIMUM_CAPACITY) {
+            this.threshold = -1;
+        } else {
+            this.threshold = getTargetCapacity(tableSize, loadFactor);
+        }
+
+        this.loadFactor = loadFactor;
+    }
+
+    /**
+     * Constructs this map with a capacity of {@code 16} or the specified map's size, whichever is larger, and
+     * with a load factor of {@code 0.75f}.
+     * All of the specified map's entries are copied into this map.
+     * @param other The specified map.
+     */
+    public SWMRLong2ObjectHashTable(final SWMRLong2ObjectHashTable<V> other) {
+        this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, other);
+    }
+
+    /**
+     * Constructs this map with a minimum capacity of the specified capacity or the specified map's size, whichever is larger, and
+     * with a load factor of {@code 0.75f}.
+     * All of the specified map's entries are copied into this map.
+     * @param capacity specified capacity, > 0
+     * @param other The specified map.
+     */
+    public SWMRLong2ObjectHashTable(final int capacity, final SWMRLong2ObjectHashTable<V> other) {
+        this(capacity, DEFAULT_LOAD_FACTOR, other);
+    }
+
+    /**
+     * Constructs this map with a min capacity of the specified capacity or the specified map's size, whichever is larger, and
+     * with the specified load factor.
+     * All of the specified map's entries are copied into this map.
+     * @param capacity specified capacity, > 0
+     * @param loadFactor specified load factor, > 0 && finite
+     * @param other The specified map.
+     */
+    public SWMRLong2ObjectHashTable(final int capacity, final float loadFactor, final SWMRLong2ObjectHashTable<V> other) {
+        this(Math.max(Validate.notNull(other, "Null map").size(), capacity), loadFactor);
+        this.putAll(other);
+    }
+
+    public final float getLoadFactor() {
+        return this.loadFactor;
+    }
+
+    protected static int getCapacityFor(final int capacity) {
+        if (capacity <= 0) {
+            throw new IllegalArgumentException("Invalid capacity: " + capacity);
+        }
+        if (capacity >= MAXIMUM_CAPACITY) {
+            return MAXIMUM_CAPACITY;
+        }
+        return IntegerUtil.roundCeilLog2(capacity);
+    }
+
+    /** Callers must still use acquire when reading the value of the entry. */
+    protected final TableEntry<V> getEntryForOpaque(final long key) {
+        final int hash = SWMRLong2ObjectHashTable.getHash(key);
+        final TableEntry<V>[] table = this.getTableAcquire();
+
+        for (TableEntry<V> curr = ArrayUtil.getOpaque(table, hash & (table.length - 1)); curr != null; curr = curr.getNextOpaque()) {
+            if (key == curr.key) {
+                return curr;
+            }
+        }
+
+        return null;
+    }
+
+    protected final TableEntry<V> getEntryForPlain(final long key) {
+        final int hash = SWMRLong2ObjectHashTable.getHash(key);
+        final TableEntry<V>[] table = this.getTablePlain();
+
+        for (TableEntry<V> curr = table[hash & (table.length - 1)]; curr != null; curr = curr.getNextPlain()) {
+            if (key == curr.key) {
+                return curr;
+            }
+        }
+
+        return null;
+    }
+
+    /* MT-Safe */
+
+    /** must be deterministic given a key */
+    protected static int getHash(final long key) {
+        return (int)it.unimi.dsi.fastutil.HashCommon.mix(key);
+    }
+
+    // rets -1 if capacity*loadFactor is too large
+    protected static int getTargetCapacity(final int capacity, final float loadFactor) {
+        final double ret = (double)capacity * (double)loadFactor;
+        if (Double.isInfinite(ret) || ret >= ((double)Integer.MAX_VALUE)) {
+            return -1;
+        }
+
+        return (int)ret;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        /* Make no attempt to deal with concurrent modifications */
+        if (!(obj instanceof SWMRLong2ObjectHashTable)) {
+            return false;
+        }
+        final SWMRLong2ObjectHashTable<?> other = (SWMRLong2ObjectHashTable<?>)obj;
+
+        if (this.size() != other.size()) {
+            return false;
+        }
+
+        final TableEntry<V>[] table = this.getTableAcquire();
+
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                final V value = curr.getValueAcquire();
+
+                final Object otherValue = other.get(curr.key);
+                if (otherValue == null || (value != otherValue && value.equals(otherValue))) {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        /* Make no attempt to deal with concurrent modifications */
+        int hash = 0;
+        final TableEntry<V>[] table = this.getTableAcquire();
+
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                hash += curr.hashCode();
+            }
+        }
+
+        return hash;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder(64);
+        builder.append("SingleWriterMultiReaderHashMap:{");
+
+        this.forEach((final long key, final V value) -> {
+            builder.append("{key: \"").append(key).append("\", value: \"").append(value).append("\"}");
+        });
+
+        return builder.append('}').toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public SWMRLong2ObjectHashTable<V> clone() {
+        return new SWMRLong2ObjectHashTable<>(this.getTableAcquire().length, this.loadFactor, this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void forEach(final Consumer<? super SWMRLong2ObjectHashTable.TableEntry<V>> action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                action.accept(curr);
+            }
+        }
+    }
+
+    @FunctionalInterface
+    public static interface BiLongObjectConsumer<V> {
+        public void accept(final long key, final V value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void forEach(final BiLongObjectConsumer<? super V> action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                final V value = curr.getValueAcquire();
+
+                action.accept(curr.key, value);
+            }
+        }
+    }
+
+    /**
+     * Provides the specified consumer with all keys contained within this map.
+     * @param action The specified consumer.
+     */
+    public void forEachKey(final LongConsumer action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                action.accept(curr.key);
+            }
+        }
+    }
+
+    /**
+     * Provides the specified consumer with all values contained within this map. Equivalent to {@code map.values().forEach(Consumer)}.
+     * @param action The specified consumer.
+     */
+    public void forEachValue(final Consumer<? super V> action) {
+        Validate.notNull(action, "Null action");
+
+        final TableEntry<V>[] table = this.getTableAcquire();
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<V> curr = ArrayUtil.getOpaque(table, i); curr != null; curr = curr.getNextOpaque()) {
+                final V value = curr.getValueAcquire();
+
+                action.accept(value);
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public V get(final long key) {
+        final TableEntry<V> entry = this.getEntryForOpaque(key);
+        return entry == null ? null : entry.getValueAcquire();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean containsKey(final long key) {
+        // note: we need to use getValueAcquire, so that the reads from this map are ordered by acquire semantics
+        return this.get(key) != null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public V getOrDefault(final long key, final V defaultValue) {
+        final TableEntry<V> entry = this.getEntryForOpaque(key);
+
+        return entry == null ? defaultValue : entry.getValueAcquire();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int size() {
+        return this.getSizeAcquire();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEmpty() {
+        return this.getSizeAcquire() == 0;
+    }
+
+    /* Non-MT-Safe */
+
+    protected int threshold;
+
+    protected final void checkResize(final int minCapacity) {
+        if (minCapacity <= this.threshold || this.threshold < 0) {
+            return;
+        }
+
+        final TableEntry<V>[] table = this.getTablePlain();
+        int newCapacity = minCapacity >= MAXIMUM_CAPACITY ? MAXIMUM_CAPACITY : IntegerUtil.roundCeilLog2(minCapacity);
+        if (newCapacity < 0) {
+            newCapacity = MAXIMUM_CAPACITY;
+        }
+        if (newCapacity <= table.length) {
+            if (newCapacity == MAXIMUM_CAPACITY) {
+                return;
+            }
+            newCapacity = table.length << 1;
+        }
+
+        //noinspection unchecked
+        final TableEntry<V>[] newTable = new TableEntry[newCapacity];
+        final int indexMask = newCapacity - 1;
+
+        for (int i = 0, len = table.length; i < len; ++i) {
+            for (TableEntry<V> entry = table[i]; entry != null; entry = entry.getNextPlain()) {
+                final long key = entry.key;
+                final int hash = SWMRLong2ObjectHashTable.getHash(key);
+                final int index = hash & indexMask;
+
+                /* we need to create a new entry since there could be reading threads */
+                final TableEntry<V> insert = new TableEntry<>(key, entry.getValuePlain());
+
+                final TableEntry<V> prev = newTable[index];
+
+                newTable[index] = insert;
+                insert.setNextPlain(prev);
+            }
+        }
+
+        if (newCapacity == MAXIMUM_CAPACITY) {
+            this.threshold = -1; /* No more resizing */
+        } else {
+            this.threshold = getTargetCapacity(newCapacity, this.loadFactor);
+        }
+        this.setTableRelease(newTable); /* use release to publish entries in table */
+    }
+
+    protected final int addToSize(final int num) {
+        final int newSize = this.getSizePlain() + num;
+
+        this.setSizeOpaque(newSize);
+        this.checkResize(newSize);
+
+        return newSize;
+    }
+
+    protected final int removeFromSize(final int num) {
+        final int newSize = this.getSizePlain() - num;
+
+        this.setSizeOpaque(newSize);
+
+        return newSize;
+    }
+
+    protected final V put(final long key, final V value, final boolean onlyIfAbsent) {
+        final TableEntry<V>[] table = this.getTablePlain();
+        final int hash = SWMRLong2ObjectHashTable.getHash(key);
+        final int index = hash & (table.length - 1);
+
+        final TableEntry<V> head = table[index];
+        if (head == null) {
+            final TableEntry<V> insert = new TableEntry<>(key, value);
+            ArrayUtil.setRelease(table, index, insert);
+            this.addToSize(1);
+            return null;
+        }
+
+        for (TableEntry<V> curr = head;;) {
+            if (key == curr.key) {
+                if (onlyIfAbsent) {
+                    return curr.getValuePlain();
+                }
+
+                final V currVal = curr.getValuePlain();
+                curr.setValueRelease(value);
+                return currVal;
+            }
+
+            final TableEntry<V> next = curr.getNextPlain();
+            if (next != null) {
+                curr = next;
+                continue;
+            }
+
+            final TableEntry<V> insert = new TableEntry<>(key, value);
+
+            curr.setNextRelease(insert);
+            this.addToSize(1);
+            return null;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public V put(final long key, final V value) {
+        Validate.notNull(value, "Null value");
+
+        return this.put(key, value, false);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public V putIfAbsent(final long key, final V value) {
+        Validate.notNull(value, "Null value");
+
+        return this.put(key, value, true);
+    }
+
+    protected final V remove(final long key, final int hash) {
+        final TableEntry<V>[] table = this.getTablePlain();
+        final int index = (table.length - 1) & hash;
+
+        final TableEntry<V> head = table[index];
+        if (head == null) {
+            return null;
+        }
+
+        if (head.key == key) {
+            ArrayUtil.setRelease(table, index, head.getNextPlain());
+            this.removeFromSize(1);
+
+            return head.getValuePlain();
+        }
+
+        for (TableEntry<V> curr = head.getNextPlain(), prev = head; curr != null; prev = curr, curr = curr.getNextPlain()) {
+            if (key == curr.key) {
+                prev.setNextRelease(curr.getNextPlain());
+                this.removeFromSize(1);
+
+                return curr.getValuePlain();
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public V remove(final long key) {
+        return this.remove(key, SWMRLong2ObjectHashTable.getHash(key));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void putAll(final SWMRLong2ObjectHashTable<? extends V> map) {
+        Validate.notNull(map, "Null map");
+
+        final int size = map.size();
+        this.checkResize(Math.max(this.getSizePlain() + size/2, size)); /* preemptively resize */
+        map.forEach(this::put);
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p>
+     * This call is non-atomic and the order that which entries are removed is undefined. The clear operation itself
+     * is release ordered, that is, after the clear operation is performed a release fence is performed.
+     * </p>
+     */
+    public void clear() {
+        Arrays.fill(this.getTablePlain(), null);
+        this.setSizeRelease(0);
+    }
+
+    public static final class TableEntry<V> {
+
+        protected final long key;
+        protected V value;
+
+        protected TableEntry<V> next;
+
+        protected static final VarHandle VALUE_HANDLE = ConcurrentUtil.getVarHandle(TableEntry.class, "value", Object.class);
+        protected static final VarHandle NEXT_HANDLE = ConcurrentUtil.getVarHandle(TableEntry.class, "next", TableEntry.class);
+
+        /* value */
+
+        protected final V getValuePlain() {
+            //noinspection unchecked
+            return (V)VALUE_HANDLE.get(this);
+        }
+
+        protected final V getValueAcquire() {
+            //noinspection unchecked
+            return (V)VALUE_HANDLE.getAcquire(this);
+        }
+
+        protected final void setValueRelease(final V to) {
+            VALUE_HANDLE.setRelease(this, to);
+        }
+
+        /* next */
+
+        protected final TableEntry<V> getNextPlain() {
+            //noinspection unchecked
+            return (TableEntry<V>)NEXT_HANDLE.get(this);
+        }
+
+        protected final TableEntry<V> getNextOpaque() {
+            //noinspection unchecked
+            return (TableEntry<V>)NEXT_HANDLE.getOpaque(this);
+        }
+
+        protected final void setNextPlain(final TableEntry<V> next) {
+            NEXT_HANDLE.set(this, next);
+        }
+
+        protected final void setNextRelease(final TableEntry<V> next) {
+            NEXT_HANDLE.setRelease(this, next);
+        }
+
+        protected TableEntry(final long key, final V value) {
+            this.key = key;
+            this.value = value;
+        }
+
+        public long getKey() {
+            return this.key;
+        }
+
+        public V getValue() {
+            return this.getValueAcquire();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public V setValue(final V value) {
+            if (value == null) {
+                throw new NullPointerException();
+            }
+
+            final V curr = this.getValuePlain();
+
+            this.setValueRelease(value);
+            return curr;
+        }
+
+        protected static int hash(final long key, final Object value) {
+            return SWMRLong2ObjectHashTable.getHash(key) ^ (value == null ? 0 : value.hashCode());
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public int hashCode() {
+            return hash(this.key, this.getValueAcquire());
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public boolean equals(final Object obj) {
+            if (this == obj) {
+                return true;
+            }
+
+            if (!(obj instanceof TableEntry<?>)) {
+                return false;
+            }
+            final TableEntry<?> other = (TableEntry<?>)obj;
+            final long otherKey = other.getKey();
+            final long thisKey = this.getKey();
+            final Object otherValue = other.getValueAcquire();
+            final V thisVal = this.getValueAcquire();
+            return (thisKey == otherKey) && (thisVal == otherValue || thisVal.equals(otherValue));
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/util/ArrayUtil.java b/src/main/java/ca/spottedleaf/concurrentutil/util/ArrayUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..ebb1ab06165addb173fea4d295001fe37f4e79d3
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/util/ArrayUtil.java
@@ -0,0 +1,816 @@
+package ca.spottedleaf.concurrentutil.util;
+
+import java.lang.invoke.VarHandle;
+
+public final class ArrayUtil {
+
+    public static final VarHandle BOOLEAN_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(boolean[].class);
+
+    public static final VarHandle BYTE_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(byte[].class);
+
+    public static final VarHandle SHORT_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(short[].class);
+
+    public static final VarHandle INT_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(int[].class);
+
+    public static final VarHandle LONG_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(long[].class);
+
+    public static final VarHandle OBJECT_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(Object[].class);
+
+    private ArrayUtil() {
+        throw new RuntimeException();
+    }
+
+    /* byte array */
+
+    public static byte getPlain(final byte[] array, final int index) {
+        return (byte)BYTE_ARRAY_HANDLE.get(array, index);
+    }
+
+    public static byte getOpaque(final byte[] array, final int index) {
+        return (byte)BYTE_ARRAY_HANDLE.getOpaque(array, index);
+    }
+
+    public static byte getAcquire(final byte[] array, final int index) {
+        return (byte)BYTE_ARRAY_HANDLE.getAcquire(array, index);
+    }
+
+    public static byte getVolatile(final byte[] array, final int index) {
+        return (byte)BYTE_ARRAY_HANDLE.getVolatile(array, index);
+    }
+
+    public static void setPlain(final byte[] array, final int index, final byte value) {
+        BYTE_ARRAY_HANDLE.set(array, index, value);
+    }
+
+    public static void setOpaque(final byte[] array, final int index, final byte value) {
+        BYTE_ARRAY_HANDLE.setOpaque(array, index, value);
+    }
+
+    public static void setRelease(final byte[] array, final int index, final byte value) {
+        BYTE_ARRAY_HANDLE.setRelease(array, index, value);
+    }
+
+    public static void setVolatile(final byte[] array, final int index, final byte value) {
+        BYTE_ARRAY_HANDLE.setVolatile(array, index, value);
+    }
+
+    public static void setVolatileContended(final byte[] array, final int index, final byte param) {
+        int failures = 0;
+
+        for (byte curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return;
+            }
+        }
+    }
+
+    public static byte compareAndExchangeVolatile(final byte[] array, final int index, final byte expect, final byte update) {
+        return (byte)BYTE_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static byte getAndAddVolatile(final byte[] array, final int index, final byte param) {
+        return (byte)BYTE_ARRAY_HANDLE.getAndAdd(array, index, param);
+    }
+
+    public static byte getAndAndVolatile(final byte[] array, final int index, final byte param) {
+        return (byte)BYTE_ARRAY_HANDLE.getAndBitwiseAnd(array, index, param);
+    }
+
+    public static byte getAndOrVolatile(final byte[] array, final int index, final byte param) {
+        return (byte)BYTE_ARRAY_HANDLE.getAndBitwiseOr(array, index, param);
+    }
+
+    public static byte getAndXorVolatile(final byte[] array, final int index, final byte param) {
+        return (byte)BYTE_ARRAY_HANDLE.getAndBitwiseXor(array, index, param);
+    }
+
+    public static byte getAndSetVolatile(final byte[] array, final int index, final byte param) {
+        return (byte)BYTE_ARRAY_HANDLE.getAndSet(array, index, param);
+    }
+
+    public static byte compareAndExchangeVolatileContended(final byte[] array, final int index, final byte expect, final byte update) {
+        return (byte)BYTE_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static byte getAndAddVolatileContended(final byte[] array, final int index, final byte param) {
+        int failures = 0;
+
+        for (byte curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (byte) (curr + param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static byte getAndAndVolatileContended(final byte[] array, final int index, final byte param) {
+        int failures = 0;
+
+        for (byte curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (byte) (curr & param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static byte getAndOrVolatileContended(final byte[] array, final int index, final byte param) {
+        int failures = 0;
+
+        for (byte curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (byte) (curr | param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static byte getAndXorVolatileContended(final byte[] array, final int index, final byte param) {
+        int failures = 0;
+
+        for (byte curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (byte) (curr ^ param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static byte getAndSetVolatileContended(final byte[] array, final int index, final byte param) {
+        int failures = 0;
+
+        for (byte curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return curr;
+            }
+        }
+    }
+
+    /* short array */
+
+    public static short getPlain(final short[] array, final int index) {
+        return (short)SHORT_ARRAY_HANDLE.get(array, index);
+    }
+
+    public static short getOpaque(final short[] array, final int index) {
+        return (short)SHORT_ARRAY_HANDLE.getOpaque(array, index);
+    }
+
+    public static short getAcquire(final short[] array, final int index) {
+        return (short)SHORT_ARRAY_HANDLE.getAcquire(array, index);
+    }
+
+    public static short getVolatile(final short[] array, final int index) {
+        return (short)SHORT_ARRAY_HANDLE.getVolatile(array, index);
+    }
+
+    public static void setPlain(final short[] array, final int index, final short value) {
+        SHORT_ARRAY_HANDLE.set(array, index, value);
+    }
+
+    public static void setOpaque(final short[] array, final int index, final short value) {
+        SHORT_ARRAY_HANDLE.setOpaque(array, index, value);
+    }
+
+    public static void setRelease(final short[] array, final int index, final short value) {
+        SHORT_ARRAY_HANDLE.setRelease(array, index, value);
+    }
+
+    public static void setVolatile(final short[] array, final int index, final short value) {
+        SHORT_ARRAY_HANDLE.setVolatile(array, index, value);
+    }
+
+    public static void setVolatileContended(final short[] array, final int index, final short param) {
+        int failures = 0;
+
+        for (short curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return;
+            }
+        }
+    }
+
+    public static short compareAndExchangeVolatile(final short[] array, final int index, final short expect, final short update) {
+        return (short)SHORT_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static short getAndAddVolatile(final short[] array, final int index, final short param) {
+        return (short)SHORT_ARRAY_HANDLE.getAndAdd(array, index, param);
+    }
+
+    public static short getAndAndVolatile(final short[] array, final int index, final short param) {
+        return (short)SHORT_ARRAY_HANDLE.getAndBitwiseAnd(array, index, param);
+    }
+
+    public static short getAndOrVolatile(final short[] array, final int index, final short param) {
+        return (short)SHORT_ARRAY_HANDLE.getAndBitwiseOr(array, index, param);
+    }
+
+    public static short getAndXorVolatile(final short[] array, final int index, final short param) {
+        return (short)SHORT_ARRAY_HANDLE.getAndBitwiseXor(array, index, param);
+    }
+
+    public static short getAndSetVolatile(final short[] array, final int index, final short param) {
+        return (short)SHORT_ARRAY_HANDLE.getAndSet(array, index, param);
+    }
+
+    public static short compareAndExchangeVolatileContended(final short[] array, final int index, final short expect, final short update) {
+        return (short)SHORT_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static short getAndAddVolatileContended(final short[] array, final int index, final short param) {
+        int failures = 0;
+
+        for (short curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (short) (curr + param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static short getAndAndVolatileContended(final short[] array, final int index, final short param) {
+        int failures = 0;
+
+        for (short curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (short) (curr & param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static short getAndOrVolatileContended(final short[] array, final int index, final short param) {
+        int failures = 0;
+
+        for (short curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (short) (curr | param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static short getAndXorVolatileContended(final short[] array, final int index, final short param) {
+        int failures = 0;
+
+        for (short curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (short) (curr ^ param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static short getAndSetVolatileContended(final short[] array, final int index, final short param) {
+        int failures = 0;
+
+        for (short curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return curr;
+            }
+        }
+    }
+
+    /* int array */
+
+    public static int getPlain(final int[] array, final int index) {
+        return (int)INT_ARRAY_HANDLE.get(array, index);
+    }
+
+    public static int getOpaque(final int[] array, final int index) {
+        return (int)INT_ARRAY_HANDLE.getOpaque(array, index);
+    }
+
+    public static int getAcquire(final int[] array, final int index) {
+        return (int)INT_ARRAY_HANDLE.getAcquire(array, index);
+    }
+
+    public static int getVolatile(final int[] array, final int index) {
+        return (int)INT_ARRAY_HANDLE.getVolatile(array, index);
+    }
+
+    public static void setPlain(final int[] array, final int index, final int value) {
+        INT_ARRAY_HANDLE.set(array, index, value);
+    }
+
+    public static void setOpaque(final int[] array, final int index, final int value) {
+        INT_ARRAY_HANDLE.setOpaque(array, index, value);
+    }
+
+    public static void setRelease(final int[] array, final int index, final int value) {
+        INT_ARRAY_HANDLE.setRelease(array, index, value);
+    }
+
+    public static void setVolatile(final int[] array, final int index, final int value) {
+        INT_ARRAY_HANDLE.setVolatile(array, index, value);
+    }
+
+    public static void setVolatileContended(final int[] array, final int index, final int param) {
+        int failures = 0;
+
+        for (int curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return;
+            }
+        }
+    }
+
+    public static int compareAndExchangeVolatile(final int[] array, final int index, final int expect, final int update) {
+        return (int)INT_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static int getAndAddVolatile(final int[] array, final int index, final int param) {
+        return (int)INT_ARRAY_HANDLE.getAndAdd(array, index, param);
+    }
+
+    public static int getAndAndVolatile(final int[] array, final int index, final int param) {
+        return (int)INT_ARRAY_HANDLE.getAndBitwiseAnd(array, index, param);
+    }
+
+    public static int getAndOrVolatile(final int[] array, final int index, final int param) {
+        return (int)INT_ARRAY_HANDLE.getAndBitwiseOr(array, index, param);
+    }
+
+    public static int getAndXorVolatile(final int[] array, final int index, final int param) {
+        return (int)INT_ARRAY_HANDLE.getAndBitwiseXor(array, index, param);
+    }
+
+    public static int getAndSetVolatile(final int[] array, final int index, final int param) {
+        return (int)INT_ARRAY_HANDLE.getAndSet(array, index, param);
+    }
+
+    public static int compareAndExchangeVolatileContended(final int[] array, final int index, final int expect, final int update) {
+        return (int)INT_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static int getAndAddVolatileContended(final int[] array, final int index, final int param) {
+        int failures = 0;
+
+        for (int curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (int) (curr + param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static int getAndAndVolatileContended(final int[] array, final int index, final int param) {
+        int failures = 0;
+
+        for (int curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (int) (curr & param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static int getAndOrVolatileContended(final int[] array, final int index, final int param) {
+        int failures = 0;
+
+        for (int curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (int) (curr | param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static int getAndXorVolatileContended(final int[] array, final int index, final int param) {
+        int failures = 0;
+
+        for (int curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (int) (curr ^ param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static int getAndSetVolatileContended(final int[] array, final int index, final int param) {
+        int failures = 0;
+
+        for (int curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return curr;
+            }
+        }
+    }
+
+    /* long array */
+
+    public static long getPlain(final long[] array, final int index) {
+        return (long)LONG_ARRAY_HANDLE.get(array, index);
+    }
+
+    public static long getOpaque(final long[] array, final int index) {
+        return (long)LONG_ARRAY_HANDLE.getOpaque(array, index);
+    }
+
+    public static long getAcquire(final long[] array, final int index) {
+        return (long)LONG_ARRAY_HANDLE.getAcquire(array, index);
+    }
+
+    public static long getVolatile(final long[] array, final int index) {
+        return (long)LONG_ARRAY_HANDLE.getVolatile(array, index);
+    }
+
+    public static void setPlain(final long[] array, final int index, final long value) {
+        LONG_ARRAY_HANDLE.set(array, index, value);
+    }
+
+    public static void setOpaque(final long[] array, final int index, final long value) {
+        LONG_ARRAY_HANDLE.setOpaque(array, index, value);
+    }
+
+    public static void setRelease(final long[] array, final int index, final long value) {
+        LONG_ARRAY_HANDLE.setRelease(array, index, value);
+    }
+
+    public static void setVolatile(final long[] array, final int index, final long value) {
+        LONG_ARRAY_HANDLE.setVolatile(array, index, value);
+    }
+
+    public static void setVolatileContended(final long[] array, final int index, final long param) {
+        int failures = 0;
+
+        for (long curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return;
+            }
+        }
+    }
+
+    public static long compareAndExchangeVolatile(final long[] array, final int index, final long expect, final long update) {
+        return (long)LONG_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static long getAndAddVolatile(final long[] array, final int index, final long param) {
+        return (long)LONG_ARRAY_HANDLE.getAndAdd(array, index, param);
+    }
+
+    public static long getAndAndVolatile(final long[] array, final int index, final long param) {
+        return (long)LONG_ARRAY_HANDLE.getAndBitwiseAnd(array, index, param);
+    }
+
+    public static long getAndOrVolatile(final long[] array, final int index, final long param) {
+        return (long)LONG_ARRAY_HANDLE.getAndBitwiseOr(array, index, param);
+    }
+
+    public static long getAndXorVolatile(final long[] array, final int index, final long param) {
+        return (long)LONG_ARRAY_HANDLE.getAndBitwiseXor(array, index, param);
+    }
+
+    public static long getAndSetVolatile(final long[] array, final int index, final long param) {
+        return (long)LONG_ARRAY_HANDLE.getAndSet(array, index, param);
+    }
+
+    public static long compareAndExchangeVolatileContended(final long[] array, final int index, final long expect, final long update) {
+        return (long)LONG_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static long getAndAddVolatileContended(final long[] array, final int index, final long param) {
+        int failures = 0;
+
+        for (long curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (long) (curr + param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static long getAndAndVolatileContended(final long[] array, final int index, final long param) {
+        int failures = 0;
+
+        for (long curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (long) (curr & param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static long getAndOrVolatileContended(final long[] array, final int index, final long param) {
+        int failures = 0;
+
+        for (long curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (long) (curr | param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static long getAndXorVolatileContended(final long[] array, final int index, final long param) {
+        int failures = 0;
+
+        for (long curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (long) (curr ^ param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static long getAndSetVolatileContended(final long[] array, final int index, final long param) {
+        int failures = 0;
+
+        for (long curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return curr;
+            }
+        }
+    }
+
+    /* boolean array */
+
+    public static boolean getPlain(final boolean[] array, final int index) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.get(array, index);
+    }
+
+    public static boolean getOpaque(final boolean[] array, final int index) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.getOpaque(array, index);
+    }
+
+    public static boolean getAcquire(final boolean[] array, final int index) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.getAcquire(array, index);
+    }
+
+    public static boolean getVolatile(final boolean[] array, final int index) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.getVolatile(array, index);
+    }
+
+    public static void setPlain(final boolean[] array, final int index, final boolean value) {
+        BOOLEAN_ARRAY_HANDLE.set(array, index, value);
+    }
+
+    public static void setOpaque(final boolean[] array, final int index, final boolean value) {
+        BOOLEAN_ARRAY_HANDLE.setOpaque(array, index, value);
+    }
+
+    public static void setRelease(final boolean[] array, final int index, final boolean value) {
+        BOOLEAN_ARRAY_HANDLE.setRelease(array, index, value);
+    }
+
+    public static void setVolatile(final boolean[] array, final int index, final boolean value) {
+        BOOLEAN_ARRAY_HANDLE.setVolatile(array, index, value);
+    }
+
+    public static void setVolatileContended(final boolean[] array, final int index, final boolean param) {
+        int failures = 0;
+
+        for (boolean curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return;
+            }
+        }
+    }
+
+    public static boolean compareAndExchangeVolatile(final boolean[] array, final int index, final boolean expect, final boolean update) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static boolean getAndOrVolatile(final boolean[] array, final int index, final boolean param) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.getAndBitwiseOr(array, index, param);
+    }
+
+    public static boolean getAndXorVolatile(final boolean[] array, final int index, final boolean param) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.getAndBitwiseXor(array, index, param);
+    }
+
+    public static boolean getAndSetVolatile(final boolean[] array, final int index, final boolean param) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.getAndSet(array, index, param);
+    }
+
+    public static boolean compareAndExchangeVolatileContended(final boolean[] array, final int index, final boolean expect, final boolean update) {
+        return (boolean)BOOLEAN_ARRAY_HANDLE.compareAndExchange(array, index, expect, update);
+    }
+
+    public static boolean getAndAndVolatileContended(final boolean[] array, final int index, final boolean param) {
+        int failures = 0;
+
+        for (boolean curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (boolean) (curr & param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static boolean getAndOrVolatileContended(final boolean[] array, final int index, final boolean param) {
+        int failures = 0;
+
+        for (boolean curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (boolean) (curr | param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static boolean getAndXorVolatileContended(final boolean[] array, final int index, final boolean param) {
+        int failures = 0;
+
+        for (boolean curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, (boolean) (curr ^ param)))) {
+                return curr;
+            }
+        }
+    }
+
+    public static boolean getAndSetVolatileContended(final boolean[] array, final int index, final boolean param) {
+        int failures = 0;
+
+        for (boolean curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return curr;
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T getPlain(final T[] array, final int index) {
+        final Object ret = OBJECT_ARRAY_HANDLE.get((Object[])array, index);
+        return (T)ret;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T getOpaque(final T[] array, final int index) {
+        final Object ret = OBJECT_ARRAY_HANDLE.getOpaque((Object[])array, index);
+        return (T)ret;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T getAcquire(final T[] array, final int index) {
+        final Object ret = OBJECT_ARRAY_HANDLE.getAcquire((Object[])array, index);
+        return (T)ret;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T getVolatile(final T[] array, final int index) {
+        final Object ret = OBJECT_ARRAY_HANDLE.getVolatile((Object[])array, index);
+        return (T)ret;
+    }
+
+    public static <T> void setPlain(final T[] array, final int index, final T value) {
+        OBJECT_ARRAY_HANDLE.set((Object[])array, index, (Object)value);
+    }
+
+    public static <T> void setOpaque(final T[] array, final int index, final T value) {
+        OBJECT_ARRAY_HANDLE.setOpaque((Object[])array, index, (Object)value);
+    }
+
+    public static <T> void setRelease(final T[] array, final int index, final T value) {
+        OBJECT_ARRAY_HANDLE.setRelease((Object[])array, index, (Object)value);
+    }
+
+    public static <T> void setVolatile(final T[] array, final int index, final T value) {
+        OBJECT_ARRAY_HANDLE.setVolatile((Object[])array, index, (Object)value);
+    }
+
+    public static <T> void setVolatileContended(final T[] array, final int index, final T param) {
+        int failures = 0;
+
+        for (T curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return;
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T compareAndExchangeVolatile(final T[] array, final int index, final T expect, final T update) {
+        final Object ret = OBJECT_ARRAY_HANDLE.compareAndExchange((Object[])array, index, (Object)expect, (Object)update);
+        return (T)ret;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T getAndSetVolatile(final T[] array, final int index, final T param) {
+        final Object ret = BYTE_ARRAY_HANDLE.getAndSet((Object[])array, index, (Object)param);
+        return (T)ret;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T compareAndExchangeVolatileContended(final T[] array, final int index, final T expect, final T update) {
+        final Object ret = OBJECT_ARRAY_HANDLE.compareAndExchange((Object[])array, index, (Object)expect, (Object)update);
+        return (T)ret;
+    }
+
+    public static <T> T getAndSetVolatileContended(final T[] array, final int index, final T param) {
+        int failures = 0;
+
+        for (T curr = getVolatile(array, index);;++failures) {
+            for (int i = 0; i < failures; ++i) {
+                ConcurrentUtil.backoff();
+            }
+
+            if (curr == (curr = compareAndExchangeVolatileContended(array, index, curr, param))) {
+                return curr;
+            }
+        }
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/util/CollectionUtil.java b/src/main/java/ca/spottedleaf/concurrentutil/util/CollectionUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..9420b9822de99d3a31224642452835b0c986f7b4
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/util/CollectionUtil.java
@@ -0,0 +1,31 @@
+package ca.spottedleaf.concurrentutil.util;
+
+import java.util.Collection;
+
+public final class CollectionUtil {
+
+    public static String toString(final Collection<?> collection, final String name) {
+        return CollectionUtil.toString(collection, name, new StringBuilder(name.length() + 128)).toString();
+    }
+
+    public static StringBuilder toString(final Collection<?> collection, final String name, final StringBuilder builder) {
+        builder.append(name).append("{elements={");
+
+        boolean first = true;
+
+        for (final Object element : collection) {
+            if (!first) {
+                builder.append(", ");
+            }
+            first = false;
+
+            builder.append('"').append(element).append('"');
+        }
+
+        return builder.append("}}");
+    }
+
+    private CollectionUtil() {
+        throw new RuntimeException();
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/util/ConcurrentUtil.java b/src/main/java/ca/spottedleaf/concurrentutil/util/ConcurrentUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..23ae82e55696a7e2ff0e0f9609c0df6a48bb8d1d
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/util/ConcurrentUtil.java
@@ -0,0 +1,166 @@
+package ca.spottedleaf.concurrentutil.util;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import java.util.concurrent.locks.LockSupport;
+
+public final class ConcurrentUtil {
+
+    public static String genericToString(final Object object) {
+        return object == null ? "null" : object.getClass().getName() + ":" + object.hashCode() + ":" + object.toString();
+    }
+
+    public static void rethrow(Throwable exception) {
+        rethrow0(exception);
+    }
+
+    private static <T extends Throwable> void rethrow0(Throwable thr) throws T {
+        throw (T)thr;
+    }
+
+    public static VarHandle getVarHandle(final Class<?> lookIn, final String fieldName, final Class<?> fieldType) {
+        try {
+            return MethodHandles.privateLookupIn(lookIn, MethodHandles.lookup()).findVarHandle(lookIn, fieldName, fieldType);
+        } catch (final Exception ex) {
+            throw new RuntimeException(ex); // unreachable
+        }
+    }
+
+    public static VarHandle getStaticVarHandle(final Class<?> lookIn, final String fieldName, final Class<?> fieldType) {
+        try {
+            return MethodHandles.privateLookupIn(lookIn, MethodHandles.lookup()).findStaticVarHandle(lookIn, fieldName, fieldType);
+        } catch (final Exception ex) {
+            throw new RuntimeException(ex); // unreachable
+        }
+    }
+
+    /**
+     * Non-exponential backoff algorithm to use in lightly contended areas.
+     * @see ConcurrentUtil#exponentiallyBackoffSimple(long)
+     * @see ConcurrentUtil#exponentiallyBackoffComplex(long)
+     */
+    public static void backoff() {
+        Thread.onSpinWait();
+    }
+
+    /**
+     * Backoff algorithm to use for a short held lock (i.e compareAndExchange operation). Generally this should not be
+     * used when a thread can block another thread. Instead, use {@link ConcurrentUtil#exponentiallyBackoffComplex(long)}.
+     * @param counter The current counter.
+     * @return The counter plus 1.
+     * @see ConcurrentUtil#backoff()
+     * @see ConcurrentUtil#exponentiallyBackoffComplex(long)
+     */
+    public static long exponentiallyBackoffSimple(final long counter) {
+        for (long i = 0; i < counter; ++i) {
+            backoff();
+        }
+        return counter + 1L;
+    }
+
+    /**
+     * Backoff algorithm to use for a lock that can block other threads (i.e if another thread contending with this thread
+     * can be thrown off the scheduler). This lock should not be used for simple locks such as compareAndExchange.
+     * @param counter The current counter.
+     * @return The next (if any) step in the backoff logic.
+     * @see ConcurrentUtil#backoff()
+     * @see ConcurrentUtil#exponentiallyBackoffSimple(long)
+     */
+    public static long exponentiallyBackoffComplex(final long counter) {
+        // TODO experimentally determine counters
+        if (counter < 100L) {
+            return exponentiallyBackoffSimple(counter);
+        }
+        if (counter < 1_200L) {
+            Thread.yield();
+            LockSupport.parkNanos(1_000L);
+            return counter + 1L;
+        }
+        // scale 0.1ms (100us) per failure
+        Thread.yield();
+        LockSupport.parkNanos(100_000L * counter);
+        return counter + 1;
+    }
+
+    /**
+     * Simple exponential backoff that will linearly increase the time per failure, according to the scale.
+     * @param counter The current failure counter.
+     * @param scale Time per failure, in ns.
+     * @param max The maximum time to wait for, in ns.
+     * @return The next counter.
+     */
+    public static long linearLongBackoff(long counter, final long scale, long max) {
+        counter = Math.min(Long.MAX_VALUE, counter + 1); // prevent overflow
+        max = Math.max(0, max);
+
+        if (scale <= 0L) {
+            return counter;
+        }
+
+        long time = scale * counter;
+
+        if (time > max || time / scale != counter) {
+            time = max;
+        }
+
+        boolean interrupted = Thread.interrupted();
+        if (time > 1_000_000L) { // 1ms
+            Thread.yield();
+        }
+        LockSupport.parkNanos(time);
+        if (interrupted) {
+            Thread.currentThread().interrupt();
+        }
+        return counter;
+    }
+
+    /**
+     * Simple exponential backoff that will linearly increase the time per failure, according to the scale.
+     * @param counter The current failure counter.
+     * @param scale Time per failure, in ns.
+     * @param max The maximum time to wait for, in ns.
+     * @param deadline The deadline in ns. Deadline time source: {@link System#nanoTime()}.
+     * @return The next counter.
+     */
+    public static long linearLongBackoffDeadline(long counter, final long scale, long max, long deadline) {
+        counter = Math.min(Long.MAX_VALUE, counter + 1); // prevent overflow
+        max = Math.max(0, max);
+
+        if (scale <= 0L) {
+            return counter;
+        }
+
+        long time = scale * counter;
+
+        // check overflow
+        if (time / scale != counter) {
+            // overflew
+            --counter;
+            time = max;
+        } else if (time > max) {
+            time = max;
+        }
+
+        final long currTime = System.nanoTime();
+        final long diff = deadline - currTime;
+        if (diff <= 0) {
+            return counter;
+        }
+        if (diff <= 1_500_000L) { // 1.5ms
+            time = 100_000L; // 100us
+        } else if (time > 1_000_000L) { // 1ms
+            Thread.yield();
+        }
+
+        boolean interrupted = Thread.interrupted();
+        LockSupport.parkNanos(time);
+        if (interrupted) {
+            Thread.currentThread().interrupt();
+        }
+        return counter;
+    }
+
+    public static VarHandle getArrayHandle(final Class<?> type) {
+        return MethodHandles.arrayElementVarHandle(type);
+    }
+}
diff --git a/src/main/java/ca/spottedleaf/concurrentutil/util/Validate.java b/src/main/java/ca/spottedleaf/concurrentutil/util/Validate.java
new file mode 100644
index 0000000000000000000000000000000000000000..382177d0d162fa3139c9078a873ce2504a2b17b2
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/concurrentutil/util/Validate.java
@@ -0,0 +1,28 @@
+package ca.spottedleaf.concurrentutil.util;
+
+public final class Validate {
+
+    public static <T> T notNull(final T obj) {
+        if (obj == null) {
+            throw new NullPointerException();
+        }
+        return obj;
+    }
+
+    public static <T> T notNull(final T obj, final String msgIfNull) {
+        if (obj == null) {
+            throw new NullPointerException(msgIfNull);
+        }
+        return obj;
+    }
+
+    public static void arrayBounds(final int off, final int len, final int arrayLength, final String msgPrefix) {
+        if (off < 0 || len < 0 || (arrayLength - off) < len) {
+            throw new ArrayIndexOutOfBoundsException(msgPrefix + ": off: " + off + ", len: " + len + ", array length: " + arrayLength);
+        }
+    }
+
+    private Validate() {
+        throw new RuntimeException();
+    }
+}