mirror of
https://github.com/vasi/pixz
synced 2024-11-16 21:26:04 +00:00
Allow capping the number of threads
This commit is contained in:
parent
cc4b76cb0b
commit
1799c4e8f1
5
common.c
5
common.c
@ -333,6 +333,8 @@ queue_t *gPipelineStartQ = NULL,
|
|||||||
*gPipelineSplitQ = NULL,
|
*gPipelineSplitQ = NULL,
|
||||||
*gPipelineMergeQ = NULL;
|
*gPipelineMergeQ = NULL;
|
||||||
|
|
||||||
|
size_t gPipelineProcessMax = 0;
|
||||||
|
|
||||||
pipeline_data_free_t gPLFreer = NULL;
|
pipeline_data_free_t gPLFreer = NULL;
|
||||||
pipeline_split_t gPLSplit = NULL;
|
pipeline_split_t gPLSplit = NULL;
|
||||||
pipeline_process_t gPLProcess = NULL;
|
pipeline_process_t gPLProcess = NULL;
|
||||||
@ -367,6 +369,9 @@ void pipeline_create(
|
|||||||
gPLMergedItems = NULL;
|
gPLMergedItems = NULL;
|
||||||
|
|
||||||
gPLProcessCount = num_threads();
|
gPLProcessCount = num_threads();
|
||||||
|
if (gPipelineProcessMax > 0 && gPipelineProcessMax < gPLProcessCount)
|
||||||
|
gPLProcessCount = gPipelineProcessMax;
|
||||||
|
|
||||||
gPLProcessThreads = malloc(gPLProcessCount * sizeof(pthread_t));
|
gPLProcessThreads = malloc(gPLProcessCount * sizeof(pthread_t));
|
||||||
for (size_t i = 0; i < (int)(gPLProcessCount * 2 + 3); ++i) {
|
for (size_t i = 0; i < (int)(gPLProcessCount * 2 + 3); ++i) {
|
||||||
// create blocks, including a margin of error
|
// create blocks, including a margin of error
|
||||||
|
12
pixz.c
12
pixz.c
@ -55,7 +55,9 @@ int main(int argc, char **argv) {
|
|||||||
char *ipath = NULL, *opath = NULL;
|
char *ipath = NULL, *opath = NULL;
|
||||||
|
|
||||||
int ch;
|
int ch;
|
||||||
while ((ch = getopt(argc, argv, "dxli:o:tvh0123456789")) != -1) {
|
char *optend;
|
||||||
|
long optint;
|
||||||
|
while ((ch = getopt(argc, argv, "dxli:o:tvhp:0123456789")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'd': op = OP_READ; break;
|
case 'd': op = OP_READ; break;
|
||||||
case 'x': op = OP_EXTRACT; break;
|
case 'x': op = OP_EXTRACT; break;
|
||||||
@ -63,7 +65,13 @@ int main(int argc, char **argv) {
|
|||||||
case 'i': ipath = optarg; break;
|
case 'i': ipath = optarg; break;
|
||||||
case 'o': opath = optarg; break;
|
case 'o': opath = optarg; break;
|
||||||
case 't': tar = false; break;
|
case 't': tar = false; break;
|
||||||
case 'h': usage(NULL);
|
case 'h': usage(NULL); break;
|
||||||
|
case 'p':
|
||||||
|
optint = strtol(optarg, &optend, 10);
|
||||||
|
if (optint < 0 || *optend)
|
||||||
|
usage("Need a non-negative integer argument to -p");
|
||||||
|
gPipelineProcessMax = optint;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
level = ch - '0';
|
level = ch - '0';
|
||||||
|
1
pixz.h
1
pixz.h
@ -106,6 +106,7 @@ int queue_pop(queue_t *q, void **datap);
|
|||||||
|
|
||||||
#pragma mark PIPELINE
|
#pragma mark PIPELINE
|
||||||
|
|
||||||
|
extern size_t gPipelineProcessMax;
|
||||||
extern queue_t *gPipelineStartQ, *gPipelineSplitQ, *gPipelineMergeQ;
|
extern queue_t *gPipelineStartQ, *gPipelineSplitQ, *gPipelineMergeQ;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
Loading…
Reference in New Issue
Block a user