Commit | Line | Data |
---|---|---|
a44ca2ca MD |
1 | #ifndef _TRACEFILE_ARRAY_H |
2 | #define _TRACEFILE_ARRAY_H | |
3 | ||
4 | /* | |
5 | * Copyright (C) 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License, version 2 only, as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | * more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along with | |
17 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 | */ | |
20 | ||
21 | #include <limits.h> | |
22 | #include <inttypes.h> | |
23 | #include <pthread.h> | |
24 | #include <stdbool.h> | |
25 | ||
26 | struct tracefile { | |
27 | /* Per-tracefile head/tail seq. */ | |
28 | uint64_t seq_head; /* Newest seqcount. Inclusive. */ | |
29 | uint64_t seq_tail; /* Oldest seqcount. Inclusive. */ | |
30 | }; | |
31 | ||
32 | /* | |
33 | * Represents an array of trace files in a stream. | |
34 | */ | |
35 | struct tracefile_array { | |
36 | struct tracefile *tf; | |
37 | size_t count; | |
38 | ||
39 | /* Current head/tail files. */ | |
40 | uint64_t file_head; | |
41 | uint64_t file_tail; | |
42 | ||
43 | /* Overall head/tail seq for the entire array. Inclusive. */ | |
44 | uint64_t seq_head; | |
45 | uint64_t seq_tail; | |
46 | }; | |
47 | ||
48 | struct tracefile_array *tracefile_array_create(size_t count); | |
49 | void tracefile_array_destroy(struct tracefile_array *tfa); | |
50 | ||
51 | void tracefile_array_file_rotate(struct tracefile_array *tfa); | |
52 | void tracefile_array_commit_seq(struct tracefile_array *tfa); | |
53 | ||
54 | uint64_t tracefile_array_get_file_index_head(struct tracefile_array *tfa); | |
55 | /* May return -1ULL in the case where we have not received any indexes yet. */ | |
56 | uint64_t tracefile_array_get_seq_head(struct tracefile_array *tfa); | |
57 | ||
58 | uint64_t tracefile_array_get_file_index_tail(struct tracefile_array *tfa); | |
59 | /* May return -1ULL in the case where we have not received any indexes yet. */ | |
60 | uint64_t tracefile_array_get_seq_tail(struct tracefile_array *tfa); | |
61 | ||
62 | bool tracefile_array_seq_in_file(struct tracefile_array *tfa, | |
63 | uint64_t file_index, uint64_t seq); | |
64 | ||
65 | #endif /* _STREAM_H */ |