diff options
author | David Sterba <dsterba@suse.com> | 2016-11-03 00:57:43 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-11-09 13:47:31 +0100 |
commit | acd258077795a2f1fd9104893d81552a3db4f012 (patch) | |
tree | ae49f14c96fd5e1ddd7745f49182cdf10dc8f50e /btrfs-image.c | |
parent | 84f9e8cfe34f7df196e5aa147e2b9ae45bc3b4f3 (diff) |
btrfs-progs: image: use fixed-size array for worker thread pointers
No need to dynamically allocate the thread pointers.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'btrfs-image.c')
-rw-r--r-- | btrfs-image.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/btrfs-image.c b/btrfs-image.c index 3f403015..e54e3fc8 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 */ |