Skip to content

Commit

Permalink
Synchronize for reads as well as writes to shared state.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Oct 2, 2018
1 parent fce66a5 commit 085b399
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import java.util.Arrays;

/**
* Genotype likelihood calculator utility.
* Genotype likelihood calculator utility. This class is thread-safe since access to shared mutable state is
* synchronized.
*
* <p>
* This class provide genotype likelihood calculators with any number of alleles able given an arbitrary ploidy and allele
Expand Down Expand Up @@ -257,7 +258,7 @@ private static GenotypeAlleleCounts[] buildGenotypeAlleleCountsArray(final int p
*
* @return never {@code null}.
*/
public GenotypeLikelihoodCalculator getInstance(final int ploidy, final int alleleCount) {
public synchronized GenotypeLikelihoodCalculator getInstance(final int ploidy, final int alleleCount) {
checkPloidyAndMaximumAllele(ploidy, alleleCount);

if (calculateGenotypeCountUsingTables(ploidy, alleleCount) == GENOTYPE_COUNT_OVERFLOW) {
Expand All @@ -270,9 +271,7 @@ public GenotypeLikelihoodCalculator getInstance(final int ploidy, final int alle
}

/**
* Update of shared tables. Note that this method is synchronized to avoid race conditions in Spark. This is because
* in Spark each region has its own HaplotypeCallerEngine instance (so there can be multiple instances in a single
* JVM), but these share a single (static) instance of this class (via AlleleSubsettingUtils).
* Update of shared tables.
*
* @param requestedMaximumAllele the new requested maximum allele maximum.
* @param requestedMaximumPloidy the new requested ploidy maximum.
Expand Down Expand Up @@ -381,7 +380,7 @@ public static int computeMaxAcceptableAlleleCount(final int ploidy, final int ma
throw new GATKException("Code should never reach here.");
}

private int calculateGenotypeCountUsingTables(int ploidy, int alleleCount) {
private synchronized int calculateGenotypeCountUsingTables(int ploidy, int alleleCount) {
checkPloidyAndMaximumAllele(ploidy, alleleCount);
ensureCapacity(alleleCount, ploidy);
return alleleFirstGenotypeOffsetByPloidy[ploidy][alleleCount];
Expand Down

0 comments on commit 085b399

Please sign in to comment.