- Timestamp:
- Mar 26, 2018, 11:16:06 AM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/output.c
r3190 r3191 67 67 - offsetof (struct output_segment, runs) \ 68 68 - sizeof (struct output_run)) 69 # define MEMBUF_MAX_TOTAL ( sizeof (void *) <= 4 \ 70 ? (size_t)512*1024 : (size_t)16*1024*1024 ) 69 71 70 72 static void *acquire_semaphore (void); … … 220 222 } 221 223 222 /* Helper for membuf_new_segment_write that figures out now much data needs to 223 be moved from the previous run in order to make it end with a newline. */ 224 /* Helper for membuf_write_new_segment and membuf_dump_most that figures out 225 now much data needs to be moved from the previous run in order to make it 226 end with a newline. */ 224 227 static size_t membuf_calc_move_len (struct output_run *tail_run) 225 228 { … … 242 245 a newline so that we pass whole lines to fwrite when dumping. */ 243 246 static size_t 244 membuf_ new_segment_write(struct output_membuf *membuf, const char *src,247 membuf_write_new_segment (struct output_membuf *membuf, const char *src, 245 248 size_t len, unsigned int *pseqno) 246 249 { … … 280 283 membuf->tail_run = &new_seg->runs[0]; 281 284 membuf->total += segsize; 282 membuf->left = segsize - sizeof (struct output_run) ;285 membuf->left = segsize - sizeof (struct output_run) - offset_runs; 283 286 284 287 /* Initialize and write data to the first run. */ … … 314 317 } 315 318 316 /* Worker for output_write that will try dump as much as possible of the 317 output, but making sure to try leave unfinished lines. */ 319 /* Worker for output_write that will dump most of the output when we hit 320 MEMBUF_MAX_TOTAL on either of the two membuf structures, then free all the 321 output segments. Incomplete lines will be held over to the next buffers 322 and copied into new segments. */ 318 323 static void 319 324 membuf_dump_most (struct output *out) 320 325 { 321 /** @todo check last segment and make local copies. */ 322 membuf_dump (out); 326 size_t out_to_move = membuf_calc_move_len (out->out.tail_run); 327 size_t err_to_move = membuf_calc_move_len (out->err.tail_run); 328 if (!out_to_move && !err_to_move) 329 membuf_dump (out); 330 else 331 { 332 /* Allocate a stack buffer for holding incomplete lines. This should be 333 fine since we're only talking about max 2 * MEMBUF_MAX_MOVE_LEN. 334 The -1 on the sequence numbers, ise because membuf_write_new_segment 335 will increment them before use. */ 336 unsigned int out_seqno = out_to_move ? out->out.tail_run->seqno - 1 : 0; 337 unsigned int err_seqno = err_to_move ? out->err.tail_run->seqno - 1 : 0; 338 char *tmp = alloca (out_to_move + err_to_move); 339 if (out_to_move) 340 { 341 out->out.tail_run->len -= out_to_move; 342 memcpy (tmp, 343 (char *)(out->out.tail_run + 1) + out->out.tail_run->len, 344 out_to_move); 345 } 346 if (err_to_move) 347 { 348 out->err.tail_run->len -= err_to_move; 349 memcpy (tmp + out_to_move, 350 (char *)(out->err.tail_run + 1) + out->err.tail_run->len, 351 err_to_move); 352 } 353 354 membuf_dump (out); 355 356 if (out_to_move) 357 { 358 size_t written = membuf_write_new_segment (&out->out, tmp, 359 out_to_move, &out_seqno); 360 assert (written == out_to_move); (void)written; 361 } 362 if (err_to_move) 363 { 364 size_t written = membuf_write_new_segment (&out->err, 365 tmp + out_to_move, 366 err_to_move, &err_seqno); 367 assert (written == err_to_move); (void)written; 368 } 369 } 323 370 } 324 371 … … 353 400 if (!runlen) 354 401 { 355 size_t max_total = sizeof (membuf) <= 4 ? 512*1024 : 16*1024*1024; 356 if (membuf->total < max_total) 357 runlen = membuf_new_segment_write (membuf, src, len, &out->seqno); 402 if (membuf->total < MEMBUF_MAX_TOTAL) 403 runlen = membuf_write_new_segment (membuf, src, len, &out->seqno); 358 404 else 359 405 membuf_dump_most (out); -
trunk/src/kmk/w32/winchildren.c
r3190 r3191 677 677 /* Move offPendingRead ahead by cbRead. */ 678 678 pPipe->offPendingRead += cbNewData; 679 assert(pPipe->offPendingRead < pPipe->cbBuffer);679 assert(pPipe->offPendingRead <= pPipe->cbBuffer); 680 680 if (pPipe->offPendingRead > pPipe->cbBuffer) 681 681 pPipe->offPendingRead = pPipe->cbBuffer;
Note:
See TracChangeset
for help on using the changeset viewer.