Get rid of all global variables
This commit is contained in:
17
src/timer.c
17
src/timer.c
@@ -5,13 +5,13 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "block.h"
|
||||
#include "main.h"
|
||||
#include "util.h"
|
||||
|
||||
static unsigned int compute_tick(void) {
|
||||
static unsigned int compute_tick(const block *const blocks,
|
||||
const unsigned short block_count) {
|
||||
unsigned int tick = 0;
|
||||
|
||||
for (unsigned short i = 0; i < LEN(blocks); ++i) {
|
||||
for (unsigned short i = 0; i < block_count; ++i) {
|
||||
const block *const block = &blocks[i];
|
||||
tick = gcd(block->interval, tick);
|
||||
}
|
||||
@@ -19,10 +19,11 @@ static unsigned int compute_tick(void) {
|
||||
return tick;
|
||||
}
|
||||
|
||||
static unsigned int compute_reset_value(void) {
|
||||
static unsigned int compute_reset_value(const block *const blocks,
|
||||
const unsigned short block_count) {
|
||||
unsigned int reset_value = 1;
|
||||
|
||||
for (unsigned short i = 0; i < LEN(blocks); ++i) {
|
||||
for (unsigned short i = 0; i < block_count; ++i) {
|
||||
const block *const block = &blocks[i];
|
||||
reset_value = MAX(block->interval, reset_value);
|
||||
}
|
||||
@@ -30,11 +31,11 @@ static unsigned int compute_reset_value(void) {
|
||||
return reset_value;
|
||||
}
|
||||
|
||||
timer timer_new(void) {
|
||||
timer timer_new(const block *const blocks, const unsigned short block_count) {
|
||||
timer timer = {
|
||||
.time = 0,
|
||||
.tick = compute_tick(),
|
||||
.reset_value = compute_reset_value(),
|
||||
.tick = compute_tick(blocks, block_count),
|
||||
.reset_value = compute_reset_value(blocks, block_count),
|
||||
};
|
||||
|
||||
return timer;
|
||||
|
||||
Reference in New Issue
Block a user