-
Notifications
You must be signed in to change notification settings - Fork 4
/
tpool.h
58 lines (52 loc) · 2.12 KB
/
tpool.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
53
54
55
56
57
58
#ifndef TPOOL_H
#define TPOOL_H
#include <stdint.h>
#include "kqueue.h"
struct tpool_stats {
int active_threads;
int blocked_threads;
uint64_t active_threads_sum;
uint64_t blocked_threads_sum;
int active_threads_samples;
int blocked_threads_samples;
int items_processed;
uint64_t processing_time_sum;
};
struct tpool {
int size;
int new_size;
struct kqueue *q;
int nprocs;
void (*func)(struct kqueue *, struct kitem *);
spin_pdr_lock_t lock;
struct tpool_stats stats;
size_t stacksize;
};
int tpool_init(struct tpool *t, int size, struct kqueue *q,
void (*func)(struct kqueue *, struct kitem *), size_t stacksize);
void tpool_resize(struct tpool *t, int size);
void tpool_wake(struct tpool *t, int count);
void tpool_inform_blocking(struct tpool *t);
void tpool_inform_unblocked(struct tpool *t);
struct tpool_stats tpool_get_stats(struct tpool *t);
int tpool_get_items_processed(struct tpool_stats *prev,
struct tpool_stats *curr);
double tpool_get_average_active_threads(struct tpool_stats *prev,
struct tpool_stats *curr);
double tpool_get_average_blocked_threads(struct tpool_stats *prev,
struct tpool_stats *curr);
double tpool_get_average_processing_time(struct tpool_stats *prev,
struct tpool_stats *curr);
void tpool_print_items_processed(char *prefix,
struct tpool_stats *prev,
struct tpool_stats *curr);
void tpool_print_average_active_threads(char *prefix,
struct tpool_stats *prev,
struct tpool_stats *curr);
void tpool_print_average_blocked_threads(char *prefix,
struct tpool_stats *prev,
struct tpool_stats *curr);
void tpool_print_average_processing_time(char *prefix,
struct tpool_stats *prev,
struct tpool_stats *curr);
#endif // TPOOL_H