-
Notifications
You must be signed in to change notification settings - Fork 2
/
block.h
52 lines (40 loc) · 949 Bytes
/
block.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 BLOCK_H_
#define BLOCK_H_
typedef struct {
int8_t *buffer;
int32_t block_length;
int32_t block_offset; // used by bgzf_write and bgzf_flush
int64_t block_address; // used by bgzf_write and bgzf_flush
int64_t id; // Used by the queue
int32_t mem;
} block_t;
block_t*
block_init();
void
block_destroy(block_t *block);
typedef struct {
int32_t head;
int32_t n;
int32_t m;
block_t **blocks;
pthread_mutex_t *mut;
} block_pool_t;
// pool is full, with mutex
block_pool_t*
block_pool_init(int32_t m);
// no blocks in the pool, no mutex
block_pool_t*
block_pool_init2(int32_t m);
// add to the end of the queue
int32_t
block_pool_add(block_pool_t *pool, block_t *block);
// get from the front of the queue
block_t*
block_pool_get(block_pool_t *pool);
block_t*
block_pool_peek(block_pool_t *pool);
void
block_pool_destroy(block_pool_t *pool);
void
block_pool_reset(block_pool_t *pool);
#endif