Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit026bc46

Browse files
committed
Back-patch bgworker API changes to 9.3.
Commit7f7485a made these changesin master; per discussion, backport the API changes (but not thefunctional changes), so that people don't get used to the 9.3 APIonly to see it get broken in the next release. There are alreadysome people coding to the original 9.3 API, and this will causeminor breakage, but there will be even more if we wait until nextyear to roll out these changes.
1 parent295f9bb commit026bc46

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

‎contrib/worker_spi/worker_spi.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,17 @@ initialize_worker_spi(worktable *table)
154154
}
155155

156156
staticvoid
157-
worker_spi_main(void*main_arg)
157+
worker_spi_main(Datummain_arg)
158158
{
159-
worktable*table= (worktable*)main_arg;
159+
intindex=DatumGetInt32(main_arg);
160+
worktable*table;
160161
StringInfoDatabuf;
162+
charname[20];
163+
164+
table=palloc(sizeof(worktable));
165+
sprintf(name,"schema%d",index);
166+
table->schema=pstrdup(name);
167+
table->name=pstrdup("counted");
161168

162169
/* Establish signal handlers before unblocking signals. */
163170
pqsignal(SIGHUP,worker_spi_sighup);
@@ -296,9 +303,7 @@ void
296303
_PG_init(void)
297304
{
298305
BackgroundWorkerworker;
299-
worktable*table;
300306
unsignedinti;
301-
charname[20];
302307

303308
/* get the configuration */
304309
DefineCustomIntVariable("worker_spi.naptime",
@@ -338,14 +343,8 @@ _PG_init(void)
338343
*/
339344
for (i=1;i <=worker_spi_total_workers;i++)
340345
{
341-
sprintf(name,"worker %d",i);
342-
worker.bgw_name=pstrdup(name);
343-
344-
table=palloc(sizeof(worktable));
345-
sprintf(name,"schema%d",i);
346-
table->schema=pstrdup(name);
347-
table->name=pstrdup("counted");
348-
worker.bgw_main_arg= (void*)table;
346+
snprintf(worker.bgw_name,BGW_MAXLEN,"worker %d",i);
347+
worker.bgw_main_arg=Int32GetDatum(i);
349348

350349
RegisterBackgroundWorker(&worker);
351350
}

‎doc/src/sgml/bgworker.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
typedef void (*bgworker_main_type)(void *main_arg);
4141
typedef struct BackgroundWorker
4242
{
43-
char*bgw_name;
43+
charbgw_name[BGW_MAXLEN];
4444
int bgw_flags;
4545
BgWorkerStartTime bgw_start_time;
4646
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
47-
bgworker_main_typebgw_main;
48-
void*bgw_main_arg;
47+
bgworker_main_type bgw_main;
48+
Datum bgw_main_arg;
4949
} BackgroundWorker;
5050
</programlisting>
5151
</para>

‎src/backend/postmaster/postmaster.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5247,9 +5247,6 @@ RegisterBackgroundWorker(BackgroundWorker *worker)
52475247
}
52485248

52495249
rw->rw_worker=*worker;
5250-
rw->rw_worker.bgw_name= ((char*)rw)+sizeof(RegisteredBgWorker);
5251-
strlcpy(rw->rw_worker.bgw_name,worker->bgw_name,namelen+1);
5252-
52535250
rw->rw_backend=NULL;
52545251
rw->rw_pid=0;
52555252
rw->rw_child_slot=0;

‎src/include/postmaster/bgworker.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#defineBGWORKER_BACKEND_DATABASE_CONNECTION0x0002
5353

5454

55-
typedefvoid (*bgworker_main_type) (void*main_arg);
55+
typedefvoid (*bgworker_main_type) (Datummain_arg);
5656

5757
/*
5858
* Points in time at which a bgworker can request to be started
@@ -66,15 +66,16 @@ typedef enum
6666

6767
#defineBGW_DEFAULT_RESTART_INTERVAL60
6868
#defineBGW_NEVER_RESTART-1
69+
#defineBGW_MAXLEN64
6970

7071
typedefstructBackgroundWorker
7172
{
72-
char*bgw_name;
73+
charbgw_name[BGW_MAXLEN];
7374
intbgw_flags;
7475
BgWorkerStartTimebgw_start_time;
7576
intbgw_restart_time;/* in seconds, or BGW_NEVER_RESTART */
7677
bgworker_main_typebgw_main;
77-
void*bgw_main_arg;
78+
Datumbgw_main_arg;
7879
}BackgroundWorker;
7980

8081
/* Register a new bgworker */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp