20
20
#include "port/pthread-win32.h"
21
21
#endif
22
22
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
+
23
33
static void pgBackupValidateFiles (void * arg );
24
34
static void do_validate_instance (void );
25
35
@@ -41,8 +51,9 @@ pgBackupValidate(pgBackup *backup)
41
51
char path [MAXPGPATH ];
42
52
parray * files ;
43
53
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 ;
46
57
int i ;
47
58
48
59
if (backup -> status != BACKUP_STATUS_OK &&
@@ -71,25 +82,31 @@ pgBackupValidate(pgBackup *backup)
71
82
pg_atomic_clear_flag (& file -> lock );
72
83
}
73
84
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
+
74
89
/* Validate files */
75
90
for (i = 0 ; i < num_threads ; i ++ )
76
91
{
77
- validate_files_args * arg = pg_malloc ( sizeof ( validate_files_args ) );
92
+ validate_files_args * arg = & ( validate_threads_args [ i ] );
78
93
arg -> files = files ;
79
94
arg -> corrupted = false;
80
- validate_threads_args [i ] = arg ;
81
95
pthread_create (& validate_threads [i ], NULL , (void * (* )(void * )) pgBackupValidateFiles , arg );
82
96
}
83
97
84
98
/* Wait theads */
85
99
for (i = 0 ; i < num_threads ; i ++ )
86
100
{
101
+ validate_files_args * arg = & (validate_threads_args [i ]);
87
102
pthread_join (validate_threads [i ], NULL );
88
- if (validate_threads_args [ i ] -> corrupted )
103
+ if (arg -> corrupted )
89
104
corrupted = true;
90
- pg_free (validate_threads_args [i ]);
91
105
}
92
106
107
+ pfree (validate_threads );
108
+ pfree (validate_threads_args );
109
+
93
110
/* cleanup */
94
111
parray_walk (files , pgFileFree );
95
112
parray_free (files );
0 commit comments