Header And Logo

PostgreSQL
| The world's most advanced open source database.

parallel.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * parallel.h
00004  *
00005  *  Parallel support header file for the pg_dump archiver
00006  *
00007  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  *  The author is not responsible for loss or damages that may
00011  *  result from its use.
00012  *
00013  * IDENTIFICATION
00014  *      src/bin/pg_dump/parallel.h
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 
00019 #ifndef PG_DUMP_PARALLEL_H
00020 #define PG_DUMP_PARALLEL_H
00021 
00022 #include "pg_backup_db.h"
00023 
00024 struct _archiveHandle;
00025 struct _tocEntry;
00026 
00027 typedef enum
00028 {
00029     WRKR_TERMINATED = 0,
00030     WRKR_IDLE,
00031     WRKR_WORKING,
00032     WRKR_FINISHED
00033 }   T_WorkerStatus;
00034 
00035 /* Arguments needed for a worker process */
00036 typedef struct ParallelArgs
00037 {
00038     struct _archiveHandle *AH;
00039     struct _tocEntry *te;
00040 }   ParallelArgs;
00041 
00042 /* State for each parallel activity slot */
00043 typedef struct ParallelSlot
00044 {
00045     ParallelArgs *args;
00046     T_WorkerStatus workerStatus;
00047     int         status;
00048     int         pipeRead;
00049     int         pipeWrite;
00050     int         pipeRevRead;
00051     int         pipeRevWrite;
00052 #ifdef WIN32
00053     uintptr_t   hThread;
00054     unsigned int threadId;
00055 #else
00056     pid_t       pid;
00057 #endif
00058 } ParallelSlot;
00059 
00060 #define NO_SLOT (-1)
00061 
00062 typedef struct ParallelState
00063 {
00064     int         numWorkers;
00065     ParallelSlot *parallelSlot;
00066 } ParallelState;
00067 
00068 #ifdef WIN32
00069 extern bool parallel_init_done;
00070 extern DWORD mainThreadId;
00071 #endif
00072 
00073 extern void init_parallel_dump_utils(void);
00074 
00075 extern int  GetIdleWorker(ParallelState *pstate);
00076 extern bool IsEveryWorkerIdle(ParallelState *pstate);
00077 extern void ListenToWorkers(struct _archiveHandle * AH, ParallelState *pstate, bool do_wait);
00078 extern int  ReapWorkerStatus(ParallelState *pstate, int *status);
00079 extern void EnsureIdleWorker(struct _archiveHandle * AH, ParallelState *pstate);
00080 extern void EnsureWorkersFinished(struct _archiveHandle * AH, ParallelState *pstate);
00081 
00082 extern ParallelState *ParallelBackupStart(struct _archiveHandle * AH,
00083                     RestoreOptions *ropt);
00084 extern void DispatchJobForTocEntry(struct _archiveHandle * AH,
00085                        ParallelState *pstate,
00086                        struct _tocEntry * te, T_Action act);
00087 extern void ParallelBackupEnd(struct _archiveHandle * AH, ParallelState *pstate);
00088 
00089 extern void checkAborting(struct _archiveHandle * AH);
00090 
00091 extern void
00092 exit_horribly(const char *modulename, const char *fmt,...)
00093 __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
00094 
00095 #endif   /* PG_DUMP_PARALLEL_H */