| 386 | } |
| 387 | |
| 388 | void switchChunk() { |
| 389 | _chunk_start = finishChunk(); |
| 390 | _start_time = _stop_time; |
| 391 | _start_ticks = _stop_ticks; |
| 392 | _base_id += 0x1000000; |
| 393 | _bytes_written = 0; |
| 394 | |
| 395 | writeHeader(_buf); |
| 396 | writeMetadata(_buf); |
| 397 | writeRecordingInfo(_buf); |
| 398 | flush(_buf); |
| 399 | |
| 400 | if (_memfd >= 0) { |
| 401 | while (ftruncate(_memfd, 0) < 0 && errno == EINTR); // restart if interrupted |
| 402 | _in_memory = true; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | bool needSwitchChunk(u64 wall_time) { |
| 407 | return loadAcquire(_bytes_written) >= _chunk_size || wall_time - _start_time >= _chunk_time; |