/** * Flip a phase in the {@link WriterReaderPhaser} instance, {@link WriterReaderPhaser#flipPhase()} * can only be called while holding the {@link WriterReaderPhaser#readerLock() readerLock}. * {@link WriterReaderPhaser#flipPhase()} will return only after all writer critical sections (protected by * {@link WriterReaderPhaser#writerCriticalSectionEnter() writerCriticalSectionEnter} and * {@link WriterReaderPhaser#writerCriticalSectionExit writerCriticalSectionEnter}) that may have been * in flight when the {@link WriterReaderPhaser#flipPhase()} call were made had completed. * <p> * No actual writer critical section activity is required for {@link WriterReaderPhaser#flipPhase()} to * succeed. * <p> * However, {@link WriterReaderPhaser#flipPhase()} is lock-free with respect to calls to * {@link WriterReaderPhaser#writerCriticalSectionEnter()} and * {@link WriterReaderPhaser#writerCriticalSectionExit writerCriticalSectionExit()}. It may spin-wait * or for active writer critical section code to complete. */ public void flipPhase() { flipPhase(0); } }
@Override void setIntegerToDoubleValueConversionRatio(final double integerToDoubleValueConversionRatio) { try { wrp.readerLock(); inactiveCounts.doubleToIntegerValueConversionRatio = 1.0 / integerToDoubleValueConversionRatio; // switch active and inactive: AtomicLongArrayWithNormalizingOffset tmp = activeCounts; activeCounts = inactiveCounts; inactiveCounts = tmp; wrp.flipPhase(); inactiveCounts.doubleToIntegerValueConversionRatio = 1.0 / integerToDoubleValueConversionRatio; // switch active and inactive again: tmp = activeCounts; activeCounts = inactiveCounts; inactiveCounts = tmp; wrp.flipPhase(); // At this point, both active and inactive have normalizingIndexOffset safely set, // and the switch in each was done without any writers using the wrong value in flight. } finally { wrp.readerUnlock(); } super.setIntegerToDoubleValueConversionRatio(integerToDoubleValueConversionRatio); }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactiveHistogram == null) { inactiveHistogram = new InternalHistogram(activeHistogram); } inactiveHistogram.reset(); // Swap active and inactive histograms: final InternalHistogram tempHistogram = inactiveHistogram; inactiveHistogram = activeHistogram; activeHistogram = tempHistogram; // Mark end time of previous interval and start time of new one: long now = System.currentTimeMillis(); activeHistogram.setStartTimeStamp(now); inactiveHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously active histogram: // Flip phase to make sure no recordings that were in flight pre-flip are still active: recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock(); } }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactiveHistogram == null) { inactiveHistogram = new InternalDoubleHistogram(activeHistogram); } inactiveHistogram.reset(); // Swap active and inactive histograms: final InternalDoubleHistogram tempHistogram = inactiveHistogram; inactiveHistogram = activeHistogram; activeHistogram = tempHistogram; // Mark end time of previous interval and start time of new one: long now = System.currentTimeMillis(); activeHistogram.setStartTimeStamp(now); inactiveHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously active histogram: // Flip phase to make sure no recordings that were in flight pre-flip are still active: recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock(); } }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactiveHistogram == null) { inactiveHistogram = new InternalConcurrentDoubleHistogram(activeHistogram); } inactiveHistogram.reset(); // Swap active and inactive histograms: final InternalConcurrentDoubleHistogram tempHistogram = inactiveHistogram; inactiveHistogram = activeHistogram; activeHistogram = tempHistogram; // Mark end time of previous interval and start time of new one: long now = System.currentTimeMillis(); activeHistogram.setStartTimeStamp(now); inactiveHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously active histogram: // Flip phase to make sure no recordings that were in flight pre-flip are still active: recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock(); } }
recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock();
/** * Flip a phase in the {@link WriterReaderPhaser} instance, {@link WriterReaderPhaser#flipPhase()} * can only be called while holding the readerLock(). * {@link WriterReaderPhaser#flipPhase()} will return only after all writer critical sections (protected by * {@link WriterReaderPhaser#writerCriticalSectionEnter()} ()} and * {@link WriterReaderPhaser#writerCriticalSectionExit(long)} ()}) that may have been in flight when the * {@link WriterReaderPhaser#flipPhase()} call were made had completed. * <p> * No actual writer critical section activity is required for {@link WriterReaderPhaser#flipPhase()} to * succeed. * <p> * However, {@link WriterReaderPhaser#flipPhase()} is lock-free with respect to calls to * {@link WriterReaderPhaser#writerCriticalSectionEnter()} and * {@link WriterReaderPhaser#writerCriticalSectionExit(long)}. It may spin-wait for for active * writer critical section code to complete. */ public void flipPhase() { flipPhase(0); } }
@Override void setIntegerToDoubleValueConversionRatio(final double integerToDoubleValueConversionRatio) { try { wrp.readerLock(); inactiveCounts.doubleToIntegerValueConversionRatio = 1.0 / integerToDoubleValueConversionRatio; // switch active and inactive: AtomicLongArrayWithNormalizingOffset tmp = activeCounts; activeCounts = inactiveCounts; inactiveCounts = tmp; wrp.flipPhase(); inactiveCounts.doubleToIntegerValueConversionRatio = 1.0 / integerToDoubleValueConversionRatio; // switch active and inactive again: tmp = activeCounts; activeCounts = inactiveCounts; inactiveCounts = tmp; wrp.flipPhase(); // At this point, both active and inactive have normalizingIndexOffset safely set, // and the switch in each was done without any writers using the wrong value in flight. } finally { wrp.readerUnlock(); } super.setIntegerToDoubleValueConversionRatio(integerToDoubleValueConversionRatio); }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactive == null) { inactive = active.createEmptyCopy(); } else { inactive.reset(); } // Swap active and inactive top: final PositionRecorder temp = inactive; inactive = active; active = temp; recordingPhaser.flipPhase(); } finally { recordingPhaser.readerUnlock(); } }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactive == null) { inactive = active.createEmptyCopy(); } else { inactive.reset(); } // Swap active and inactive top: final PositionRecorder temp = inactive; inactive = active; active = temp; recordingPhaser.flipPhase(); } finally { recordingPhaser.readerUnlock(); } }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactiveHistogram == null) { inactiveHistogram = new InternalHistogram(activeHistogram); } inactiveHistogram.reset(); // Swap active and inactive histograms: final InternalHistogram tempHistogram = inactiveHistogram; inactiveHistogram = activeHistogram; activeHistogram = tempHistogram; // Mark end time of previous interval and start time of new one: long now = System.currentTimeMillis(); activeHistogram.setStartTimeStamp(now); inactiveHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously active histogram: // Flip phase to make sure no recordings that were in flight pre-flip are still active: recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock(); } }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactiveHistogram == null) { inactiveHistogram = new InternalDoubleHistogram(activeHistogram); } inactiveHistogram.reset(); // Swap active and inactive histograms: final InternalDoubleHistogram tempHistogram = inactiveHistogram; inactiveHistogram = activeHistogram; activeHistogram = tempHistogram; // Mark end time of previous interval and start time of new one: long now = System.currentTimeMillis(); activeHistogram.setStartTimeStamp(now); inactiveHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously active histogram: // Flip phase to make sure no recordings that were in flight pre-flip are still active: recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock(); } }
private void performIntervalSample() { try { recordingPhaser.readerLock(); // Make sure we have an inactive version to flip in: if (inactiveHistogram == null) { inactiveHistogram = new InternalConcurrentDoubleHistogram(activeHistogram); } inactiveHistogram.reset(); // Swap active and inactive histograms: final InternalConcurrentDoubleHistogram tempHistogram = inactiveHistogram; inactiveHistogram = activeHistogram; activeHistogram = tempHistogram; // Mark end time of previous interval and start time of new one: long now = System.currentTimeMillis(); activeHistogram.setStartTimeStamp(now); inactiveHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously active histogram: // Flip phase to make sure no recordings that were in flight pre-flip are still active: recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock(); } }
private synchronized void updateHistograms() { try { recordingPhaser.readerLock(); inactiveRawDataHistogram.reset(); inactivePauseCorrectionsHistogram.reset(); swapHistograms(); long now = System.currentTimeMillis(); activeRecordingHistogram.setStartTimeStamp(now); activePauseCorrectionsHistogram.setStartTimeStamp(now); inactiveRawDataHistogram.setEndTimeStamp(now); inactivePauseCorrectionsHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously current recording histogram: // Flip phase on epochs to make sure no in-flight recordings are active on pre-flip phase: recordingPhaser.flipPhase(); } finally { recordingPhaser.readerUnlock(); } }
private synchronized void updateHistograms() { try { recordingPhaser.readerLock(); inactiveRawDataHistogram.reset(); inactivePauseCorrectionsHistogram.reset(); swapHistograms(); long now = System.currentTimeMillis(); activeRecordingHistogram.setStartTimeStamp(now); activePauseCorrectionsHistogram.setStartTimeStamp(now); inactiveRawDataHistogram.setEndTimeStamp(now); inactivePauseCorrectionsHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously current recording histogram: // Flip phase on epochs to make sure no in-flight recordings are active on pre-flip phase: recordingPhaser.flipPhase(); } finally { recordingPhaser.readerUnlock(); } }
recordingPhaser.flipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.readerUnlock();