Finalizes config and allocates data memory buffer
| 1341 | |
| 1342 | // Finalizes config and allocates data memory buffer |
| 1343 | int cDataMemoryLevel::finaliseLevel() |
| 1344 | { |
| 1345 | if (lcfg.finalised) |
| 1346 | return 1; |
| 1347 | long minBuf; |
| 1348 | if (lcfg.blocksizeReader <= lcfg.blocksizeWriter) { |
| 1349 | minBuf = 2 * lcfg.blocksizeWriter + 1; // +1 just for safety... |
| 1350 | } else { |
| 1351 | minBuf = lcfg.blocksizeReader + 2 * lcfg.blocksizeWriter; // +1 just for safety... |
| 1352 | } |
| 1353 | // adjust level buffersize based on blocksize from write requests... |
| 1354 | if (lcfg.nT < minBuf) { |
| 1355 | lcfg.nT = minBuf; |
| 1356 | } |
| 1357 | lcfg.blocksizeIsSet = 1; |
| 1358 | if ( (!lcfg.blocksizeIsSet) || (!lcfg.namesAreSet) ) { |
| 1359 | COMP_ERR("cannot finalise level '%s' : blocksizeIsSet=%i, namesAreSet=%i (both should be 1...)", |
| 1360 | getName(), lcfg.blocksizeIsSet, lcfg.namesAreSet); |
| 1361 | } |
| 1362 | |
| 1363 | // allocate data matrix |
| 1364 | if ((lcfg.N<=0)||(lcfg.nT<=0)) COMP_ERR("cDataMemoryLevel::finaliseLevel: cannot allocate matrix with one (or more) dimensions == 0. did you add fields to this level ['%s']? (N=%i, nT=%i)",getName(),lcfg.N,lcfg.nT); |
| 1365 | data = new cMatrix(lcfg.N,lcfg.nT,lcfg.noTimeMeta); |
| 1366 | if (data==NULL) COMP_ERR("cannot allocate level (out of memory)!"); |
| 1367 | |
| 1368 | if (!lcfg.noTimeMeta) { |
| 1369 | // allocate tmeta |
| 1370 | tmeta = new TimeMetaInfo[lcfg.nT](); |
| 1371 | if (tmeta == NULL) OUT_OF_MEMORY; |
| 1372 | } |
| 1373 | |
| 1374 | // initialise mutexes: |
| 1375 | smileMutexCreate(RWptrMtx); |
| 1376 | smileMutexCreate(RWmtx); |
| 1377 | smileMutexCreate(RWstatMtx); |
| 1378 | |
| 1379 | lcfg.finalised = 1; |
| 1380 | return 1; |
| 1381 | } |
| 1382 | |
| 1383 | int cDataMemoryLevel::checkRead(long vIdx, int special, int rdId, long len, int *result) |
| 1384 | { |
no test coverage detected