]> granicus.if.org Git - postgresql/commitdiff
Back-patch bgworker API changes to 9.3.
authorRobert Haas <rhaas@postgresql.org>
Mon, 22 Jul 2013 19:41:44 +0000 (15:41 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 22 Jul 2013 19:41:44 +0000 (15:41 -0400)
Commit 7f7485a0cde92aa4ba235a1ffe4dda0ca0b6cc9a made these changes
in master; per discussion, backport the API changes (but not the
functional changes), so that people don't get used to the 9.3 API
only to see it get broken in the next release.  There are already
some people coding to the original 9.3 API, and this will cause
minor breakage, but there will be even more if we wait until next
year to roll out these changes.

contrib/worker_spi/worker_spi.c
doc/src/sgml/bgworker.sgml
src/backend/postmaster/postmaster.c
src/include/postmaster/bgworker.h

index 84ac1b7730b06bc8465862bcf15171883ea46af8..3a75bb3f4eb190f28e28f892e9f212caeb1a752c 100644 (file)
@@ -154,10 +154,17 @@ initialize_worker_spi(worktable *table)
 }
 
 static void
-worker_spi_main(void *main_arg)
+worker_spi_main(Datum main_arg)
 {
-       worktable  *table = (worktable *) main_arg;
+       int                     index = DatumGetInt32(main_arg);
+       worktable  *table;
        StringInfoData buf;
+       char            name[20];
+
+       table = palloc(sizeof(worktable));
+       sprintf(name, "schema%d", index);
+       table->schema = pstrdup(name);
+       table->name = pstrdup("counted");
 
        /* Establish signal handlers before unblocking signals. */
        pqsignal(SIGHUP, worker_spi_sighup);
@@ -296,9 +303,7 @@ void
 _PG_init(void)
 {
        BackgroundWorker worker;
-       worktable  *table;
        unsigned int i;
-       char            name[20];
 
        /* get the configuration */
        DefineCustomIntVariable("worker_spi.naptime",
@@ -338,14 +343,8 @@ _PG_init(void)
         */
        for (i = 1; i <= worker_spi_total_workers; i++)
        {
-               sprintf(name, "worker %d", i);
-               worker.bgw_name = pstrdup(name);
-
-               table = palloc(sizeof(worktable));
-               sprintf(name, "schema%d", i);
-               table->schema = pstrdup(name);
-               table->name = pstrdup("counted");
-               worker.bgw_main_arg = (void *) table;
+               snprintf(worker.bgw_name, BGW_MAXLEN, "worker %d", i);
+               worker.bgw_main_arg = Int32GetDatum(i);
 
                RegisterBackgroundWorker(&worker);
        }
index 7d2ffd14feff031b1bba4ffb385f60e2c731ddf9..7ffeca5321aa9b3ed6f2ce07454075cbefd80ad2 100644 (file)
 typedef void (*bgworker_main_type)(void *main_arg);
 typedef struct BackgroundWorker
 {
-    char       *bgw_name;
+    char        bgw_name[BGW_MAXLEN];
     int         bgw_flags;
     BgWorkerStartTime bgw_start_time;
     int         bgw_restart_time;       /* in seconds, or BGW_NEVER_RESTART */
-    bgworker_main_type  bgw_main;
-    void       *bgw_main_arg;
+    bgworker_main_type bgw_main;
+    Datum       bgw_main_arg;
 } BackgroundWorker;
 </programlisting>
   </para>
index 1e41a0e75ec0ce1320276a46e7b100cf7099d512..f219bd1301345561bf1ebf9d2a84cd3fb30c2be1 100644 (file)
@@ -5247,9 +5247,6 @@ RegisterBackgroundWorker(BackgroundWorker *worker)
        }
 
        rw->rw_worker = *worker;
-       rw->rw_worker.bgw_name = ((char *) rw) + sizeof(RegisteredBgWorker);
-       strlcpy(rw->rw_worker.bgw_name, worker->bgw_name, namelen + 1);
-
        rw->rw_backend = NULL;
        rw->rw_pid = 0;
        rw->rw_child_slot = 0;
index e91e344eb67856854e6773262124a6757f3a93c2..e0f468fab9eeb7128418713db8ea234ebb9cef21 100644 (file)
@@ -52,7 +52,7 @@
 #define BGWORKER_BACKEND_DATABASE_CONNECTION           0x0002
 
 
-typedef void (*bgworker_main_type) (void *main_arg);
+typedef void (*bgworker_main_type) (Datum main_arg);
 
 /*
  * Points in time at which a bgworker can request to be started
@@ -66,15 +66,16 @@ typedef enum
 
 #define BGW_DEFAULT_RESTART_INTERVAL   60
 #define BGW_NEVER_RESTART                              -1
+#define BGW_MAXLEN                                             64
 
 typedef struct BackgroundWorker
 {
-       char       *bgw_name;
+       char        bgw_name[BGW_MAXLEN];
        int                     bgw_flags;
        BgWorkerStartTime bgw_start_time;
        int                     bgw_restart_time;               /* in seconds, or BGW_NEVER_RESTART */
        bgworker_main_type bgw_main;
-       void       *bgw_main_arg;
+       Datum           bgw_main_arg;
 } BackgroundWorker;
 
 /* Register a new bgworker */