File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
javasdk/NRSDK/src/com/neuronrobotics/sdk/common Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ public class BowlerDatagramFactory {
2828
2929 private static BowlerDatagram pool [];
3030 private static int failed =0 ;
31+ private static int lastIndex = 0 ;
3132 private static int poolDefaultSize = 1500 ;
3233 private static long packetTimeout = 2000 ;
3334
@@ -57,11 +58,20 @@ private static synchronized BowlerDatagram getNextPacket(){
5758 BowlerDatagram ref = null ;
5859
5960 //Find the most recent free packet from the pool
60- for (int i =0 ;(i <pool .length && ref ==null );i ++){
61+ for (int i =lastIndex ;(i <pool .length && ref ==null );i ++){
6162 //Log.warning("Checking pool packet "+i);
6263 if (pool [i ].isFree ()){
64+ lastIndex =i ;
6365 ref =pool [i ];
6466 }
67+ if (i ==pool .length -1 ){
68+ //loop around since we started at the last index
69+ i =0 ;
70+ }
71+ if (i ==lastIndex -1 ){
72+ //looped around, bail
73+ i =pool .length ;
74+ }
6575 }
6676 if (ref == null ){
6777 //The whole list was search and no free packets were found
You can’t perform that action at this time.
0 commit comments