38 lines
957 B
C
38 lines
957 B
C
#pragma once
|
|
|
|
#include <time.h>
|
|
#include <stddef.h>
|
|
#include <assert.h>
|
|
|
|
enum timer_status {
|
|
TIMER_STOPPED,
|
|
TIMER_RUNNING,
|
|
};
|
|
|
|
struct stopwatch_time {
|
|
int integer_value;
|
|
int integer_digits;
|
|
int fraction_value;
|
|
int fraction_digits;
|
|
};
|
|
|
|
struct running_counter {
|
|
struct timespec start; // (absolute)
|
|
struct timespec offset; // (relative)
|
|
};
|
|
|
|
struct timer_state {
|
|
struct running_counter counter;
|
|
struct stopwatch_time time;
|
|
enum timer_status status;
|
|
int _pad;
|
|
};
|
|
|
|
static_assert((sizeof (struct running_counter)) == (8 * 2) * 2);
|
|
static_assert((sizeof (struct stopwatch_time)) == 4 * 4);
|
|
static_assert((sizeof (enum timer_status)) == 4);
|
|
static_assert((sizeof (struct timer_state)) == ((8 * 2) * 2) + (4 * 4) + 4 + 4);
|
|
static_assert((offsetof (struct timer_state, counter)) == 0);
|
|
static_assert((offsetof (struct timer_state, time )) == (8 * 2) * 2);
|
|
static_assert((offsetof (struct timer_state, status )) == ((8 * 2) * 2) + (4 * 4));
|