| 437 | } |
| 438 | |
| 439 | void* fxFindChunk(txMachine* the, txSize size, txBoolean *once) |
| 440 | { |
| 441 | txBlock* block; |
| 442 | txChunk* chunk; |
| 443 | #if mxStress |
| 444 | if (fxShouldStress()) { |
| 445 | if (*once) { |
| 446 | fxCollect(the, XS_COMPACT_FLAG | XS_ORGANIC_FLAG); |
| 447 | *once = 0; |
| 448 | } |
| 449 | } |
| 450 | #endif |
| 451 | #if mxNoChunks |
| 452 | if ((the->currentChunksSize + size > the->maximumChunksSize)) { |
| 453 | fxCollect(the, XS_COMPACT_FLAG | XS_ORGANIC_FLAG); |
| 454 | if (the->collectFlag & XS_TRASHING_CHUNKS_FLAG) |
| 455 | the->maximumChunksSize += the->minimumChunksSize; |
| 456 | } |
| 457 | chunk = c_malloc_noforcefail(size); |
| 458 | if (!chunk) |
| 459 | fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT); |
| 460 | chunk->size = size; |
| 461 | chunk->temporary = (txByte*)the->firstBlock; |
| 462 | the->firstBlock = (txBlock*)chunk; |
| 463 | return chunk; |
| 464 | #endif |
| 465 | again: |
| 466 | block = the->firstBlock; |
| 467 | while (block) { |
| 468 | if ((block->current + size) <= block->limit) { |
| 469 | chunk = (txChunk*)(block->current); |
| 470 | block->current += size; |
| 471 | chunk->temporary = block->current; |
| 472 | return chunk; |
| 473 | } |
| 474 | block = block->nextBlock; |
| 475 | } |
| 476 | if (*once) { |
| 477 | txBoolean wasThrashing = ((the->collectFlag & XS_TRASHING_CHUNKS_FLAG) != 0), isThrashing; |
| 478 | fxCollect(the, XS_COMPACT_FLAG | XS_ORGANIC_FLAG); |
| 479 | isThrashing = ((the->collectFlag & XS_TRASHING_CHUNKS_FLAG) != 0); |
| 480 | *once = 0; |
| 481 | if (wasThrashing && isThrashing) |
| 482 | return C_NULL; |
| 483 | goto again; |
| 484 | } |
| 485 | return C_NULL; |
| 486 | } |
| 487 | |
| 488 | txSlot* fxFindKey(txMachine* the) |
| 489 | { |
no test coverage detected