Changeset 15510


Ignore:
Timestamp:
05/06/13 19:01:18 (11 years ago)
Author:
tbretz
Message:
Sanity check for mem==NULL in TGB_free; make sure that for each event memory can be allocated only once (and not again if it was already deleted because an incomplete event was cancelled; The 'no memory left' was issued not at the first but the second call; make sure that events which are already in the process of processing are not overwritten in readFAD; hopefully fixed the loop which checkes for events to be deleted; removed an obsolete argument from checkAndCloseRun
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/EventBuilder.c

    r15495 r15510  
    126126    // We will return this amount of memory
    127127    tgb_inuse += MAX_TOT_MEM;
     128    gj.bufTot++;
    128129
    129130    // No free slot available, allocate a new one
     
    147148void TGB_free(void *mem)
    148149{
     150    if (!mem)
     151        return;
     152
    149153    // Add the last free slot to the stack
    150154    TGB_entry *entry = (TGB_entry*)malloc(sizeof(TGB_entry));
     
    565569
    566570
    567 int
    568 mBufFree (int i)
    569 {
    570    TGB_free(evtCtrl[i].FADhead);
    571 
    572    evtCtrl[i].fEvent = NULL;
    573    evtCtrl[i].FADhead = NULL;
    574 
    575    evtCtrl[i].evNum = evtCtrl[i].nRoi = -1;
    576    evtCtrl[i].runNum = 0;
    577 
    578    gj.usdMem = tgb_inuse;
    579 
    580    gj.bufTot--;
    581 
    582    return 0;
    583 
    584 } /*-----------------------------------------------------------------*/
     571void mBufFree (int i)
     572{
     573    TGB_free(evtCtrl[i].FADhead);
     574
     575    evtCtrl[i].fEvent = NULL;
     576    evtCtrl[i].FADhead = NULL;
     577
     578    evtCtrl[i].evNum = evtCtrl[i].nRoi = -1;
     579    evtCtrl[i].runNum = 0;
     580
     581    gj.usdMem = tgb_inuse;
     582
     583    gj.bufTot--;
     584}
    585585
    586586uint64_t reportIncomplete(int id, const char *txt)
     
    10251025
    10261026          // We have a valid entry, but no memory has yet been allocated
    1027           if (idx >= 0 && evtCtrl[idx].FADhead == NULL)
     1027          if (idx >= 0 && evtCtrl[idx].evtStat==0 && evtCtrl[idx].FADhead==NULL)
    10281028          {
    10291029              // Try to get memory from the big buffer
     
    10331033                  // If this works properly, this is a hack which can be removed, or
    10341034                  // replaced by a signal or dim message
    1035                   if (rd[i].bufTyp==2)
    1036                       factPrintf(kError, 882, "malloc failed for event %d (run=%d)", evtCtrl[idx].evNum, evtCtrl[idx].runNum);
     1035                  if (rd[i].bufTyp==1)
     1036                      factPrintf(kError, 882, "No free memory left for %d (run=%d)", evtCtrl[idx].evNum, evtCtrl[idx].runNum);
    10371037                  rd[i].bufTyp = 2;
    10381038                  continue;
     
    10491049
    10501050              gj.rateNew++;
    1051               gj.bufTot++;
    10521051              if (gj.bufTot > gj.maxEvt)
    10531052                  gj.maxEvt = gj.bufTot;
     
    10621061          if (idx < -1000)
    10631062              continue;
     1063
     1064          if (evtCtrl[idx].evtStat==-1 || evtCtrl[idx].evtStat>=90)
     1065          {
     1066              factPrintf(kError, 882, "Received data of event %d [%d] (run=%d) has already been advanced (stat=%d)... skipping", evtCtrl[idx].evNum, i, evtCtrl[idx].runNum, evtCtrl[idx].evtStat);
     1067              continue;
     1068          }
    10641069
    10651070          //we have a valid entry in mBuffer[]; fill it
     
    11531158              // the user has expressed that the old events are obsolste now
    11541159              // and the run will be closed anyway
    1155               if (evtCtrl[k].evtStat>=0 && evtCtrl[k].evtStat<90)
     1160              if (evtCtrl[k].evtStat>0 && evtCtrl[k].evtStat<90)
    11561161              {
    11571162                  reportIncomplete(k, "expired");
     
    11851190      {
    11861191          // Check the more likely case first: incomplete events
    1187           if (evtCtrl[k0].evtStat>=0 && evtCtrl[k0].evtStat<100)
     1192          if (evtCtrl[k0].evtStat>0 && evtCtrl[k0].evtStat<100)
    11881193          {
    11891194              gj.bufNew++;     //incomplete event in Buffer
     
    12011206              //timeout for incomplete events
    12021207              evtCtrl[k0].evtStat = 90;
     1208
    12031209              gj.evtSkip++;
    12041210
     
    12091215          // evtState==0 can happen if the event was initialized (some data received)
    12101216          // but the data did not make sense (e.g. inconsistent rois)
    1211           if (evtCtrl[k0].evtStat==0 || evtCtrl[k0].evtStat == 10000)
     1217          if (evtCtrl[k0].evtStat==10000)
    12121218          {
     1219              evtCtrl[k0].evtStat = -1;
    12131220              mBufFree(k0);   //event written--> free memory
    1214               evtCtrl[k0].evtStat = -1;
    12151221
    12161222              gj.evtWrite++;
     
    13081314           // signals that the event can be deleted. (Note, that there are currently never
    13091315           // two threads processing the same event at the same time)
    1310            if ((evtCtrl[k0].evtStat>0 && evtCtrl[k0].evtStat<90) || evtCtrl[k0].evtStat==10000)
     1316           if (evtCtrl[k0].evtStat<90 || evtCtrl[k0].evtStat==10000)
    13111317           {
     1318               evtCtrl[k0].evtStat = -1;
    13121319               mBufFree(k0);   //event written--> free memory
    13131320               evtCtrl_frstPtr = (evtCtrl_frstPtr+1) % MAX_EVT;
    1314                evtCtrl[k0].evtStat = -1;
    13151321           }
    13161322
     
    14931499                   factPrintf(kError, 502, "procEvt: Could not open new file for run %d (idx=%d, evt=%d, runOpen failed)", irun, idx, ievt);
    14941500                   runCtrl[idx].fileId = 91;
     1501                   // FIXME: What happens to evtStat? Shell we really just try again?
    14951502                   continue;
    14961503               }
     
    15991606}
    16001607
    1601 void checkAndCloseRun(int j, int irun, int cond, int where)
     1608void checkAndCloseRun(int j, int cond, int where)
    16021609{
    16031610    if (!cond &&
     
    16301637    {
    16311638        factPrintf(kInfo, 503, "writeEvt-%d: Closed run %d (reason=%d)",
    1632                    where, irun, ii);
     1639                   where, runCtrl[j].runId, ii);
    16331640        runCtrl[j].fileId = 93+where*2;
    16341641    }
     
    16731680
    16741681           const uint32_t irun = evtCtrl[k0].runNum;
    1675            const int32_t  ievt = evtCtrl[k0].evNum;
    16761682
    16771683           const int idx = evtCtrl[k0].runCtrl_idx;
     
    16971703                   factPrintf(kError, 503, "writeEvt: Writing event for run %d failed (runWrite)", irun);
    16981704
    1699                checkAndCloseRun(idx, irun, rc<0, 1);
     1705               checkAndCloseRun(idx, rc<0, 1);
    17001706           }
    17011707
     
    17101716               //ETIENNE added the condition at this line. dunno what to do with run 0: skipping it
    17111717               const int cond = /*runCtrl[j].lastTime < lastStartedTime &&*/ runCtrl[j].runId == 0;
    1712                checkAndCloseRun(j, runCtrl[j].runId, cond, 2);
     1718               checkAndCloseRun(j, cond, 2);
    17131719           }
    17141720       }
     
    17311737   {
    17321738       if (runCtrl[j].fileId == 0)
    1733            checkAndCloseRun(j, runCtrl[j].runId, 1, 3);
     1739           checkAndCloseRun(j, 1, 3);
    17341740   }
    17351741
Note: See TracChangeset for help on using the changeset viewer.