jpayne@68: package kmer; jpayne@68: jpayne@68: import java.util.ArrayList; jpayne@68: import java.util.concurrent.atomic.AtomicInteger; jpayne@68: jpayne@68: import shared.KillSwitch; jpayne@68: import shared.Shared; jpayne@68: import shared.Tools; jpayne@68: jpayne@68: public class OwnershipThread extends Thread { jpayne@68: jpayne@68: public static void clear(AbstractKmerTable[] tables){ jpayne@68: process(tables, CLEAR); jpayne@68: } jpayne@68: jpayne@68: public static void initialize(AbstractKmerTable[] tables){ jpayne@68: process(tables, INITIALIZE); jpayne@68: } jpayne@68: jpayne@68: private static void process(AbstractKmerTable[] tables, int mode){ jpayne@68: if(tables.length<2){ jpayne@68: if(mode==INITIALIZE){ jpayne@68: for(AbstractKmerTable akt : tables){akt.initializeOwnership();} jpayne@68: }else if(mode==CLEAR){ jpayne@68: for(AbstractKmerTable akt : tables){akt.clearOwnership();} jpayne@68: }else{ jpayne@68: KillSwitch.kill("Bad mode: "+mode); jpayne@68: } jpayne@68: return; jpayne@68: } jpayne@68: final int threads=Tools.min(Shared.threads(), tables.length); jpayne@68: final AtomicInteger next=new AtomicInteger(0); jpayne@68: ArrayList alpt=new ArrayList(threads); jpayne@68: for(int i=0; i