|
97 | 97 | private long router_start_time; |
98 | 98 | private int router_count; |
99 | 99 |
|
100 | | - final ThreadPool internal_lookup_pool; |
101 | | - final ThreadPool external_lookup_pool; |
102 | | - final ThreadPool internal_put_pool; |
103 | | - private final ThreadPool external_put_pool; |
| 100 | + private final ThreadPoolParent<DhtTask> internal_lookup_pool; |
| 101 | + private final ThreadPoolParent<DhtTask> external_lookup_pool; |
| 102 | + private final ThreadPoolParent<DhtTask> internal_put_pool; |
| 103 | + private final ThreadPoolParent<DhtTask> external_put_pool; |
104 | 104 |
|
105 | 105 | private final Map<HashWrapper, Object> imported_state = new HashMap<>(); |
106 | 106 |
|
|
235 | 235 | transport.getProtocolVersion(), |
236 | 236 | logger ); |
237 | 237 |
|
238 | | - internal_lookup_pool = new ThreadPool("DHTControl:internallookups", lookup_concurrency ); |
239 | | - internal_put_pool = new ThreadPool("DHTControl:internalputs", lookup_concurrency ); |
240 | | - |
241 | | - // external pools queue when full ( as opposed to blocking ) |
242 | | - |
243 | | - external_lookup_pool = new ThreadPool("DHTControl:externallookups", EXTERNAL_LOOKUP_CONCURRENCY, true ); |
244 | | - external_put_pool = new ThreadPool("DHTControl:puts", EXTERNAL_PUT_CONCURRENCY, true ); |
| 238 | + if ( AEThreadVirtual.areVirtualThreadsAvailable()){ |
| 239 | + |
| 240 | + internal_lookup_pool = new ThreadPoolVirtual<DhtTask>("DHTControl:internallookups", lookup_concurrency ); |
| 241 | + internal_put_pool = new ThreadPoolVirtual<DhtTask>("DHTControl:internalputs", lookup_concurrency ); |
| 242 | + |
| 243 | + // external pools queue when full ( as opposed to blocking ) |
| 244 | + |
| 245 | + external_lookup_pool = new ThreadPoolVirtual<DhtTask>("DHTControl:externallookups", EXTERNAL_LOOKUP_CONCURRENCY, true ); |
| 246 | + external_put_pool = new ThreadPoolVirtual<DhtTask>("DHTControl:puts", EXTERNAL_PUT_CONCURRENCY, true ); |
245 | 247 |
|
| 248 | + }else{ |
| 249 | + |
| 250 | + internal_lookup_pool = new ThreadPool<DhtTask>("DHTControl:internallookups", lookup_concurrency ); |
| 251 | + internal_put_pool = new ThreadPool<DhtTask>("DHTControl:internalputs", lookup_concurrency ); |
| 252 | + |
| 253 | + // external pools queue when full ( as opposed to blocking ) |
| 254 | + |
| 255 | + external_lookup_pool = new ThreadPool<DhtTask>("DHTControl:externallookups", EXTERNAL_LOOKUP_CONCURRENCY, true ); |
| 256 | + external_put_pool = new ThreadPool<DhtTask>("DHTControl:puts", EXTERNAL_PUT_CONCURRENCY, true ); |
| 257 | + } |
| 258 | + |
246 | 259 | createRouter( transport.getLocalContact()); |
247 | 260 |
|
248 | 261 | node_id_byte_count = router.getID().length; |
|
962 | 975 |
|
963 | 976 | // we don't want this to be blocking as it'll stuff the stats |
964 | 977 |
|
965 | | - external_lookup_pool.run( |
| 978 | + external_lookup_pool.runTask( |
966 | 979 | new DhtTask(external_lookup_pool) |
967 | 980 | { |
968 | 981 | private byte[] target = {}; |
|
1072 | 1085 |
|
1073 | 1086 | protected void |
1074 | 1087 | put( |
1075 | | - ThreadPool thread_pool, |
| 1088 | + ThreadPoolParent<DhtTask> thread_pool, |
1076 | 1089 | boolean high_priority, |
1077 | 1090 | byte[] initial_encoded_key, |
1078 | 1091 | String description, |
|
1099 | 1112 |
|
1100 | 1113 | protected void |
1101 | 1114 | put( |
1102 | | - final ThreadPool thread_pool, |
| 1115 | + final ThreadPoolParent<DhtTask> thread_pool, |
1103 | 1116 | final boolean high_priority, |
1104 | 1117 | final byte[] initial_encoded_key, |
1105 | 1118 | final String description, |
|
1413 | 1426 |
|
1414 | 1427 | protected void |
1415 | 1428 | put( |
1416 | | - final ThreadPool thread_pool, |
| 1429 | + final ThreadPoolParent<DhtTask> thread_pool, |
1417 | 1430 | final boolean high_priority, |
1418 | 1431 | byte[][] initial_encoded_keys, |
1419 | 1432 | final String description, |
|
2371 | 2384 |
|
2372 | 2385 | protected DhtTask |
2373 | 2386 | lookup( |
2374 | | - final ThreadPool thread_pool, |
| 2387 | + ThreadPoolParent<DhtTask> thread_pool, |
2375 | 2388 | boolean high_priority, |
2376 | 2389 | final byte[] _lookup_id, |
2377 | 2390 | final String description, |
@@ -2588,14 +2601,22 @@ synchronized void release() |
2588 | 2601 | { |
2589 | 2602 | //System.out.println("release-start"); |
2590 | 2603 | runningState = 1; |
2591 | | - new AEThread2("DHT lookup runner",true) { |
2592 | | - @Override |
2593 | | - public void run() { |
2594 | | - thread_pool.registerThreadAsChild(worker); |
2595 | | - lookupSteps(); |
2596 | | - thread_pool.deregisterThreadAsChild(worker); |
2597 | | - } |
2598 | | - }.start(); |
| 2604 | + |
| 2605 | + if ( AEThreadVirtual.areVirtualThreadsAvailable()){ |
| 2606 | + |
| 2607 | + AEThreadVirtual.run("DHT lookup runner", this::lookupSteps ); |
| 2608 | + |
| 2609 | + }else{ |
| 2610 | + |
| 2611 | + new AEThread2("DHT lookup runner",true) { |
| 2612 | + @Override |
| 2613 | + public void run() { |
| 2614 | + thread_pool.registerThreadAsChild(worker); |
| 2615 | + lookupSteps(); |
| 2616 | + thread_pool.deregisterThreadAsChild(worker); |
| 2617 | + } |
| 2618 | + }.start(); |
| 2619 | + } |
2599 | 2620 | } |
2600 | 2621 | } |
2601 | 2622 |
|
@@ -3139,7 +3160,7 @@ public int compare( |
3139 | 3160 | } |
3140 | 3161 | }; |
3141 | 3162 |
|
3142 | | - thread_pool.run( task, high_priority, true); |
| 3163 | + thread_pool.runTask( task, high_priority, true); |
3143 | 3164 |
|
3144 | 3165 | return( task ); |
3145 | 3166 | } |
@@ -5623,7 +5644,7 @@ public int compare( |
5623 | 5644 |
|
5624 | 5645 | protected |
5625 | 5646 | DhtTask( |
5626 | | - ThreadPool thread_pool ) |
| 5647 | + ThreadPoolParent<DhtTask> thread_pool ) |
5627 | 5648 | { |
5628 | 5649 | activity = new controlActivity( thread_pool, this ); |
5629 | 5650 |
|
@@ -5819,13 +5840,13 @@ public int compare( |
5819 | 5840 | controlActivity |
5820 | 5841 | implements DHTControlActivity |
5821 | 5842 | { |
5822 | | - protected final ThreadPool tp; |
5823 | | - protected final DhtTask task; |
5824 | | - protected final int type; |
| 5843 | + protected final ThreadPoolParent<DhtTask> tp; |
| 5844 | + protected final DhtTask task; |
| 5845 | + protected final int type; |
5825 | 5846 |
|
5826 | 5847 | protected |
5827 | 5848 | controlActivity( |
5828 | | - ThreadPool _tp, |
| 5849 | + ThreadPoolParent<DhtTask> _tp, |
5829 | 5850 | DhtTask _task ) |
5830 | 5851 | { |
5831 | 5852 | tp = _tp; |
|
0 commit comments