From: Mathieu Desnoyers Date: Sat, 30 Apr 2011 19:58:40 +0000 (-0400) Subject: Move stream pos declaration into CTF header X-Git-Tag: v0.1~121 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=dd2544fde7500d15afb76f588009874cc577f0ac Move stream pos declaration into CTF header Signed-off-by: Mathieu Desnoyers --- diff --git a/include/babeltrace/ctf/metadata.h b/include/babeltrace/ctf/metadata.h index 91987a9b..dea7ef7e 100644 --- a/include/babeltrace/ctf/metadata.h +++ b/include/babeltrace/ctf/metadata.h @@ -20,6 +20,7 @@ */ #include +#include #include #include #include diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h index 73288ef6..c311b532 100644 --- a/include/babeltrace/ctf/types.h +++ b/include/babeltrace/ctf/types.h @@ -23,6 +23,59 @@ #include #include +/* + * Always update stream_pos with move_pos and init_pos. + */ +struct stream_pos { + char *base; /* Base address */ + size_t offset; /* Offset from base, in bits */ + int dummy; /* Dummy position, for length calculation */ +}; + +static inline +void init_pos(struct stream_pos *pos, char *base) +{ + pos->base = base; /* initial base, page-aligned */ + pos->offset = 0; + pos->dummy = false; +} + +/* + * move_pos - move position of a relative bit offset + * + * TODO: allow larger files by updating base too. + */ +static inline +void move_pos(struct stream_pos *pos, size_t offset) +{ + pos->offset = pos->offset + offset; +} + +/* + * align_pos - align position on a bit offset (> 0) + * + * TODO: allow larger files by updating base too. + */ +static inline +void align_pos(struct stream_pos *pos, size_t offset) +{ + pos->offset += offset_align(pos->offset, offset); +} + +static inline +void copy_pos(struct stream_pos *dest, struct stream_pos *src) +{ + memcpy(dest, src, sizeof(struct stream_pos)); +} + +static inline +char *get_pos_addr(struct stream_pos *pos) +{ + /* Only makes sense to get the address after aligning on CHAR_BIT */ + assert(!(pos->offset % CHAR_BIT)); + return pos->base + (pos->offset / CHAR_BIT); +} + /* * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits, * *not* in bytes. diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index 9704efed..3d2b70a4 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -31,59 +31,7 @@ /* Preallocate this many fields for structures */ #define DEFAULT_NR_STRUCT_FIELDS 8 -/* - * Always update stream_pos with move_pos and init_pos. - */ -struct stream_pos { - char *base; /* Base address */ - size_t offset; /* Offset from base, in bits */ - int dummy; /* Dummy position, for length calculation */ -}; - -static inline -void init_pos(struct stream_pos *pos, char *base) -{ - pos->base = base; /* initial base, page-aligned */ - pos->offset = 0; - pos->dummy = false; -} - -/* - * move_pos - move position of a relative bit offset - * - * TODO: allow larger files by updating base too. - */ -static inline -void move_pos(struct stream_pos *pos, size_t offset) -{ - pos->offset = pos->offset + offset; -} - -/* - * align_pos - align position on a bit offset (> 0) - * - * TODO: allow larger files by updating base too. - */ -static inline -void align_pos(struct stream_pos *pos, size_t offset) -{ - pos->offset += offset_align(pos->offset, offset); -} - -static inline -void copy_pos(struct stream_pos *dest, struct stream_pos *src) -{ - memcpy(dest, src, sizeof(struct stream_pos)); -} - -static inline -char *get_pos_addr(struct stream_pos *pos) -{ - /* Only makes sense to get the address after aligning on CHAR_BIT */ - assert(!(pos->offset % CHAR_BIT)); - return pos->base + (pos->offset / CHAR_BIT); -} - +struct stream_pos; struct format; struct definition;