Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
54aabaa8
Commit
54aabaa8
authored
Jun 27, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename BindingTable to ShmemIndex.
parent
7487a826
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
130 additions
and
130 deletions
+130
-130
src/backend/storage/buffer/buf_init.c
src/backend/storage/buffer/buf_init.c
+5
-5
src/backend/storage/ipc/ipci.c
src/backend/storage/ipc/ipci.c
+2
-2
src/backend/storage/ipc/shmem.c
src/backend/storage/ipc/shmem.c
+94
-94
src/backend/storage/ipc/spin.c
src/backend/storage/ipc/spin.c
+6
-6
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/lock.c
+4
-4
src/backend/storage/lmgr/proc.c
src/backend/storage/lmgr/proc.c
+4
-4
src/include/storage/ipc.h
src/include/storage/ipc.h
+3
-3
src/include/storage/shmem.h
src/include/storage/shmem.h
+12
-12
No files found.
src/backend/storage/buffer/buf_init.c
View file @
54aabaa8
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.1
7 1998/01/07 21:04:46
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.1
8 1998/06/27 15:47:43
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -277,14 +277,14 @@ BufferShmemSize()
...
@@ -277,14 +277,14 @@ BufferShmemSize()
nbuckets
=
1
<<
(
int
)
my_log2
((
NBuffers
-
1
)
/
DEF_FFACTOR
+
1
);
nbuckets
=
1
<<
(
int
)
my_log2
((
NBuffers
-
1
)
/
DEF_FFACTOR
+
1
);
nsegs
=
1
<<
(
int
)
my_log2
((
nbuckets
-
1
)
/
DEF_SEGSIZE
+
1
);
nsegs
=
1
<<
(
int
)
my_log2
((
nbuckets
-
1
)
/
DEF_SEGSIZE
+
1
);
/* size of shmem
binding
table */
/* size of shmem
index
table */
size
+=
MAXALIGN
(
my_log2
(
BTABLE
_SIZE
)
*
sizeof
(
void
*
));
/* HTAB->dir */
size
+=
MAXALIGN
(
my_log2
(
SHMEM_INDEX
_SIZE
)
*
sizeof
(
void
*
));
/* HTAB->dir */
size
+=
MAXALIGN
(
sizeof
(
HHDR
));
/* HTAB->hctl */
size
+=
MAXALIGN
(
sizeof
(
HHDR
));
/* HTAB->hctl */
size
+=
MAXALIGN
(
DEF_SEGSIZE
*
sizeof
(
SEGMENT
));
size
+=
MAXALIGN
(
DEF_SEGSIZE
*
sizeof
(
SEGMENT
));
size
+=
BUCKET_ALLOC_INCR
*
size
+=
BUCKET_ALLOC_INCR
*
(
MAXALIGN
(
sizeof
(
BUCKET_INDEX
))
+
(
MAXALIGN
(
sizeof
(
BUCKET_INDEX
))
+
MAXALIGN
(
BTABLE
_KEYSIZE
)
+
MAXALIGN
(
SHMEM_INDEX
_KEYSIZE
)
+
MAXALIGN
(
BTABLE
_DATASIZE
));
MAXALIGN
(
SHMEM_INDEX
_DATASIZE
));
/* size of buffer descriptors */
/* size of buffer descriptors */
size
+=
MAXALIGN
((
NBuffers
+
1
)
*
sizeof
(
BufferDesc
));
size
+=
MAXALIGN
((
NBuffers
+
1
)
*
sizeof
(
BufferDesc
));
...
...
src/backend/storage/ipc/ipci.c
View file @
54aabaa8
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.1
4 1998/06/27 04:53:35
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.1
5 1998/06/27 15:47:44
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -83,7 +83,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key)
...
@@ -83,7 +83,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key)
IPCKeyGetBufferMemoryKey
(
key
),
size
);
IPCKeyGetBufferMemoryKey
(
key
),
size
);
}
}
ShmemCreate
(
IPCKeyGetBufferMemoryKey
(
key
),
size
);
ShmemCreate
(
IPCKeyGetBufferMemoryKey
(
key
),
size
);
Shmem
BindingTable
Reset
();
Shmem
Index
Reset
();
InitShmem
(
key
,
size
);
InitShmem
(
key
,
size
);
InitBufferPool
(
key
);
InitBufferPool
(
key
);
...
...
src/backend/storage/ipc/shmem.c
View file @
54aabaa8
...
@@ -7,14 +7,14 @@
...
@@ -7,14 +7,14 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.2
4 1998/06/27 14:06:41
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.2
5 1998/06/27 15:47:44
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
/*
/*
* POSTGRES processes share one or more regions of shared memory.
* POSTGRES processes share one or more regions of shared memory.
* The shared memory is created by a postmaster and is
"attached to"
* The shared memory is created by a postmaster and is
inherited
* by each
of the backends
. The routines in this file are used for
* by each
backends via fork()
. The routines in this file are used for
* allocating and binding to shared memory data structures.
* allocating and binding to shared memory data structures.
*
*
* NOTES:
* NOTES:
...
@@ -30,16 +30,16 @@
...
@@ -30,16 +30,16 @@
* it (assigned in the module that declares it).
* it (assigned in the module that declares it).
*
*
* (b) During initialization, each module looks for its
* (b) During initialization, each module looks for its
* shared data structures in a hash table called the "
Binding Table
".
* shared data structures in a hash table called the "
Shmem Index
".
* If the data structure is not present, the caller can allocate
* If the data structure is not present, the caller can allocate
* a new one and initialize it. If the data structure is present,
* a new one and initialize it. If the data structure is present,
* the caller "attaches" to the structure by initializing a pointer
* the caller "attaches" to the structure by initializing a pointer
* in the local address space.
* in the local address space.
* The
binding table
has two purposes: first, it gives us
* The
shmem index
has two purposes: first, it gives us
* a simple model of how the world looks when a backend process
* a simple model of how the world looks when a backend process
* initializes. If something is present in the
binding table
,
* initializes. If something is present in the
shmem index
,
* it is initialized. If it is not, it is uninitialized. Second,
* it is initialized. If it is not, it is uninitialized. Second,
* the
binding table
allows us to allocate shared memory on demand
* the
shmem index
allows us to allocate shared memory on demand
* instead of trying to preallocate structures and hard-wire the
* instead of trying to preallocate structures and hard-wire the
* sizes and locations in header files. If you are using a lot
* sizes and locations in header files. If you are using a lot
* of shared memory in a lot of different places (and changing
* of shared memory in a lot of different places (and changing
...
@@ -54,7 +54,7 @@
...
@@ -54,7 +54,7 @@
* unnecessary.
* unnecessary.
*
*
* See InitSem() in sem.c for an example of how to use the
* See InitSem() in sem.c for an example of how to use the
*
binding table
.
*
shmem index
.
*
*
*/
*/
#include <stdio.h>
#include <stdio.h>
...
@@ -76,28 +76,28 @@ static unsigned long ShmemSize = 0; /* current size (and default) */
...
@@ -76,28 +76,28 @@ static unsigned long ShmemSize = 0; /* current size (and default) */
SPINLOCK
ShmemLock
;
/* lock for shared memory allocation */
SPINLOCK
ShmemLock
;
/* lock for shared memory allocation */
SPINLOCK
BindingLock
;
/* lock for binding table
access */
SPINLOCK
ShmemIndexLock
;
/* lock for shmem index
access */
static
unsigned
long
*
ShmemFreeStart
=
NULL
;
/* pointer to the OFFSET
static
unsigned
long
*
ShmemFreeStart
=
NULL
;
/* pointer to the OFFSET
* of first free shared
* of first free shared
* memory */
* memory */
static
unsigned
long
*
Shmem
BindingTableOffset
=
NULL
;
/* start of the binding
static
unsigned
long
*
Shmem
IndexOffset
=
NULL
;
/* start of the shmem index
* table (for bootstrap) */
* table (for bootstrap) */
static
int
ShmemBootstrap
=
FALSE
;
/* flag becomes true when shared
static
int
ShmemBootstrap
=
FALSE
;
/* flag becomes true when shared
* mem is created by POSTMASTER */
* mem is created by POSTMASTER */
static
HTAB
*
BindingTable
=
NULL
;
static
HTAB
*
ShmemIndex
=
NULL
;
/* ---------------------
/* ---------------------
* Shmem
BindingTableReset() - Resets the binding table
to NULL....
* Shmem
IndexReset() - Resets the shmem index
to NULL....
* useful when the postmaster destroys existing shared memory
* useful when the postmaster destroys existing shared memory
* and creates all new segments after a backend crash.
* and creates all new segments after a backend crash.
* ----------------------
* ----------------------
*/
*/
void
void
Shmem
BindingTable
Reset
(
void
)
Shmem
Index
Reset
(
void
)
{
{
BindingTable
=
(
HTAB
*
)
NULL
;
ShmemIndex
=
(
HTAB
*
)
NULL
;
}
}
/*
/*
...
@@ -147,7 +147,7 @@ InitShmem(unsigned int key, unsigned int size)
...
@@ -147,7 +147,7 @@ InitShmem(unsigned int key, unsigned int size)
HASHCTL
info
;
HASHCTL
info
;
int
hash_flags
;
int
hash_flags
;
Binding
Ent
*
result
,
ShmemIndex
Ent
*
result
,
item
;
item
;
bool
found
;
bool
found
;
IpcMemoryId
shmid
;
IpcMemoryId
shmid
;
...
@@ -178,15 +178,15 @@ InitShmem(unsigned int key, unsigned int size)
...
@@ -178,15 +178,15 @@ InitShmem(unsigned int key, unsigned int size)
/* First long in shared memory is the count of available space */
/* First long in shared memory is the count of available space */
ShmemFreeStart
=
(
unsigned
long
*
)
ShmemBase
;
ShmemFreeStart
=
(
unsigned
long
*
)
ShmemBase
;
/* next is a shmem pointer to the
binding table
*/
/* next is a shmem pointer to the
shmem index
*/
Shmem
BindingTable
Offset
=
ShmemFreeStart
+
1
;
Shmem
Index
Offset
=
ShmemFreeStart
+
1
;
currFreeSpace
+=
currFreeSpace
+=
sizeof
(
ShmemFreeStart
)
+
sizeof
(
Shmem
BindingTable
Offset
);
sizeof
(
ShmemFreeStart
)
+
sizeof
(
Shmem
Index
Offset
);
/*
/*
* bootstrap initialize spin locks so we can start to use the
* bootstrap initialize spin locks so we can start to use the
* allocator and
binding table
.
* allocator and
shmem index
.
*/
*/
if
(
!
InitSpinLocks
(
ShmemBootstrap
,
IPCKeyGetSpinLockSemaphoreKey
(
key
)))
if
(
!
InitSpinLocks
(
ShmemBootstrap
,
IPCKeyGetSpinLockSemaphoreKey
(
key
)))
return
(
FALSE
);
return
(
FALSE
);
...
@@ -201,37 +201,37 @@ InitShmem(unsigned int key, unsigned int size)
...
@@ -201,37 +201,37 @@ InitShmem(unsigned int key, unsigned int size)
/* if ShmemFreeStart is NULL, then the allocator won't work */
/* if ShmemFreeStart is NULL, then the allocator won't work */
Assert
(
*
ShmemFreeStart
);
Assert
(
*
ShmemFreeStart
);
/* create OR attach to the shared memory
binding table
*/
/* create OR attach to the shared memory
shmem index
*/
info
.
keysize
=
BTABLE
_KEYSIZE
;
info
.
keysize
=
SHMEM_INDEX
_KEYSIZE
;
info
.
datasize
=
BTABLE
_DATASIZE
;
info
.
datasize
=
SHMEM_INDEX
_DATASIZE
;
hash_flags
=
(
HASH_ELEM
);
hash_flags
=
(
HASH_ELEM
);
/* This will acquire the
binding table
lock, but not release it. */
/* This will acquire the
shmem index
lock, but not release it. */
BindingTable
=
ShmemInitHash
(
"BindingTable
"
,
ShmemIndex
=
ShmemInitHash
(
"ShmemIndex
"
,
BTABLE_SIZE
,
BTABLE
_SIZE
,
SHMEM_INDEX_SIZE
,
SHMEM_INDEX
_SIZE
,
&
info
,
hash_flags
);
&
info
,
hash_flags
);
if
(
!
BindingTable
)
if
(
!
ShmemIndex
)
{
{
elog
(
FATAL
,
"InitShmem: couldn't initialize
Binding Table
"
);
elog
(
FATAL
,
"InitShmem: couldn't initialize
Shmem Index
"
);
return
(
FALSE
);
return
(
FALSE
);
}
}
/*
/*
* Now, check the
binding table for an entry to the binding table
. If
* Now, check the
shmem index for an entry to the shmem index
. If
* there is an entry there, someone else created the table. Otherwise,
* there is an entry there, someone else created the table. Otherwise,
* we did and we have to initialize it.
* we did and we have to initialize it.
*/
*/
MemSet
(
item
.
key
,
0
,
BTABLE
_KEYSIZE
);
MemSet
(
item
.
key
,
0
,
SHMEM_INDEX
_KEYSIZE
);
strncpy
(
item
.
key
,
"
BindingTable"
,
BTABLE
_KEYSIZE
);
strncpy
(
item
.
key
,
"
ShmemIndex"
,
SHMEM_INDEX
_KEYSIZE
);
result
=
(
Binding
Ent
*
)
result
=
(
ShmemIndex
Ent
*
)
hash_search
(
BindingTable
,
(
char
*
)
&
item
,
HASH_ENTER
,
&
found
);
hash_search
(
ShmemIndex
,
(
char
*
)
&
item
,
HASH_ENTER
,
&
found
);
if
(
!
result
)
if
(
!
result
)
{
{
elog
(
FATAL
,
"InitShmem: corrupted
binding table
"
);
elog
(
FATAL
,
"InitShmem: corrupted
shmem index
"
);
return
(
FALSE
);
return
(
FALSE
);
}
}
...
@@ -239,14 +239,14 @@ InitShmem(unsigned int key, unsigned int size)
...
@@ -239,14 +239,14 @@ InitShmem(unsigned int key, unsigned int size)
{
{
/*
/*
* bootstrapping shmem: we have to initialize the
binding table
* bootstrapping shmem: we have to initialize the
shmem index
* now.
* now.
*/
*/
Assert
(
ShmemBootstrap
);
Assert
(
ShmemBootstrap
);
result
->
location
=
MAKE_OFFSET
(
BindingTable
->
hctl
);
result
->
location
=
MAKE_OFFSET
(
ShmemIndex
->
hctl
);
*
Shmem
BindingTable
Offset
=
result
->
location
;
*
Shmem
Index
Offset
=
result
->
location
;
result
->
size
=
BTABLE
_SIZE
;
result
->
size
=
SHMEM_INDEX
_SIZE
;
ShmemBootstrap
=
FALSE
;
ShmemBootstrap
=
FALSE
;
...
@@ -254,9 +254,9 @@ InitShmem(unsigned int key, unsigned int size)
...
@@ -254,9 +254,9 @@ InitShmem(unsigned int key, unsigned int size)
else
else
Assert
(
!
ShmemBootstrap
);
Assert
(
!
ShmemBootstrap
);
/* now release the lock acquired in ShmemHashInit */
/* now release the lock acquired in ShmemHashInit */
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
Assert
(
result
->
location
==
MAKE_OFFSET
(
BindingTable
->
hctl
));
Assert
(
result
->
location
==
MAKE_OFFSET
(
ShmemIndex
->
hctl
));
return
(
TRUE
);
return
(
TRUE
);
}
}
...
@@ -329,7 +329,7 @@ ShmemIsValid(unsigned long addr)
...
@@ -329,7 +329,7 @@ ShmemIsValid(unsigned long addr)
* for the structure before creating the structure itself.
* for the structure before creating the structure itself.
*/
*/
HTAB
*
HTAB
*
ShmemInitHash
(
char
*
name
,
/* table string name for
binding
*/
ShmemInitHash
(
char
*
name
,
/* table string name for
shmem index
*/
long
init_size
,
/* initial size */
long
init_size
,
/* initial size */
long
max_size
,
/* max size of the table */
long
max_size
,
/* max size of the table */
HASHCTL
*
infoP
,
/* info about key and bucket size */
HASHCTL
*
infoP
,
/* info about key and bucket size */
...
@@ -348,12 +348,12 @@ ShmemInitHash(char *name, /* table string name for binding */
...
@@ -348,12 +348,12 @@ ShmemInitHash(char *name, /* table string name for binding */
infoP
->
max_size
=
max_size
;
infoP
->
max_size
=
max_size
;
hash_flags
|=
HASH_SHARED_MEM
;
hash_flags
|=
HASH_SHARED_MEM
;
/* look it up in the
binding table
*/
/* look it up in the
shmem index
*/
location
=
location
=
ShmemInitStruct
(
name
,
my_log2
(
max_size
)
+
sizeof
(
HHDR
),
&
found
);
ShmemInitStruct
(
name
,
my_log2
(
max_size
)
+
sizeof
(
HHDR
),
&
found
);
/*
/*
*
binding table
is corrupted. Let someone else give the error
*
shmem index
is corrupted. Let someone else give the error
* message since they have more information
* message since they have more information
*/
*/
if
(
location
==
NULL
)
if
(
location
==
NULL
)
...
@@ -379,7 +379,7 @@ ShmemInitHash(char *name, /* table string name for binding */
...
@@ -379,7 +379,7 @@ ShmemInitHash(char *name, /* table string name for binding */
* ShmemPIDLookup -- lookup process data structure using process id
* ShmemPIDLookup -- lookup process data structure using process id
*
*
* Returns: TRUE if no error. locationPtr is initialized if PID is
* Returns: TRUE if no error. locationPtr is initialized if PID is
* found in the
binding table
.
* found in the
shmem index
.
*
*
* NOTES:
* NOTES:
* only information about success or failure is the value of
* only information about success or failure is the value of
...
@@ -388,23 +388,23 @@ ShmemInitHash(char *name, /* table string name for binding */
...
@@ -388,23 +388,23 @@ ShmemInitHash(char *name, /* table string name for binding */
bool
bool
ShmemPIDLookup
(
int
pid
,
SHMEM_OFFSET
*
locationPtr
)
ShmemPIDLookup
(
int
pid
,
SHMEM_OFFSET
*
locationPtr
)
{
{
Binding
Ent
*
result
,
ShmemIndex
Ent
*
result
,
item
;
item
;
bool
found
;
bool
found
;
Assert
(
BindingTable
);
Assert
(
ShmemIndex
);
MemSet
(
item
.
key
,
0
,
BTABLE
_KEYSIZE
);
MemSet
(
item
.
key
,
0
,
SHMEM_INDEX
_KEYSIZE
);
sprintf
(
item
.
key
,
"PID %d"
,
pid
);
sprintf
(
item
.
key
,
"PID %d"
,
pid
);
SpinAcquire
(
Binding
Lock
);
SpinAcquire
(
ShmemIndex
Lock
);
result
=
(
Binding
Ent
*
)
result
=
(
ShmemIndex
Ent
*
)
hash_search
(
BindingTable
,
(
char
*
)
&
item
,
HASH_ENTER
,
&
found
);
hash_search
(
ShmemIndex
,
(
char
*
)
&
item
,
HASH_ENTER
,
&
found
);
if
(
!
result
)
if
(
!
result
)
{
{
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
elog
(
ERROR
,
"ShmemInitPID:
BindingTable
corrupted"
);
elog
(
ERROR
,
"ShmemInitPID:
ShmemIndex
corrupted"
);
return
(
FALSE
);
return
(
FALSE
);
}
}
...
@@ -414,39 +414,39 @@ ShmemPIDLookup(int pid, SHMEM_OFFSET *locationPtr)
...
@@ -414,39 +414,39 @@ ShmemPIDLookup(int pid, SHMEM_OFFSET *locationPtr)
else
else
result
->
location
=
*
locationPtr
;
result
->
location
=
*
locationPtr
;
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
return
(
TRUE
);
return
(
TRUE
);
}
}
/*
/*
* ShmemPIDDestroy -- destroy
binding table
entry for process
* ShmemPIDDestroy -- destroy
shmem index
entry for process
* using process id
* using process id
*
*
* Returns: offset of the process struct in shared memory or
* Returns: offset of the process struct in shared memory or
* INVALID_OFFSET if not found.
* INVALID_OFFSET if not found.
*
*
* Side Effect: removes the entry from the
binding table
* Side Effect: removes the entry from the
shmem index
*/
*/
SHMEM_OFFSET
SHMEM_OFFSET
ShmemPIDDestroy
(
int
pid
)
ShmemPIDDestroy
(
int
pid
)
{
{
Binding
Ent
*
result
,
ShmemIndex
Ent
*
result
,
item
;
item
;
bool
found
;
bool
found
;
SHMEM_OFFSET
location
=
0
;
SHMEM_OFFSET
location
=
0
;
Assert
(
BindingTable
);
Assert
(
ShmemIndex
);
MemSet
(
item
.
key
,
0
,
BTABLE
_KEYSIZE
);
MemSet
(
item
.
key
,
0
,
SHMEM_INDEX
_KEYSIZE
);
sprintf
(
item
.
key
,
"PID %d"
,
pid
);
sprintf
(
item
.
key
,
"PID %d"
,
pid
);
SpinAcquire
(
Binding
Lock
);
SpinAcquire
(
ShmemIndex
Lock
);
result
=
(
Binding
Ent
*
)
result
=
(
ShmemIndex
Ent
*
)
hash_search
(
BindingTable
,
(
char
*
)
&
item
,
HASH_REMOVE
,
&
found
);
hash_search
(
ShmemIndex
,
(
char
*
)
&
item
,
HASH_REMOVE
,
&
found
);
if
(
found
)
if
(
found
)
location
=
result
->
location
;
location
=
result
->
location
;
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
if
(
!
result
)
if
(
!
result
)
{
{
...
@@ -473,33 +473,33 @@ ShmemPIDDestroy(int pid)
...
@@ -473,33 +473,33 @@ ShmemPIDDestroy(int pid)
* table is returned.
* table is returned.
*
*
* Returns: real pointer to the object. FoundPtr is TRUE if
* Returns: real pointer to the object. FoundPtr is TRUE if
* the object is already in the
binding table
(hence, already
* the object is already in the
shmem index
(hence, already
* initialized).
* initialized).
*/
*/
long
*
long
*
ShmemInitStruct
(
char
*
name
,
unsigned
long
size
,
bool
*
foundPtr
)
ShmemInitStruct
(
char
*
name
,
unsigned
long
size
,
bool
*
foundPtr
)
{
{
Binding
Ent
*
result
,
ShmemIndex
Ent
*
result
,
item
;
item
;
long
*
structPtr
;
long
*
structPtr
;
strncpy
(
item
.
key
,
name
,
BTABLE
_KEYSIZE
);
strncpy
(
item
.
key
,
name
,
SHMEM_INDEX
_KEYSIZE
);
item
.
location
=
BAD_LOCATION
;
item
.
location
=
BAD_LOCATION
;
SpinAcquire
(
Binding
Lock
);
SpinAcquire
(
ShmemIndex
Lock
);
if
(
!
BindingTable
)
if
(
!
ShmemIndex
)
{
{
#ifdef USE_ASSERT_CHECKING
#ifdef USE_ASSERT_CHECKING
char
*
strname
=
"
BindingTable
"
;
char
*
strname
=
"
ShmemIndex
"
;
#endif
#endif
/*
/*
* If the
binding table
doesnt exist, we fake it.
* If the
shmem index
doesnt exist, we fake it.
*
*
* If we are creating the first
binding table
, then let shmemalloc()
* If we are creating the first
shmem index
, then let shmemalloc()
* allocate the space for a new HTAB. Otherwise, find the old one
* allocate the space for a new HTAB. Otherwise, find the old one
* and return that. Notice that the
Binding
Lock is held until the
* and return that. Notice that the
ShmemIndex
Lock is held until the
*
binding table
has been completely initialized.
*
shmem index
has been completely initialized.
*/
*/
Assert
(
!
strcmp
(
name
,
strname
));
Assert
(
!
strcmp
(
name
,
strname
));
if
(
ShmemBootstrap
)
if
(
ShmemBootstrap
)
...
@@ -511,41 +511,41 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
...
@@ -511,41 +511,41 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
}
}
else
else
{
{
Assert
(
Shmem
BindingTable
Offset
);
Assert
(
Shmem
Index
Offset
);
*
foundPtr
=
TRUE
;
*
foundPtr
=
TRUE
;
return
((
long
*
)
MAKE_PTR
(
*
Shmem
BindingTable
Offset
));
return
((
long
*
)
MAKE_PTR
(
*
Shmem
Index
Offset
));
}
}
}
}
else
else
{
{
/* look it up in the
binding table
*/
/* look it up in the
shmem index
*/
result
=
(
Binding
Ent
*
)
result
=
(
ShmemIndex
Ent
*
)
hash_search
(
BindingTable
,
(
char
*
)
&
item
,
HASH_ENTER
,
foundPtr
);
hash_search
(
ShmemIndex
,
(
char
*
)
&
item
,
HASH_ENTER
,
foundPtr
);
}
}
if
(
!
result
)
if
(
!
result
)
{
{
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
elog
(
ERROR
,
"ShmemInitStruct:
Binding Table
corrupted"
);
elog
(
ERROR
,
"ShmemInitStruct:
Shmem Index
corrupted"
);
return
(
NULL
);
return
(
NULL
);
}
}
else
if
(
*
foundPtr
)
else
if
(
*
foundPtr
)
{
{
/*
/*
* Structure is in the
binding table
so someone else has allocated
* Structure is in the
shmem index
so someone else has allocated
* it already. The size better be the same as the size we are
* it already. The size better be the same as the size we are
* trying to initialize to or there is a name conflict (or worse).
* trying to initialize to or there is a name conflict (or worse).
*/
*/
if
(
result
->
size
!=
size
)
if
(
result
->
size
!=
size
)
{
{
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
elog
(
NOTICE
,
"ShmemInitStruct:
BindingTable
entry size is wrong"
);
elog
(
NOTICE
,
"ShmemInitStruct:
ShmemIndex
entry size is wrong"
);
/* let caller print its message too */
/* let caller print its message too */
return
(
NULL
);
return
(
NULL
);
}
}
...
@@ -558,9 +558,9 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
...
@@ -558,9 +558,9 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
if
(
!
structPtr
)
if
(
!
structPtr
)
{
{
/* out of memory */
/* out of memory */
Assert
(
BindingTable
);
Assert
(
ShmemIndex
);
hash_search
(
BindingTable
,
(
char
*
)
&
item
,
HASH_REMOVE
,
foundPtr
);
hash_search
(
ShmemIndex
,
(
char
*
)
&
item
,
HASH_REMOVE
,
foundPtr
);
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
*
foundPtr
=
FALSE
;
*
foundPtr
=
FALSE
;
elog
(
NOTICE
,
"ShmemInitStruct: cannot allocate '%s'"
,
elog
(
NOTICE
,
"ShmemInitStruct: cannot allocate '%s'"
,
...
@@ -572,7 +572,7 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
...
@@ -572,7 +572,7 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
}
}
Assert
(
ShmemIsValid
((
unsigned
long
)
structPtr
));
Assert
(
ShmemIsValid
((
unsigned
long
)
structPtr
));
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
return
(
structPtr
);
return
(
structPtr
);
}
}
...
@@ -586,19 +586,19 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
...
@@ -586,19 +586,19 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
bool
bool
TransactionIdIsInProgress
(
TransactionId
xid
)
TransactionIdIsInProgress
(
TransactionId
xid
)
{
{
Binding
Ent
*
result
;
ShmemIndex
Ent
*
result
;
PROC
*
proc
;
PROC
*
proc
;
Assert
(
BindingTable
);
Assert
(
ShmemIndex
);
SpinAcquire
(
Binding
Lock
);
SpinAcquire
(
ShmemIndex
Lock
);
hash_seq
((
HTAB
*
)
NULL
);
hash_seq
((
HTAB
*
)
NULL
);
while
((
result
=
(
BindingEnt
*
)
hash_seq
(
BindingTable
))
!=
NULL
)
while
((
result
=
(
ShmemIndexEnt
*
)
hash_seq
(
ShmemIndex
))
!=
NULL
)
{
{
if
(
result
==
(
Binding
Ent
*
)
TRUE
)
if
(
result
==
(
ShmemIndex
Ent
*
)
TRUE
)
{
{
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
return
(
false
);
return
(
false
);
}
}
if
(
result
->
location
==
INVALID_OFFSET
||
if
(
result
->
location
==
INVALID_OFFSET
||
...
@@ -607,12 +607,12 @@ TransactionIdIsInProgress(TransactionId xid)
...
@@ -607,12 +607,12 @@ TransactionIdIsInProgress(TransactionId xid)
proc
=
(
PROC
*
)
MAKE_PTR
(
result
->
location
);
proc
=
(
PROC
*
)
MAKE_PTR
(
result
->
location
);
if
(
proc
->
xid
==
xid
)
if
(
proc
->
xid
==
xid
)
{
{
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
return
(
true
);
return
(
true
);
}
}
}
}
SpinRelease
(
Binding
Lock
);
SpinRelease
(
ShmemIndex
Lock
);
elog
(
ERROR
,
"TransactionIdIsInProgress:
BindingTable
corrupted"
);
elog
(
ERROR
,
"TransactionIdIsInProgress:
ShmemIndex
corrupted"
);
return
(
false
);
return
(
false
);
}
}
src/backend/storage/ipc/spin.c
View file @
54aabaa8
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.1
3 1998/06/23 16:04:46
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.1
4 1998/06/27 15:47:45
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -53,7 +53,7 @@ bool
...
@@ -53,7 +53,7 @@ bool
InitSpinLocks
(
int
init
,
IPCKey
key
)
InitSpinLocks
(
int
init
,
IPCKey
key
)
{
{
extern
SPINLOCK
ShmemLock
;
extern
SPINLOCK
ShmemLock
;
extern
SPINLOCK
Binding
Lock
;
extern
SPINLOCK
ShmemIndex
Lock
;
extern
SPINLOCK
BufMgrLock
;
extern
SPINLOCK
BufMgrLock
;
extern
SPINLOCK
LockMgrLock
;
extern
SPINLOCK
LockMgrLock
;
extern
SPINLOCK
ProcStructLock
;
extern
SPINLOCK
ProcStructLock
;
...
@@ -66,7 +66,7 @@ InitSpinLocks(int init, IPCKey key)
...
@@ -66,7 +66,7 @@ InitSpinLocks(int init, IPCKey key)
/* These six spinlocks have fixed location is shmem */
/* These six spinlocks have fixed location is shmem */
ShmemLock
=
(
SPINLOCK
)
SHMEMLOCKID
;
ShmemLock
=
(
SPINLOCK
)
SHMEMLOCKID
;
BindingLock
=
(
SPINLOCK
)
BINDING
LOCKID
;
ShmemIndexLock
=
(
SPINLOCK
)
SHMEMINDEX
LOCKID
;
BufMgrLock
=
(
SPINLOCK
)
BUFMGRLOCKID
;
BufMgrLock
=
(
SPINLOCK
)
BUFMGRLOCKID
;
LockMgrLock
=
(
SPINLOCK
)
LOCKMGRLOCKID
;
LockMgrLock
=
(
SPINLOCK
)
LOCKMGRLOCKID
;
ProcStructLock
=
(
SPINLOCK
)
PROCSTRUCTLOCKID
;
ProcStructLock
=
(
SPINLOCK
)
PROCSTRUCTLOCKID
;
...
@@ -265,7 +265,7 @@ AttachSpinLocks(IPCKey key)
...
@@ -265,7 +265,7 @@ AttachSpinLocks(IPCKey key)
* InitSpinLocks -- Spinlock bootstrapping
* InitSpinLocks -- Spinlock bootstrapping
*
*
* We need several spinlocks for bootstrapping:
* We need several spinlocks for bootstrapping:
*
BindingLock (for the shmem binding
table) and
*
ShmemIndexLock (for the shmem index
table) and
* ShmemLock (for the shmem allocator), BufMgrLock (for buffer
* ShmemLock (for the shmem allocator), BufMgrLock (for buffer
* pool exclusive access), LockMgrLock (for the lock table), and
* pool exclusive access), LockMgrLock (for the lock table), and
* ProcStructLock (a spin lock for the shared process structure).
* ProcStructLock (a spin lock for the shared process structure).
...
@@ -277,7 +277,7 @@ bool
...
@@ -277,7 +277,7 @@ bool
InitSpinLocks
(
int
init
,
IPCKey
key
)
InitSpinLocks
(
int
init
,
IPCKey
key
)
{
{
extern
SPINLOCK
ShmemLock
;
extern
SPINLOCK
ShmemLock
;
extern
SPINLOCK
Binding
Lock
;
extern
SPINLOCK
ShmemIndex
Lock
;
extern
SPINLOCK
BufMgrLock
;
extern
SPINLOCK
BufMgrLock
;
extern
SPINLOCK
LockMgrLock
;
extern
SPINLOCK
LockMgrLock
;
extern
SPINLOCK
ProcStructLock
;
extern
SPINLOCK
ProcStructLock
;
...
@@ -305,7 +305,7 @@ InitSpinLocks(int init, IPCKey key)
...
@@ -305,7 +305,7 @@ InitSpinLocks(int init, IPCKey key)
/* These five (or six) spinlocks have fixed location is shmem */
/* These five (or six) spinlocks have fixed location is shmem */
ShmemLock
=
(
SPINLOCK
)
SHMEMLOCKID
;
ShmemLock
=
(
SPINLOCK
)
SHMEMLOCKID
;
BindingLock
=
(
SPINLOCK
)
BINDING
LOCKID
;
ShmemIndexLock
=
(
SPINLOCK
)
SHMEMINDEX
LOCKID
;
BufMgrLock
=
(
SPINLOCK
)
BUFMGRLOCKID
;
BufMgrLock
=
(
SPINLOCK
)
BUFMGRLOCKID
;
LockMgrLock
=
(
SPINLOCK
)
LOCKMGRLOCKID
;
LockMgrLock
=
(
SPINLOCK
)
LOCKMGRLOCKID
;
ProcStructLock
=
(
SPINLOCK
)
PROCSTRUCTLOCKID
;
ProcStructLock
=
(
SPINLOCK
)
PROCSTRUCTLOCKID
;
...
...
src/backend/storage/lmgr/lock.c
View file @
54aabaa8
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.
29 1998/06/27 04:53:37
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.
30 1998/06/27 15:47:46
momjian Exp $
*
*
* NOTES
* NOTES
* Outside modules can create a lock table and acquire/release
* Outside modules can create a lock table and acquire/release
...
@@ -216,9 +216,9 @@ LockTypeInit(LOCKTAB *ltable,
...
@@ -216,9 +216,9 @@ LockTypeInit(LOCKTAB *ltable,
* LockTableInit -- initialize a lock table structure
* LockTableInit -- initialize a lock table structure
*
*
* Notes:
* Notes:
* (a) a lock table has four separate entries in the
binding
* (a) a lock table has four separate entries in the
shmem index
* table. This is because every shared hash table and spinlock
* table. This is because every shared hash table and spinlock
* has its name stored in the
binding table
at its creation. It
* has its name stored in the
shmem index
at its creation. It
* is wasteful, in this case, but not much space is involved.
* is wasteful, in this case, but not much space is involved.
*
*
*/
*/
...
@@ -242,7 +242,7 @@ LockTableInit(char *tabName,
...
@@ -242,7 +242,7 @@ LockTableInit(char *tabName,
return
(
INVALID_TABLEID
);
return
(
INVALID_TABLEID
);
}
}
/* allocate a string for the
binding
table lookup */
/* allocate a string for the
shmem index
table lookup */
shmemName
=
(
char
*
)
palloc
((
unsigned
)
(
strlen
(
tabName
)
+
32
));
shmemName
=
(
char
*
)
palloc
((
unsigned
)
(
strlen
(
tabName
)
+
32
));
if
(
!
shmemName
)
if
(
!
shmemName
)
{
{
...
...
src/backend/storage/lmgr/proc.c
View file @
54aabaa8
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.3
7 1998/06/27 04:53:39
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.3
8 1998/06/27 15:47:46
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -46,7 +46,7 @@
...
@@ -46,7 +46,7 @@
* This is so that we can support more backends. (system-wide semaphore
* This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95
* sets run out pretty fast.) -ay 4/95
*
*
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.3
7 1998/06/27 04:53:39
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.3
8 1998/06/27 15:47:46
momjian Exp $
*/
*/
#include <sys/time.h>
#include <sys/time.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -184,7 +184,7 @@ InitProcess(IPCKey key)
...
@@ -184,7 +184,7 @@ InitProcess(IPCKey key)
{
{
/*
/*
* have to allocate one. We can't use the normal
binding
table
* have to allocate one. We can't use the normal
shmem index
table
* mechanism because the proc structure is stored by PID instead
* mechanism because the proc structure is stored by PID instead
* of by a global name (need to look it up by PID when we cleanup
* of by a global name (need to look it up by PID when we cleanup
* dead processes).
* dead processes).
...
@@ -261,7 +261,7 @@ InitProcess(IPCKey key)
...
@@ -261,7 +261,7 @@ InitProcess(IPCKey key)
MemSet
(
MyProc
->
sLocks
,
0
,
MAX_SPINS
*
sizeof
(
*
MyProc
->
sLocks
));
MemSet
(
MyProc
->
sLocks
,
0
,
MAX_SPINS
*
sizeof
(
*
MyProc
->
sLocks
));
/* -------------------------
/* -------------------------
* Install ourselves in the
binding
table. The name to
* Install ourselves in the
shmem index
table. The name to
* use is determined by the OS-assigned process id. That
* use is determined by the OS-assigned process id. That
* allows the cleanup process to find us after any untimely
* allows the cleanup process to find us after any untimely
* exit.
* exit.
...
...
src/include/storage/ipc.h
View file @
54aabaa8
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: ipc.h,v 1.2
8 1998/06/27 13:24:21
momjian Exp $
* $Id: ipc.h,v 1.2
9 1998/06/27 15:47:47
momjian Exp $
*
*
* NOTES
* NOTES
* This file is very architecture-specific. This stuff should actually
* This file is very architecture-specific. This stuff should actually
...
@@ -109,7 +109,7 @@ typedef enum _LockId_
...
@@ -109,7 +109,7 @@ typedef enum _LockId_
LOCKLOCKID
,
LOCKLOCKID
,
OIDGENLOCKID
,
OIDGENLOCKID
,
SHMEMLOCKID
,
SHMEMLOCKID
,
BINDING
LOCKID
,
SHMEMINDEX
LOCKID
,
LOCKMGRLOCKID
,
LOCKMGRLOCKID
,
SINVALLOCKID
,
SINVALLOCKID
,
...
@@ -139,7 +139,7 @@ typedef struct slock
...
@@ -139,7 +139,7 @@ typedef struct slock
typedef
enum
_LockId_
typedef
enum
_LockId_
{
{
SHMEMLOCKID
,
SHMEMLOCKID
,
BINDING
LOCKID
,
SHMEMINDEX
LOCKID
,
BUFMGRLOCKID
,
BUFMGRLOCKID
,
LOCKMGRLOCKID
,
LOCKMGRLOCKID
,
SINVALLOCKID
,
SINVALLOCKID
,
...
...
src/include/storage/shmem.h
View file @
54aabaa8
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: shmem.h,v 1.1
2 1998/06/25 14:24:35
momjian Exp $
* $Id: shmem.h,v 1.1
3 1998/06/27 15:47:48
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -49,7 +49,7 @@ extern SHMEM_OFFSET ShmemBase;
...
@@ -49,7 +49,7 @@ extern SHMEM_OFFSET ShmemBase;
extern
SPINLOCK
ShmemLock
;
extern
SPINLOCK
ShmemLock
;
extern
SPINLOCK
Binding
Lock
;
extern
SPINLOCK
ShmemIndex
Lock
;
/* shmemqueue.c */
/* shmemqueue.c */
typedef
struct
SHM_QUEUE
typedef
struct
SHM_QUEUE
...
@@ -59,7 +59,7 @@ typedef struct SHM_QUEUE
...
@@ -59,7 +59,7 @@ typedef struct SHM_QUEUE
}
SHM_QUEUE
;
}
SHM_QUEUE
;
/* shmem.c */
/* shmem.c */
extern
void
Shmem
BindingTable
Reset
(
void
);
extern
void
Shmem
Index
Reset
(
void
);
extern
void
ShmemCreate
(
unsigned
int
key
,
unsigned
int
size
);
extern
void
ShmemCreate
(
unsigned
int
key
,
unsigned
int
size
);
extern
int
InitShmem
(
unsigned
int
key
,
unsigned
int
size
);
extern
int
InitShmem
(
unsigned
int
key
,
unsigned
int
size
);
extern
long
*
ShmemAlloc
(
unsigned
long
size
);
extern
long
*
ShmemAlloc
(
unsigned
long
size
);
...
@@ -77,21 +77,21 @@ extern bool TransactionIdIsInProgress(TransactionId xid);
...
@@ -77,21 +77,21 @@ extern bool TransactionIdIsInProgress(TransactionId xid);
typedef
int
TableID
;
typedef
int
TableID
;
/* size constants for the
binding
table */
/* size constants for the
shmem index
table */
/* max size of data structure string name */
/* max size of data structure string name */
#define
BTABLE
_KEYSIZE (50)
#define
SHMEM_INDEX
_KEYSIZE (50)
/* data in
binding
table hash bucket */
/* data in
shmem index
table hash bucket */
#define
BTABLE_DATASIZE (sizeof(BindingEnt) - BTABLE
_KEYSIZE)
#define
SHMEM_INDEX_DATASIZE (sizeof(ShmemIndexEnt) - SHMEM_INDEX
_KEYSIZE)
/* maximum size of the
binding
table */
/* maximum size of the
shmem index
table */
#define
BTABLE
_SIZE (100)
#define
SHMEM_INDEX
_SIZE (100)
/* this is a hash bucket in the
binding
table */
/* this is a hash bucket in the
shmem index
table */
typedef
struct
typedef
struct
{
{
char
key
[
BTABLE
_KEYSIZE
];
/* string name */
char
key
[
SHMEM_INDEX
_KEYSIZE
];
/* string name */
unsigned
long
location
;
/* location in shared mem */
unsigned
long
location
;
/* location in shared mem */
unsigned
long
size
;
/* numbytes allocated for the structure */
unsigned
long
size
;
/* numbytes allocated for the structure */
}
Binding
Ent
;
}
ShmemIndex
Ent
;
/*
/*
* prototypes for functions in shmqueue.c
* prototypes for functions in shmqueue.c
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment