-
Notifications
You must be signed in to change notification settings - Fork 1
/
athr.h
52 lines (42 loc) · 1.47 KB
/
athr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef ATHR_H
#define ATHR_H
#include "athr_ema.h"
#include "athr_option.h"
#include "athr_thread.h"
#include "athr_widget_main.h"
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
/* How often to update initially, in milliseconds. */
#define ATHR_TIMESTEP 250
/* Limit on how long to update, in milliseconds. */
#define ATHR_TIMESTEP_LIMIT 750
struct athr_elapsed;
struct athr
{
unsigned timestep;
uint64_t total;
atomic_uint_fast64_t consumed;
uint_fast64_t last_consumed;
struct athr_ema speed;
struct athr_elapsed *elapsed;
struct athr_elapsed *total_elapsed;
enum athr_option opts;
struct athr_widget_main main;
atomic_bool stop;
atomic_flag lock;
struct athr_thread thr;
};
#define ATHR_INIT \
(struct athr) \
{ \
ATHR_TIMESTEP, 0, 0, 0, ATHR_EMA_INIT, NULL, NULL, ATHR_BAR, \
ATHR_WIDGET_MAIN_INIT, false, ATOMIC_FLAG_INIT, ATHR_THR_INIT \
}
int athr_start(struct athr *, uint64_t total, char const *desc, enum athr_option opts);
void athr_eat(struct athr *, uint64_t amount);
void athr_stop(struct athr *);
void athr_disable_threading(bool disable);
int athr_sleep(unsigned milliseconds);
void athr_stop_wait(struct athr *at);
#endif