Skip to content

Commit 18d82d0

Browse files
committed
Native shared memory implementation for win32.
Uses same underlying tech as before, but not the sysv emulation layer.
1 parent 3b765db commit 18d82d0

File tree

7 files changed

+310
-151
lines changed

7 files changed

+310
-151
lines changed

configure

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22278,13 +22278,21 @@ fi
2227822278

2227922279

2228022280
# Select shared-memory implementation type.
22281+
if test "$PORTNAME" != "win32"; then
2228122282

2228222283
cat >>confdefs.h <<\_ACEOF
2228322284
#define USE_SYSV_SHARED_MEMORY 1
2228422285
_ACEOF
2228522286

22286-
SHMEM_IMPLEMENTATION="src/backend/port/sysv_shmem.c"
22287+
SHMEM_IMPLEMENTATION="src/backend/port/sysv_shmem.c"
22288+
else
22289+
22290+
cat >>confdefs.h <<\_ACEOF
22291+
#define USE_WIN32_SHARED_MEMORY 1
22292+
_ACEOF
2228722293

22294+
SHMEM_IMPLEMENTATION="src/backend/port/win32_shmem.c"
22295+
fi
2228822296

2228922297
# If not set in template file, set bytes to use libc memset()
2229022298
if test x"$MEMSET_LOOP_LIMIT" = x"" ; then

configure.in

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.502 2007/02/21 15:12:39 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.503 2007/03/21 14:39:23 mha Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -1367,9 +1367,13 @@ fi
13671367

13681368

13691369
# Select shared-memory implementation type.
1370-
AC_DEFINE(USE_SYSV_SHARED_MEMORY, 1, [Define to select SysV-style shared memory.])
1371-
SHMEM_IMPLEMENTATION="src/backend/port/sysv_shmem.c"
1372-
1370+
if test "$PORTNAME" != "win32"; then
1371+
AC_DEFINE(USE_SYSV_SHARED_MEMORY, 1, [Define to select SysV-style shared memory.])
1372+
SHMEM_IMPLEMENTATION="src/backend/port/sysv_shmem.c"
1373+
else
1374+
AC_DEFINE(USE_WIN32_SHARED_MEMORY, 1, [Define to select Win32-style shared memory.])
1375+
SHMEM_IMPLEMENTATION="src/backend/port/win32_shmem.c"
1376+
fi
13731377

13741378
# If not set in template file, set bytes to use libc memset()
13751379
if test x"$MEMSET_LOOP_LIMIT" = x"" ; then

src/backend/port/sysv_shmem.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.49 2007/02/06 16:20:23 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.50 2007/03/21 14:39:23 mha Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -195,11 +195,8 @@ PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
195195
{
196196
IpcMemoryId shmId = (IpcMemoryId) id2;
197197
struct shmid_ds shmStat;
198-
199-
#ifndef WIN32
200198
struct stat statbuf;
201199
PGShmemHeader *hdr;
202-
#endif
203200

204201
/*
205202
* We detect whether a shared memory segment is in use by seeing whether
@@ -238,11 +235,8 @@ PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
238235
/*
239236
* Try to attach to the segment and see if it matches our data directory.
240237
* This avoids shmid-conflict problems on machines that are running
241-
* several postmasters under the same userid. On Windows, which doesn't
242-
* have useful inode numbers, we can't do this so we punt and assume there
243-
* is a conflict.
238+
* several postmasters under the same userid.
244239
*/
245-
#ifndef WIN32
246240
if (stat(DataDir, &statbuf) < 0)
247241
return true; /* if can't stat, be conservative */
248242

@@ -265,7 +259,6 @@ PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
265259

266260
/* Trouble --- looks a lot like there's still live backends */
267261
shmdt((void *) hdr);
268-
#endif
269262

270263
return true;
271264
}
@@ -296,10 +289,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
296289
void *memAddress;
297290
PGShmemHeader *hdr;
298291
IpcMemoryId shmid;
299-
300-
#ifndef WIN32
301292
struct stat statbuf;
302-
#endif
303293

304294
/* Room for a header? */
305295
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
@@ -372,7 +362,6 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
372362
hdr->creatorPID = getpid();
373363
hdr->magic = PGShmemMagic;
374364

375-
#ifndef WIN32
376365
/* Fill in the data directory ID info, too */
377366
if (stat(DataDir, &statbuf) < 0)
378367
ereport(FATAL,
@@ -381,7 +370,6 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
381370
DataDir)));
382371
hdr->device = statbuf.st_dev;
383372
hdr->inode = statbuf.st_ino;
384-
#endif
385373

386374
/*
387375
* Initialize space allocation status for segment.

src/backend/port/win32/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Makefile for backend/port/win32
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.9 2007/01/20 17:16:12 petere Exp $
7+
# $PostgreSQL: pgsql/src/backend/port/win32/Makefile,v 1.10 2007/03/21 14:39:23 mha Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/port/win32
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = shmem.o timer.o socket.o signal.o security.o
15+
OBJS = timer.o socket.o signal.o security.o
1616

1717
all: SUBSYS.o
1818

src/backend/port/win32/shmem.c

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)