From acd258077795a2f1fd9104893d81552a3db4f012 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 3 Nov 2016 00:57:43 +0100 Subject: [PATCH] btrfs-progs: image: use fixed-size array for worker thread pointers No need to dynamically allocate the thread pointers. Signed-off-by: David Sterba --- btrfs-image.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/btrfs-image.c b/btrfs-image.c index 3f40301..e54e3fc 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -99,7 +99,7 @@ struct metadump_struct { struct meta_cluster *cluster; - pthread_t *threads; + pthread_t threads[MAX_WORKER_THREADS]; size_t num_threads; pthread_mutex_t mutex; pthread_cond_t cond; @@ -132,7 +132,7 @@ struct mdrestore_struct { FILE *in; FILE *out; - pthread_t *threads; + pthread_t threads[MAX_WORKER_THREADS]; size_t num_threads; pthread_mutex_t mutex; pthread_cond_t cond; @@ -738,7 +738,6 @@ static void metadump_destroy(struct metadump_struct *md, int num_threads) free(name->sub); free(name); } - free(md->threads); free(md->cluster); } @@ -752,11 +751,6 @@ static int metadump_init(struct metadump_struct *md, struct btrfs_root *root, md->cluster = calloc(1, BLOCK_SIZE); if (!md->cluster) return -ENOMEM; - md->threads = calloc(num_threads, sizeof(pthread_t)); - if (!md->threads) { - free(md->cluster); - return -ENOMEM; - } INIT_LIST_HEAD(&md->list); INIT_LIST_HEAD(&md->ordered); md->root = root; @@ -1841,7 +1835,6 @@ static void mdrestore_destroy(struct mdrestore_struct *mdres, int num_threads) pthread_cond_destroy(&mdres->cond); pthread_mutex_destroy(&mdres->mutex); - free(mdres->threads); } static int mdrestore_init(struct mdrestore_struct *mdres, @@ -1871,11 +1864,8 @@ static int mdrestore_init(struct mdrestore_struct *mdres, return 0; mdres->num_threads = num_threads; - mdres->threads = calloc(num_threads, sizeof(pthread_t)); - if (!mdres->threads) - return -ENOMEM; for (i = 0; i < num_threads; i++) { - ret = pthread_create(mdres->threads + i, NULL, restore_worker, + ret = pthread_create(&mdres->threads[i], NULL, restore_worker, mdres); if (ret) { /* pthread_create returns errno directly */ -- 2.7.4