27 HANDLE *thread_handles;
43 } transfer_thread_arg;
45 exec_thread_arg **exec_thread_args;
46 transfer_thread_arg **transfer_thread_args;
49 void **cur_thread_args;
51 DWORD win32_exec_prog(exec_thread_arg *
args);
52 DWORD win32_transfer_all_new_dbs(transfer_thread_arg *
args);
72 exec_thread_arg *new_arg;
86 if (thread_handles == NULL)
89 if (exec_thread_args == NULL)
101 exec_thread_args[
i] =
pg_malloc0(
sizeof(exec_thread_arg));
104 cur_thread_args = (
void **) exec_thread_args;
133 if (new_arg->log_file)
136 if (new_arg->opt_log_file)
137 pg_free(new_arg->opt_log_file);
138 new_arg->opt_log_file = opt_log_file ?
pg_strdup(opt_log_file) : NULL;
143 child = (HANDLE) _beginthreadex(NULL, 0, (
void *) win32_exec_prog,
156 win32_exec_prog(exec_thread_arg *
args)
176 char *old_pgdata,
char *new_pgdata,
177 char *old_tablespace)
183 transfer_thread_arg *new_arg;
192 if (thread_handles == NULL)
195 if (transfer_thread_args == NULL)
207 transfer_thread_args[
i] =
pg_malloc0(
sizeof(transfer_thread_arg));
210 cur_thread_args = (
void **) transfer_thread_args;
244 new_arg->old_db_arr = old_db_arr;
245 new_arg->new_db_arr = new_db_arr;
246 if (new_arg->old_pgdata)
248 new_arg->old_pgdata =
pg_strdup(old_pgdata);
249 if (new_arg->new_pgdata)
251 new_arg->new_pgdata =
pg_strdup(new_pgdata);
252 if (new_arg->old_tablespace)
253 pg_free(new_arg->old_tablespace);
254 new_arg->old_tablespace = old_tablespace ?
pg_strdup(old_tablespace) : NULL;
256 child = (HANDLE) _beginthreadex(NULL, 0, (
void *) win32_transfer_all_new_dbs,
269 win32_transfer_all_new_dbs(transfer_thread_arg *
args)
272 args->new_pgdata,
args->old_tablespace);
298 child = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
299 if (child == (pid_t) -1)
303 if (work_status != 0)
304 pg_fatal(
"child process exited abnormally: status %d\n", work_status);
307 thread_num = WaitForMultipleObjects(
parallel_jobs, thread_handles,
308 false, wait_for_child ? INFINITE : 0);
310 if (thread_num == WAIT_TIMEOUT || thread_num == WAIT_FAILED)
314 thread_num -= WAIT_OBJECT_0;
317 GetExitCodeThread(thread_handles[thread_num], &
res);
322 CloseHandle(thread_handles[thread_num]);
329 thread_handles[thread_num] = thread_handles[
parallel_jobs - 1];
337 tmp_args = cur_thread_args[thread_num];
338 cur_thread_args[thread_num] = cur_thread_args[
parallel_jobs - 1];
bool exec_prog(const char *log_filename, const char *opt_log_file, bool report_error, bool exit_on_error, const char *fmt,...)
void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata, char *old_tablespace)
bool reap_child(bool wait_for_child)
void parallel_exec_prog(const char *log_file, const char *opt_log_file, const char *fmt,...)
static void PGresult * res
void * pg_malloc0(size_t size)
char * pg_strdup(const char *in)
void * pg_malloc(size_t size)
static void const char fflush(stdout)
static void const char * fmt
void transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata, char *old_tablespace)