public long extractAlarm(long now,boolean isTest){
  long lastTime=_now.getAndSet(now);
  long nextTime=_nextAlarmTime.get();
  if (now < nextTime) {
    return nextTime;
  }
  _nextAlarmTime.set(now + CLOCK_NEXT);
  int delta;
  delta=(int)(now - lastTime) / CLOCK_INTERVAL;
  delta=Math.min(delta,CLOCK_PERIOD);
  Alarm alarm;
  int bucket=getBucket(lastTime);
  for (int i=0; i <= delta; i++) {
    while ((alarm=extractNextAlarm(bucket,now,isTest)) != null) {
      dispatch(alarm,now,isTest);
    }
    bucket=(bucket + 1) % CLOCK_PERIOD;
  }
  while ((alarm=extractNextCurrentAlarm()) != null) {
    dispatch(alarm,now,isTest);
  }
  long next=updateNextAlarmTime(now);
  _lastTime=now;
  return next;
}

public long extractAlarm ( long now , boolean isTest ) { long lastTime = _now . getAndSet ( now ) ; long nextTime = _nextAlarmTime . get ( ) ; if ( now < nextTime ) { return nextTime ; } _nextAlarmTime . set ( now + CLOCK_NEXT ) ; int delta ; delta = ( int ) ( now - lastTime ) / CLOCK_INTERVAL ; delta = Math . min ( delta , CLOCK_PERIOD ) ; Alarm alarm ; int bucket = getBucket ( lastTime ) ; for ( int i = 0 ; i <= delta ; i ++ ) { while ( ( alarm = extractNextAlarm ( bucket , now , isTest ) ) != null ) { dispatch ( alarm , now , isTest ) ; } bucket = ( bucket + 1 ) % CLOCK_PERIOD ; } while ( ( alarm = extractNextCurrentAlarm ( ) ) != null ) { dispatch ( alarm , now , isTest ) ; } long next = updateNextAlarmTime ( now ) ; _lastTime = now ; return next ; }
returns the next alarm ready to run
