Changeset 15126 for trunk/FACT++
- Timestamp:
- 03/20/13 13:50:05 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r14734 r15126 166 166 EtiMemoryChunks[i].events[j] = evtId; 167 167 EtiMemoryChunks[i].nFreeSlots--; 168 if (EtiMemoryChunks[i].nFreeSlots < 0) 169 { 170 snprintf(str, MXSTR, "Number of free slot in chunk %d went below zero (%d) slot: %d", i, EtiMemoryChunks[i].nFreeSlots, j); 171 factOut(kError, 000, str); 172 return NULL; 173 } 168 174 mBufferMapping[evtIndex].eventNumber = evtId; 169 175 mBufferMapping[evtIndex].chunk = i; … … 174 180 //If I reach this point then we have a problem because it should have found 175 181 //a free spot just above. 182 snprintf(str, MXSTR, "Could not find a free slot in a chunk that's supposed to have some. chunk=%d", i); 183 factOut(kError, 000, str); 184 return NULL; 176 185 } 177 186 } 178 187 //If we reach this point this means that we should allocate more memory 179 int32_t numNewSlots = 0; 180 if ((numAllocatedChunks + 1)*MAX_CHUNK_SIZE < g_maxMem) 181 numNewSlots = MAX_SLOTS_PER_CHUNK; 182 else 183 numNewSlots = (g_maxMem - numAllocatedChunks*MAX_CHUNK_SIZE)/MAX_SLOT_SIZE; 184 185 if (numNewSlots == 0)//cannot allocate more without exceeding the max mem limit 186 { 188 int32_t numNewSlots = MAX_SLOTS_PER_CHUNK; 189 if ((numAllocatedChunks + 1)*MAX_CHUNK_SIZE >= g_maxMem) 187 190 return NULL; 188 } 189 190 EtiMemoryChunks[numAllocatedChunks].pointers[0] = malloc(MAX_SLOT_SIZE*numNewSlots); 191 192 EtiMemoryChunks[numAllocatedChunks].pointers[0] = malloc(MAX_SLOT_SIZE*MAX_SLOTS_PER_CHUNK); 191 193 if (EtiMemoryChunks[numAllocatedChunks].pointers[0] == NULL) 192 194 { … … 205 207 for (int i=1;i<numNewSlots;i++) 206 208 { 207 EtiMemoryChunks[numAllocatedChunks].pointers[i] = &(((char*)(EtiMemoryChunks[numAllocatedChunks].pointers[i-1]))[MAX_SLOT_SIZE]);209 EtiMemoryChunks[numAllocatedChunks].pointers[i] = EtiMemoryChunks[numAllocatedChunks].pointers[0] + i*MAX_SLOT_SIZE;// &(((char*)(EtiMemoryChunks[numAllocatedChunks].pointers[i-1]))[MAX_SLOT_SIZE]); 208 210 EtiMemoryChunks[numAllocatedChunks].events[i] = -1; 209 211 } … … 239 241 free(EtiMemoryChunks[chunkIndex].pointers[0]); 240 242 EtiMemoryChunks[chunkIndex].pointers[0] = NULL; 243 EtiMemoryChunks[chunkIndex].nSlots = 0; 241 244 numAllocatedChunks--; 242 245 chunkIndex--; … … 680 683 evID, sk); 681 684 factOut (kError, 882, str); 682 } else { 685 } 686 #ifdef EVTDEBUG 687 else 688 { 683 689 snprintf (str, MXSTR, "No memory left to keep event %6d sock %3d", 684 690 evID, sk); 685 691 factOut (kDebug, 882, str); 686 692 } 693 #endif 687 694 return -11; 688 695 } … … 767 774 768 775 776 #ifdef EVTDEBUG 769 777 snprintf (str, MXSTR, 770 778 "%5d %8d start new evt %8d %8d sock %3d len %5d t %10d", evID, 771 779 runID, i, evtCtrl.lastPtr, sk, fadlen, mBuffer[i].pcTime); 772 780 factOut (kDebug, -11, str); 781 #endif 773 782 evtCtrl.lastPtr++; 774 783 if (evtCtrl.lastPtr == MAX_EVT * MAX_RUN) … … 1135 1144 } else { 1136 1145 jrd = 0; //did read nothing as requested 1146 #ifdef EVTDEBUG 1137 1147 snprintf (str, MXSTR, "do not read from socket %d %d", i, 1138 1148 rd[i].bufLen); 1139 1149 factOut (kDebug, 301, str); 1140 } 1150 #endif 1151 } 1141 1152 1142 1153 gi.gotByte[b] += jrd; … … 1410 1421 } 1411 1422 } 1423 #ifdef EVTDEBUG 1412 1424 snprintf (str, MXSTR, 1413 1425 "%5d complete event roi %4d roiTM %d cpy %8d %5d", … … 1415 1427 qncpy, qnrun); 1416 1428 factOut (kDebug, -1, str); 1417 1429 #endif 1418 1430 //complete event read ---> flag for next processing 1419 1431 evtCtrl.evtStat[iDx] = 99; … … 1598 1610 1599 1611 int id = evtCtrl.evtBuf[k0]; 1612 #ifdef EVTDEBUG 1600 1613 snprintf (str, MXSTR, "%5d free event buffer, nb=%3d", 1601 1614 mBuffer[id].evNum, mBuffer[id].nBoard); 1602 1615 factOut (kDebug, -1, str); 1616 #endif 1603 1617 mBufFree (id); //event written--> free memory 1604 1618 evtCtrl.evtStat[k0] = -1; … … 1643 1657 } else { 1644 1658 xwait.tv_sec = 0; 1645 xwait.tv_nsec = 2000000; // sleep for ~2 msec1659 xwait.tv_nsec = 1000; // sleep for ~1 usec 1646 1660 } 1647 1661 nanosleep (&xwait, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.