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

Commitb40b4dd

Browse files
committed
Reserve zero as an invalid DSM handle.
Previously, the handle for the control segment could not be zero, butsome other DSM segment could potentially have a handle value of zero.However, that means that if someone wanted to store a dsm_handle thatmight or might not be valid, they would need a separate boolean tokeep track of whether the associated value is legal. That's annoying,so change things so that no DSM segment can ever have a handle of 0 -or as we call it here, DSM_HANDLE_INVALID.Thomas Munro. This was submitted as part of a much larger patch toadd an malloc-like allocator for dynamic shared memory, but this partseems like a good idea independently of the rest of the patch.
1 parent0a74819 commitb40b4dd

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎src/backend/storage/ipc/dsm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ dsm_postmaster_startup(PGShmemHeader *shim)
182182
Assert(dsm_control_address==NULL);
183183
Assert(dsm_control_mapped_size==0);
184184
dsm_control_handle=random();
185-
if (dsm_control_handle==0)
185+
if (dsm_control_handle==DSM_HANDLE_INVALID)
186186
continue;
187187
if (dsm_impl_op(DSM_OP_CREATE,dsm_control_handle,segsize,
188188
&dsm_control_impl_private,&dsm_control_address,
@@ -476,6 +476,8 @@ dsm_create(Size size, int flags)
476476
{
477477
Assert(seg->mapped_address==NULL&&seg->mapped_size==0);
478478
seg->handle=random();
479+
if (seg->handle==DSM_HANDLE_INVALID)/* Reserve sentinel */
480+
continue;
479481
if (dsm_impl_op(DSM_OP_CREATE,seg->handle,size,&seg->impl_private,
480482
&seg->mapped_address,&seg->mapped_size,ERROR))
481483
break;

‎src/include/storage/dsm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ typedef struct dsm_segment dsm_segment;
1919

2020
#defineDSM_CREATE_NULL_IF_MAXSEGMENTS0x0001
2121

22+
/* A sentinel value for an invalid DSM handle. */
23+
#defineDSM_HANDLE_INVALID 0
24+
2225
/* Startup and shutdown functions. */
2326
structPGShmemHeader;/* avoid including pg_shmem.h */
2427
externvoiddsm_cleanup_using_control_segment(dsm_handleold_control_handle);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp