| 1 | #include "tracer.h" |
| 2 | #include "ustd.h" |
| 3 | #include "localerr.h" |
| 4 | |
| 5 | #define USTD_BUFFER_TRUNC(offset, bufinfo) \ |
| 6 | ((offset) & (~(((bufinfo)->subbuf_size*(bufinfo)->n_subbufs)-1))) |
| 7 | |
| 8 | void finish_consuming_dead_subbuffer(struct buffer_info *buf) |
| 9 | { |
| 10 | struct ltt_channel_buf_struct *ltt_buf = buf->bufstruct_mem; |
| 11 | |
| 12 | long write_offset = local_read(<t_buf->offset); |
| 13 | long consumed_offset = atomic_long_read(<t_buf->consumed); |
| 14 | |
| 15 | long i_subbuf; |
| 16 | |
| 17 | DBG("processing died buffer"); |
| 18 | DBG("consumed offset is %ld", consumed_offset); |
| 19 | DBG("write offset is %ld", write_offset); |
| 20 | |
| 21 | long first_subbuf = write_offset / buf->subbuf_size; |
| 22 | long last_subbuf = consumed_offset / buf->subbuf_size; |
| 23 | |
| 24 | if(last_subbuf - first_subbuf > buf->n_subbufs) { |
| 25 | DBG("an overflow has occurred, nothing can be recovered"); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | for(i_subbuf=first_subbuf; ; i_subbuf++, i_subbuf %= buf->n_subbufs) { |
| 30 | long commit_count = local_read(<t_buf->commit_count[i_subbuf]); |
| 31 | |
| 32 | unsigned long valid_length = buf->subbuf_size; |
| 33 | long n_subbufs_order = get_count_order(buf->n_subbufs); |
| 34 | long commit_count_mask = (~0UL >> n_subbufs_order); |
| 35 | |
| 36 | /* check if subbuf was fully written */ |
| 37 | if (((commit_count - buf->subbuf_size) & commit_count_mask) |
| 38 | - (USTD_BUFFER_TRUNC(consumed_offset, buf) >> n_subbufs_order) |
| 39 | != 0) { |
| 40 | struct ltt_subbuffer_header *header = (struct ltt_subbuffer_header *)((char *)buf->mem)+i_subbuf*buf->subbuf_size; |
| 41 | valid_length = buf->subbuf_size - header->lost_size; |
| 42 | } |
| 43 | |
| 44 | patient_write(buf->file_fd, buf->mem + i_subbuf * buf->subbuf_size, buf->subbuf_size); |
| 45 | |
| 46 | if(i_subbuf == last_subbuf) |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | |