summaryrefslogtreecommitdiffstats
path: root/src/ctx.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2025-02-27 11:54:49 -0500
committerTavian Barnes <tavianator@tavianator.com>2025-02-27 11:54:49 -0500
commit5798978f77ef8c3efb3c99fa7fb9538c5c597024 (patch)
tree32d3fbcff0910b4c17a7b4b6048d2e0631d2abfe /src/ctx.c
parenta561d782265c2157f270f0ead6b88db24e433d92 (diff)
downloadbfs-5798978f77ef8c3efb3c99fa7fb9538c5c597024.tar.xz
bfstd: New nproc() function
Diffstat (limited to 'src/ctx.c')
-rw-r--r--src/ctx.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/ctx.c b/src/ctx.c
index 2c55a35..d92d8ba 100644
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -24,20 +24,6 @@
#include <time.h>
#include <unistd.h>
-/** Get the initial value for ctx->threads (-j). */
-static int bfs_nproc(void) {
- long nproc = xsysconf(_SC_NPROCESSORS_ONLN);
-
- if (nproc < 1) {
- nproc = 1;
- } else if (nproc > 8) {
- // Not much speedup after 8 threads
- nproc = 8;
- }
-
- return nproc;
-}
-
struct bfs_ctx *bfs_ctx_new(void) {
struct bfs_ctx *ctx = ZALLOC(struct bfs_ctx);
if (!ctx) {
@@ -50,9 +36,14 @@ struct bfs_ctx *bfs_ctx_new(void) {
ctx->maxdepth = INT_MAX;
ctx->flags = BFTW_RECOVER;
ctx->strategy = BFTW_BFS;
- ctx->threads = bfs_nproc();
ctx->optlevel = 3;
+ ctx->threads = nproc();
+ if (ctx->threads > 8) {
+ // Not much speedup after 8 threads
+ ctx->threads = 8;
+ }
+
trie_init(&ctx->files);
ctx->umask = umask(0);