MCPcopy Create free account
hub / github.com/F-Stack/f-stack / main

Function main

freebsd/contrib/zstd/examples/streaming_compression_thread_pool.c:127–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127int main(int argc, const char** argv)
128{
129 const char* const exeName = argv[0];
130
131 if (argc<=3) {
132 printf("wrong arguments\n");
133 printf("usage:\n");
134 printf("%s POOL_SIZE LEVEL FILES\n", exeName);
135 return 1;
136 }
137
138 int pool_size = atoi (argv[1]);
139 CHECK(pool_size != 0, "can't parse POOL_SIZE!");
140
141 int level = atoi (argv[2]);
142 CHECK(level != 0, "can't parse LEVEL!");
143
144 argc -= 3;
145 argv += 3;
146
147#if defined(ZSTD_STATIC_LINKING_ONLY)
148 ZSTD_threadPool *pool = ZSTD_createThreadPool (pool_size);
149 CHECK(pool != NULL, "ZSTD_createThreadPool() failed!");
150 fprintf (stderr, "Using shared thread pool of size %d\n", pool_size);
151#else
152 fprintf (stderr, "All threads use its own thread pool\n");
153#endif
154
155 pthread_t *threads = malloc_orDie(argc * sizeof(pthread_t));
156 compress_args_t *args = malloc_orDie(argc * sizeof(compress_args_t));
157
158 for (unsigned i = 0; i < argc; i++)
159 {
160 args[i].fname = argv[i];
161 args[i].outName = createOutFilename_orDie(args[i].fname);
162 args[i].cLevel = level;
163#if defined(ZSTD_STATIC_LINKING_ONLY)
164 args[i].pool = pool;
165#endif
166
167 pthread_create (&threads[i], NULL, compressFile_orDie, &args[i]);
168 }
169
170 for (unsigned i = 0; i < argc; i++)
171 pthread_join (threads[i], NULL);
172
173#if defined(ZSTD_STATIC_LINKING_ONLY)
174 ZSTD_freeThreadPool (pool);
175#endif
176
177 return 0;
178}

Callers

nothing calls this directly

Calls 6

ZSTD_createThreadPoolFunction · 0.85
malloc_orDieFunction · 0.85
ZSTD_freeThreadPoolFunction · 0.85
createOutFilename_orDieFunction · 0.70
printfFunction · 0.50
pthread_createFunction · 0.50

Tested by

no test coverage detected