- Timestamp:
- Sep 15, 2020, 2:55:26 PM (5 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/memalloc.c
r3458 r3461 371 371 TRACE2((NULL, "pstackrelease: %p - %u refs (%s)\n", pst, refs, caller)); K_NOREF(caller); 372 372 if (refs == 0) { 373 shinstance * const psh = shthread_get_shell();374 373 struct stack_block *top; 375 374 while ((top = pst->top) != &pst->first) … … 382 381 pst->nextbyte = NULL; 383 382 pst->top = NULL; 384 /** @todo push into an alloc cache rather than freeing it */ 385 sh_free(psh, pst); 383 384 if (!psh->freepstack) 385 psh->freepstack = pst; 386 else 387 sh_free(psh, pst); 386 388 } 387 389 } else … … 395 397 while (target < psh->pstacksize) { 396 398 unsigned idx = --psh->pstacksize; 397 pstack_block *ps k= psh->pstack[idx];399 pstack_block *pst = psh->pstack[idx]; 398 400 psh->pstack[idx] = NULL; 399 if (psh->curpstack == psk) 400 psh->curpstack = idx > 0 ? psh->pstack[idx - 1] : NULL; 401 pstackrelease(psh, psk, "popstackmark"); 401 if (psh->curpstack == pst) { 402 pstack_block *pstnext; 403 if (idx <= 0 || (pstnext = psh->pstack[idx - 1])->done) 404 psh->curpstack = NULL; 405 else 406 psh->curpstack = pstnext; 407 } 408 pstackrelease(psh, pst, "popstackmark"); 402 409 } 403 410 … … 454 461 * Allocate and initialize it. 455 462 */ 456 pst = (pstack_block *)ckmalloc(psh, blocksize); 463 pst = psh->freepstack; 464 if (pst) 465 psh->freepstack = NULL; 466 else 467 pst = (pstack_block *)ckmalloc(psh, blocksize); 457 468 pst->nextbyte = &pst->first.space[0]; 458 469 pst->avail = blocksize - offsetof(pstack_block, first.space); 459 470 pst->topsize = blocksize - offsetof(pstack_block, first.space); 471 pst->top = &pst->first; 460 472 pst->strleft = 0; 461 pst->top = &pst->first;462 473 pst->allocations = 0; 463 474 pst->bytesalloced = 0; … … 468 479 pst->fragmentation = 0; 469 480 pst->refs = 1; 470 pst-> padding = 42;481 pst->done = K_FALSE; 471 482 pst->first.prev = NULL; 472 483 … … 480 491 TRACE2((psh, "pstackallocpush: %p - entry %u\n", pst, psh->pstacksize - 1)); 481 492 return pst; 493 } 494 495 /** 496 * Marks the block as done, preventing it from being marked current again. 497 */ 498 void pstackmarkdone(pstack_block *pst) 499 { 500 pst->done = K_TRUE; 482 501 } 483 502 -
trunk/src/kash/memalloc.h
r3458 r3461 94 94 unsigned pstackretainpush(struct shinstance *, struct pstack_block *); 95 95 struct pstack_block *pstackallocpush(struct shinstance *); 96 void pstackmarkdone(struct pstack_block *); 96 97 #endif 97 98 void *pstalloc(struct shinstance *, size_t); -
trunk/src/kash/parser.c
r3458 r3461 133 133 union node *ret; 134 134 int t; 135 135 #ifdef KASH_SEPARATE_PARSER_ALLOCATOR 136 pstack_block *pst = pstackallocpush(psh); 137 #endif 136 138 TRACE2((psh, "parsecmd(%d)\n", interact)); 137 #ifdef KASH_SEPARATE_PARSER_ALLOCATOR 138 pstackallocpush(psh); 139 #endif 139 140 140 psh->tokpushback = 0; 141 141 psh->doprompt = interact; … … 155 155 TRACE2((psh, "parsecmd(%d) returns:\n", interact)); 156 156 showtree(psh, ret); 157 #endif 158 #ifdef KASH_SEPARATE_PARSER_ALLOCATOR 159 pstackmarkdone(pst); 157 160 #endif 158 161 return ret; -
trunk/src/kash/shinstance.c
r3460 r3461 541 541 psh->pstack = NULL; 542 542 } 543 sh_free(psh, psh->freepstack); 544 psh->freepstack = NULL; 543 545 #endif 544 546 psh->markp = NULL; 545 546 547 547 548 /* -
trunk/src/kash/shinstance.h
r3460 r3461 131 131 /** Reference counter. */ 132 132 unsigned volatile refs; 133 unsigned padding; 133 /** Whether to make it current when is restored to the top of the stack. */ 134 KBOOL done; 134 135 /** The first stack block. */ 135 136 struct stack_block first; … … 339 340 unsigned pstacksize; /**< Number of entries in pstack. */ 340 341 unsigned pstackalloced; /**< The allocated size of pstack. */ 342 pstack_block *freepstack; /**< One cached pstack entry (lots of parsecmd calls). */ 341 343 #endif 342 344
Note:
See TracChangeset
for help on using the changeset viewer.