19 #include "TimeQueue.hpp" 
   20 #include <ErrorHandlingMacros.hpp> 
   21 #include <GlobalData.hpp> 
   22 #include <FastScheduler.hpp> 
   23 #include <VMSignal.hpp> 
   25 static const int MAX_TIME_QUEUE_VALUE = 32000;
 
   27 TimeQueue::TimeQueue()
 
   32 TimeQueue::~TimeQueue()
 
   39   globalData.theNextTimerJob = 65535;
 
   40   globalData.theCurrentTimer = 0;
 
   41   globalData.theShortTQIndex = 0;
 
   42   globalData.theLongTQIndex = 0;
 
   43   for (
int i = 0; 
i < MAX_NO_OF_TQ; 
i++)
 
   44     theFreeIndex[
i] = 
i+1;
 
   45   theFreeIndex[MAX_NO_OF_TQ - 1] = NULL_TQ_ENTRY;
 
   46   globalData.theFirstFreeTQIndex = 0;
 
   50 TimeQueue::insert(
Signal* signal, BlockNumber bnr, 
 
   51                   GlobalSignalNumber gsn, Uint32 delayTime)
 
   55   register Uint32 regCurrentTime = globalData.theCurrentTimer;
 
   57   register Uint32 regSave;
 
   60   newEntry.time_struct.delay_time = regCurrentTime + delayTime;
 
   61   newEntry.time_struct.job_index = getIndex();
 
   62   regSave = newEntry.copy_struct;
 
   64   globalScheduler.insertTimeQueue(signal, bnr, gsn, 
 
   65                                   newEntry.time_struct.job_index);
 
   67   if (newEntry.time_struct.delay_time < globalData.theNextTimerJob)
 
   68     globalData.theNextTimerJob = newEntry.time_struct.delay_time;
 
   70     register Uint32 regShortIndex = globalData.theShortTQIndex;
 
   71     if (regShortIndex == 0){
 
   72       theShortQueue[0].copy_struct = newEntry.copy_struct;
 
   73     } 
else if (regShortIndex >= MAX_NO_OF_SHORT_TQ - 1) {
 
   74       ERROR_SET(ecError, NDBD_EXIT_TIME_QUEUE_SHORT, 
 
   75                 "Too many in Short Time Queue", 
"TimeQueue.C" );
 
   77       for (i = 0; i < regShortIndex; i++) {
 
   78         if (theShortQueue[i].time_struct.delay_time > 
 
   79             newEntry.time_struct.delay_time)  {
 
   81           regSave = theShortQueue[
i].copy_struct;
 
   82           theShortQueue[
i].copy_struct = newEntry.copy_struct;
 
   86       if (i == regShortIndex) {
 
   87         theShortQueue[regShortIndex].copy_struct = regSave;
 
   89         for (i++; i < regShortIndex; i++) {
 
   90           register Uint32 regTmp = theShortQueue[
i].copy_struct;
 
   91           theShortQueue[
i].copy_struct = regSave;
 
   94         theShortQueue[regShortIndex].copy_struct = regSave;
 
   97     globalData.theShortTQIndex = regShortIndex + 1;
 
   98   } 
else if (delayTime <= (
unsigned)MAX_TIME_QUEUE_VALUE) {
 
   99     register Uint32 regLongIndex = globalData.theLongTQIndex;
 
  100     if (regLongIndex == 0) {
 
  101       theLongQueue[0].copy_struct = newEntry.copy_struct;
 
  102     } 
else if (regLongIndex >= MAX_NO_OF_LONG_TQ - 1) {
 
  103       ERROR_SET(ecError, NDBD_EXIT_TIME_QUEUE_LONG, 
 
  104                 "Too many in Long Time Queue", 
"TimeQueue.C" );
 
  106       for (i = 0; i < regLongIndex; i++) {
 
  107         if (theLongQueue[i].time_struct.delay_time > 
 
  108             newEntry.time_struct.delay_time) {
 
  110           regSave = theLongQueue[
i].copy_struct;
 
  111           theLongQueue[
i].copy_struct = newEntry.copy_struct;
 
  115       if (i == regLongIndex) {
 
  116         theLongQueue[regLongIndex].copy_struct = regSave;
 
  118         for (i++; i < regLongIndex; i++) {
 
  119           register Uint32 regTmp = theLongQueue[
i].copy_struct;
 
  120           theLongQueue[
i].copy_struct = regSave;
 
  123         theLongQueue[regLongIndex].copy_struct = regSave;
 
  126     globalData.theLongTQIndex = regLongIndex + 1;
 
  128     ERROR_SET(ecError, NDBD_EXIT_TIME_QUEUE_DELAY, 
 
  129               "Too long delay for Time Queue", 
"TimeQueue.C" );
 
  135 TimeQueue::scanTable()
 
  137   register Uint32 
i, j;
 
  139   globalData.theCurrentTimer++;
 
  140   if (globalData.theCurrentTimer == 32000)
 
  142   if (globalData.theNextTimerJob > globalData.theCurrentTimer)
 
  144   globalData.theNextTimerJob = 65535; 
 
  145   for (i = 0; i < globalData.theShortTQIndex; i++) {
 
  146     if (theShortQueue[i].time_struct.delay_time > globalData.theCurrentTimer){
 
  149       releaseIndex((Uint32)theShortQueue[i].time_struct.job_index);
 
  150       globalScheduler.scheduleTimeQueue(theShortQueue[i].time_struct.job_index);
 
  154     for (j = i; j < globalData.theShortTQIndex; j++)
 
  155       theShortQueue[j - i].copy_struct = theShortQueue[j].copy_struct;
 
  156     globalData.theShortTQIndex -= 
i;
 
  158   if (globalData.theShortTQIndex != 0) 
 
  159     globalData.theNextTimerJob = theShortQueue[0].time_struct.delay_time;
 
  160   for (i = 0; i < globalData.theLongTQIndex; i++) {
 
  161     if (theLongQueue[i].time_struct.delay_time > globalData.theCurrentTimer) {
 
  164       releaseIndex((Uint32)theLongQueue[i].time_struct.job_index);
 
  165       globalScheduler.scheduleTimeQueue(theLongQueue[i].time_struct.job_index);
 
  169     for (j = i; j < globalData.theLongTQIndex; j++)
 
  170       theLongQueue[j - i].copy_struct = theLongQueue[j].copy_struct;
 
  171     globalData.theLongTQIndex -= 
i;
 
  173   if (globalData.theLongTQIndex != 0) 
 
  174     if (globalData.theNextTimerJob > theLongQueue[0].time_struct.delay_time)
 
  175       globalData.theNextTimerJob = theLongQueue[0].time_struct.delay_time;
 
  179 TimeQueue::recount_timers()
 
  183   globalData.theCurrentTimer = 0;
 
  184   globalData.theNextTimerJob -= 32000;
 
  186   for (i = 0; i < globalData.theShortTQIndex; i++)
 
  187     theShortQueue[i].time_struct.delay_time -= 32000;
 
  188   for (i = 0; i < globalData.theLongTQIndex; i++)
 
  189     theLongQueue[i].time_struct.delay_time -= 32000;
 
  193 TimeQueue::getIndex()
 
  195   Uint32 retValue = globalData.theFirstFreeTQIndex;
 
  196   globalData.theFirstFreeTQIndex = (Uint32)theFreeIndex[retValue];
 
  197   if (retValue >= MAX_NO_OF_TQ)
 
  198     ERROR_SET(fatal, NDBD_EXIT_TIME_QUEUE_INDEX, 
 
  199               "Index out of range", 
"TimeQueue.C" );
 
  204 TimeQueue::releaseIndex(Uint32 aIndex)
 
  206   theFreeIndex[aIndex] = globalData.theFirstFreeTQIndex;
 
  207   globalData.theFirstFreeTQIndex = aIndex;