Skip to content

Commit 341c721

Browse files
committed
Run remote searches at low priority
1 parent d2b1563 commit 341c721

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

core/src/com/biglybt/core/content/RelatedContentSearcher.java

+24
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.biglybt.pif.ddb.*;
4141
import com.biglybt.pif.utils.search.*;
4242
import com.biglybt.pifimpl.local.ddb.DDBaseImpl;
43+
import com.biglybt.pifimpl.local.utils.UtilitiesImpl;
4344
import com.biglybt.plugin.dht.DHTPluginBasicInterface;
4445
import com.biglybt.plugin.dht.DHTPluginContact;
4546
import com.biglybt.plugin.dht.DHTPluginInterface.DHTInterface;
@@ -901,6 +902,29 @@
901902
int min_leechers,
902903
int max_age_secs,
903904
boolean is_local )
905+
{
906+
if ( is_local ){
907+
908+
return( matchContent0( term, min_seeds, min_leechers, max_age_secs, is_local ));
909+
910+
}else{
911+
912+
return(
913+
UtilitiesImpl.runAtLowPriority(
914+
"remsearch",
915+
()->{
916+
return( matchContent0( term, min_seeds, min_leechers, max_age_secs, is_local ));
917+
}));
918+
}
919+
}
920+
921+
List<RelatedContent>
922+
matchContent0(
923+
final String term,
924+
int min_seeds,
925+
int min_leechers,
926+
int max_age_secs,
927+
boolean is_local )
904928
{
905929
if ( !is_local ){
906930

core/src/com/biglybt/pifimpl/local/utils/UtilitiesImpl.java

+48
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.net.URL;
3535
import java.nio.ByteBuffer;
3636
import java.util.*;
37+
import java.util.function.Supplier;
3738

3839
import com.biglybt.core.Core;
3940
import com.biglybt.core.ipchecker.extipchecker.ExternalIPChecker;
@@ -1164,6 +1165,53 @@ public DelayedTask createDelayedTask(Runnable target) {
11641165
return addDelayedTask(pi.getPluginName(), target);
11651166
}
11661167

1168+
public static <T> T
1169+
runAtLowPriority(
1170+
String name,
1171+
Supplier<T> r )
1172+
{
1173+
Object [] result = { null };
1174+
1175+
AESemaphore sem = new AESemaphore( name );
1176+
1177+
AEThread2.createAndStartDaemon(
1178+
name,
1179+
()->{
1180+
try{
1181+
Thread t = Thread.currentThread();
1182+
1183+
int p = t.getPriority();
1184+
1185+
t.setPriority( Thread.MIN_PRIORITY );
1186+
1187+
try{
1188+
1189+
T res = r.get();
1190+
1191+
synchronized( result ){
1192+
1193+
result[0] = res;
1194+
}
1195+
1196+
1197+
}finally{
1198+
1199+
t.setPriority( p );
1200+
}
1201+
}finally{
1202+
1203+
sem.release();
1204+
}
1205+
});
1206+
1207+
sem.reserve();
1208+
1209+
synchronized( result ){
1210+
1211+
return( (T)result[0]);
1212+
}
1213+
}
1214+
11671215
private static List delayed_tasks = new ArrayList();
11681216
private static AESemaphore delayed_tasks_sem = new AESemaphore( "Utilities:delayedTask" );
11691217
private static AEThread2 delayed_task_thread;

0 commit comments

Comments
 (0)