- /* Rotate to next file. */
- tfa->file_head = (tfa->file_head + 1) % tfa->count;
- if (tfa->file_head == tfa->file_tail) {
- /* Move tail. */
- tfa->file_tail = (tfa->file_tail + 1) % tfa->count;
- }
- headp = &tfa->tf[tfa->file_head].seq_head;
- tailp = &tfa->tf[tfa->file_head].seq_tail;
- /*
- * If we overwrite a file with content, we need to push the tail
- * to the position following the content we are overwriting.
- */
- if (*headp != -1ULL) {
- tfa->seq_tail = tfa->tf[tfa->file_tail].seq_tail;
+ switch (type) {
+ case TRACEFILE_ROTATE_READ:
+ /*
+ * Rotate read head to write head position, thus allowing
+ * reader to consume the newly rotated head file.
+ */
+ tfa->file_head_read = tfa->file_head_write;
+ break;
+ case TRACEFILE_ROTATE_WRITE:
+ /* Rotate write head to next file, pushing tail if needed. */
+ tfa->file_head_write = (tfa->file_head_write + 1) % tfa->count;
+ if (tfa->file_head_write == tfa->file_tail) {
+ /* Move tail. */
+ tfa->file_tail = (tfa->file_tail + 1) % tfa->count;
+ }
+ headp = &tfa->tf[tfa->file_head_write].seq_head;
+ tailp = &tfa->tf[tfa->file_head_write].seq_tail;
+ /*
+ * If we overwrite a file with content, we need to push the tail
+ * to the position following the content we are overwriting.
+ */
+ if (*headp != -1ULL) {
+ tfa->seq_tail = tfa->tf[tfa->file_tail].seq_tail;
+ }
+ /* Reset this file head/tail (overwrite). */
+ *headp = -1ULL;
+ *tailp = -1ULL;
+ break;
+ default:
+ abort();