2
0
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:
Dave Vasilevsky 2012-10-14 01:59:35 -04:00
parent cc4b76cb0b
commit 1799c4e8f1
3 changed files with 16 additions and 2 deletions

View File

@ -333,6 +333,8 @@ queue_t *gPipelineStartQ = NULL,
*gPipelineSplitQ = NULL,
*gPipelineMergeQ = NULL;
size_t gPipelineProcessMax = 0;
pipeline_data_free_t gPLFreer = NULL;
pipeline_split_t gPLSplit = NULL;
pipeline_process_t gPLProcess = NULL;
@ -367,6 +369,9 @@ void pipeline_create(
gPLMergedItems = NULL;
gPLProcessCount = num_threads();
if (gPipelineProcessMax > 0 && gPipelineProcessMax < gPLProcessCount)
gPLProcessCount = gPipelineProcessMax;
gPLProcessThreads = malloc(gPLProcessCount * sizeof(pthread_t));
for (size_t i = 0; i < (int)(gPLProcessCount * 2 + 3); ++i) {
// create blocks, including a margin of error

12
pixz.c
View File

@ -55,7 +55,9 @@ int main(int argc, char **argv) {
char *ipath = NULL, *opath = NULL;
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) {
case 'd': op = OP_READ; break;
case 'x': op = OP_EXTRACT; break;
@ -63,7 +65,13 @@ int main(int argc, char **argv) {
case 'i': ipath = optarg; break;
case 'o': opath = optarg; 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:
if (ch >= '0' && ch <= '9') {
level = ch - '0';

1
pixz.h
View File

@ -106,6 +106,7 @@ int queue_pop(queue_t *q, void **datap);
#pragma mark PIPELINE
extern size_t gPipelineProcessMax;
extern queue_t *gPipelineStartQ, *gPipelineSplitQ, *gPipelineMergeQ;
typedef enum {