6 typedef u_int32_t fsample_t
;
8 typedef struct fsample fsample
;
10 /* nice loss of type safety here... */
11 typedef void *(*CoreHandlerAddFn
)(void *handler
, void *arg
);
12 typedef void (*CoreHandlerDelFn
)(void *);
14 /* single sample functions */
15 fsample
*fsopen(char *filename
, size_t samples
, CoreHandlerAddFn chafn
, CoreHandlerDelFn chdfn
);
16 void fsclose(fsample
*f
);
19 typedef fsample_t (*DeriveValueFn
)(struct fsample_m
*v
, int entry
, fsample_t pos
, void *tag
);
21 typedef struct fsample_m_entry
{
28 typedef struct fsample_m
{
30 CoreHandlerAddFn chafn
;
31 CoreHandlerDelFn chdfn
;
32 struct fsample_m_entry entry
[];
35 /* multiple sample functions */
36 fsample_m
*fsopen_m(size_t count
, char *filename
, size_t samples
, CoreHandlerAddFn chafn
, CoreHandlerDelFn chdfn
);
37 void fsclose_m(fsample_m
*f
);
38 int fsadd_m(fsample_m
*f
, char *filename
, size_t freq
, DeriveValueFn derive
, void *tag
);
39 void fsset_m(fsample_m
*f
, fsample_t pos
, fsample_t value
);
42 fsample_t
fsamean(fsample_m
*f
, int entry
, fsample_t pos
, void *tag
);
43 fsample_t
fsapmean(fsample_m
*f
, int entry
, fsample_t pos
, void *tag
);
47 unsigned char iteration
;
50 struct fsample_header
{
53 unsigned char iteration
;
61 struct fsample_header
*header
;
63 CoreHandlerDelFn corehandlerdel
;
66 static inline unsigned char previteration(fsample
*f
) {
67 unsigned char p
= f
->header
->iteration
- 1;
73 /* doesn't support writing to negative numbers... */
74 static inline void fsset(fsample
*f
, fsample_t pos
, fsample_t value
) {
75 fsample_t actualpos
= pos
% f
->samples
;
76 struct fsample_p
*p
= &f
->m
[actualpos
];
78 if(f
->header
->lastpos
> actualpos
) {
79 f
->header
->iteration
++;
80 if(f
->header
->iteration
== 0)
81 f
->header
->iteration
= 1;
84 f
->header
->lastpos
= actualpos
;
86 p
->iteration
= f
->header
->iteration
;
90 static inline fsample_t
mmod(int x
, int y
) {
97 #error Unknown modulo operator function.
101 /* API functions only have access to positive indicies */
102 static inline fsample_t
__fsget(fsample
*f
, int pos
, fsample_t
*t
) {
103 struct fsample_p
*p
= &f
->m
[mmod(pos
, f
->samples
)];
105 if(p
->iteration
!= f
->header
->iteration
) {
106 unsigned char prev
= previteration(f
);
108 if(prev
!= p
->iteration
|| (pos
<= f
->header
->lastpos
)) {
109 /*printf("bad: prev: %d p->iteration: %d, pos: %d lastpos: %d\n", prev, p->iteration, pos, f->header->lastpos);*/
118 static inline fsample_t
fsget_r(fsample
*f
, fsample_t pos
, fsample_t
*t
) {
119 struct fsample_p
*p
= &f
->m
[mmod(pos
, f
->samples
)];
125 static inline fsample_t
fsget(fsample
*f
, fsample_t pos
, fsample_t
*t
) {
126 return __fsget(f
, pos
, t
);
129 static inline fsample_t
__fsget_m(fsample_m
*f
, int entry
, int pos
, fsample_t
*t
) {
130 return __fsget(f
->entry
[entry
].f
, pos
/ f
->entry
[entry
].freq
, t
);
133 static inline fsample_t
fsget_m(fsample_m
*f
, int entry
, fsample_t pos
, fsample_t
*t
) {
134 return fsget(f
->entry
[entry
].f
, pos
/ f
->entry
[entry
].freq
, t
);
137 static inline fsample_t
fsget_mr(fsample_m
*f
, int entry
, fsample_t pos
, fsample_t
*t
) {
138 return fsget_r(f
->entry
[entry
].f
, pos
/ f
->entry
[entry
].freq
, t
);