Skip to content

Commit 14fa954

Browse files
committed
use dynamically allocated array for validate_threads
1 parent 79ece89 commit 14fa954

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/validate.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
#include "port/pthread-win32.h"
2121
#endif
2222

23+
#ifdef WIN32
24+
typedef struct win32_pthread *pthread_t;
25+
typedef int pthread_attr_t;
26+
#define PTHREAD_MUTEX_INITIALIZER NULL //{ NULL, 0 }
27+
#define PTHREAD_ONCE_INIT false
28+
29+
int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
30+
int pthread_join(pthread_t th, void **thread_return);
31+
#endif
32+
2333
static void pgBackupValidateFiles(void *arg);
2434
static void do_validate_instance(void);
2535

@@ -41,8 +51,9 @@ pgBackupValidate(pgBackup *backup)
4151
char path[MAXPGPATH];
4252
parray *files;
4353
bool corrupted = false;
44-
pthread_t validate_threads[num_threads];
45-
validate_files_args *validate_threads_args[num_threads];
54+
/* arrays with meta info for multi threaded validate */
55+
pthread_t *validate_threads;
56+
validate_files_args *validate_threads_args;
4657
int i;
4758

4859
if (backup->status != BACKUP_STATUS_OK &&
@@ -71,25 +82,31 @@ pgBackupValidate(pgBackup *backup)
7182
pg_atomic_clear_flag(&file->lock);
7283
}
7384

85+
/* init thread args with own file lists */
86+
validate_threads = (pthread_t *) palloc(sizeof(pthread_t)*num_threads);
87+
validate_threads_args = (validate_files_args *) palloc(sizeof(validate_files_args)*num_threads);
88+
7489
/* Validate files */
7590
for (i = 0; i < num_threads; i++)
7691
{
77-
validate_files_args *arg = pg_malloc(sizeof(validate_files_args));
92+
validate_files_args *arg = &(validate_threads_args[i]);
7893
arg->files = files;
7994
arg->corrupted = false;
80-
validate_threads_args[i] = arg;
8195
pthread_create(&validate_threads[i], NULL, (void *(*)(void *)) pgBackupValidateFiles, arg);
8296
}
8397

8498
/* Wait theads */
8599
for (i = 0; i < num_threads; i++)
86100
{
101+
validate_files_args *arg = &(validate_threads_args[i]);
87102
pthread_join(validate_threads[i], NULL);
88-
if (validate_threads_args[i]->corrupted)
103+
if (arg->corrupted)
89104
corrupted = true;
90-
pg_free(validate_threads_args[i]);
91105
}
92106

107+
pfree(validate_threads);
108+
pfree(validate_threads_args);
109+
93110
/* cleanup */
94111
parray_walk(files, pgFileFree);
95112
parray_free(files);

0 commit comments

Comments
 (0)