-
Notifications
You must be signed in to change notification settings - Fork 2
/
pbgzf.h
150 lines (124 loc) · 3.65 KB
/
pbgzf.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef PBGZF_H_
#define PBGZF_H_
#include <pthread.h>
#include <config.h>
#include "bgzf.h"
#include "block.h"
#include "queue.h"
#include "reader.h"
#include "consumer.h"
#include "writer.h"
#include "util.h"
#define BZ2_DEFAULT_LEVEL 9
typedef struct {
pthread_attr_t attr;
pthread_t *threads;
int32_t n;
consumer_t **c;
} consumers_t;
typedef struct {
pthread_attr_t attr;
pthread_t thread;
reader_t *r;
} producer_t;
typedef struct {
pthread_attr_t attr;
pthread_t thread;
writer_t *w;
} outputter_t;
typedef struct {
block_t *block; // buffer block
block_pool_t *pool;
char open_mode;
int32_t queue_size;
int32_t num_threads;
int32_t block_offset; // for pbgzf_flush_tr
int64_t block_address; // for pbgzf_flush_tr
int32_t eof_ok; // for pbgzf_check_EOF
int32_t eof;
int64_t n_blocks;
queue_t *input;
queue_t *output;
reader_t *r;
writer_t *w;
consumers_t *c;
producer_t *p;
outputter_t *o;
} PBGZF;
#ifdef __cplusplus
extern "C" {
#endif
#define PBGZF_QUEUE_SIZE 100
#define PBGZF_BLOCKS_POOL_NUM 100
//#define PBGZF_USE_LOCAL_POOLS
/*
* Sets the number of consumer threads per file handle. If set to
* X, the numebr of threads will be X+1, due to the need to have a
* single reader or writer thread in addition to the consumer
* thread(s).
*/
void
pbgzf_set_num_threads_per(int32_t n);
/*
* Open an existing file descriptor for reading or writing.
* Mode must be either "r" or "w".
* A subsequent pbgzf_close will not close the file descriptor.
* Returns null on error.
*/
PBGZF* pbgzf_fdopen(int fd, const char* __restrict mode);
/*
* Open the specified file for reading or writing.
* Mode must be either "r" or "w".
* Returns null on error.
*/
PBGZF* pbgzf_open(const char* path, const char* __restrict mode);
/*
* Close the BGZ file and free all associated resources.
* Does not close the underlying file descriptor if created with pbgzf_fdopen.
* Returns zero on success, -1 on error.
*/
int pbgzf_close(PBGZF* fp);
/*
* Read up to length bytes from the file storing into data.
* Returns the number of bytes actually read.
* Returns zero on end of file.
* Returns -1 on error.
*/
int pbgzf_read(PBGZF* fp, void* data, int length);
/*
* Write length bytes from data to the file.
* Returns the number of bytes written.
* Returns -1 on error.
*/
int pbgzf_write(PBGZF* fp, const void* data, int length);
/*
* Return a virtual file pointer to the current location in the file.
* No interpetation of the value should be made, other than a subsequent
* call to pbgzf_seek can be used to position the file at the same point.
* Return value is non-negative on success.
* Returns -1 on error.
*/
int64_t pbgzf_tell(PBGZF *fp);
/*
* Set the file to read from the location specified by pos, which must
* be a value previously returned by pbgzf_tell for this file (but not
* necessarily one returned by this file handle).
* The where argument must be SEEK_SET.
* Seeking on a file opened for write is not supported.
* Returns zero on success, -1 on error.
*/
int64_t pbgzf_seek(PBGZF* fp, int64_t pos, int where);
int pbgzf_check_EOF(PBGZF *fp);
int pbgzf_flush(PBGZF* fp);
int pbgzf_flush_try(PBGZF *fp, int size);
void pbgzf_set_cache_size(PBGZF *fp, int cache_size);
#ifdef __cplusplus
}
#endif
void
#ifdef HAVE_LIBIGZIP0C
pbgzf_main(int f_src, int f_dst, int compress, int compress_level, int compress_type, int queue_size, int num_threads, int uncompressed_block_size, int use_igzip);
#else
pbgzf_main(int f_src, int f_dst, int compress, int compress_level, int compress_type, int queue_size, int num_threads, int uncompressed_block_size);
#endif
#endif