diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-11-15 16:30:35 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-11-15 16:33:29 -0500 |
commit | b40b4dd9e10ea701c8d47ccba9407fc32ed384e5 (patch) | |
tree | 97a6bd5f4ba10dcecd8a0f3900c4cbe37be8dbd5 /src/backend/storage/ipc | |
parent | 0a7481930c788e9d74a154aac0c8b401fc6a81f9 (diff) |
Reserve zero as an invalid DSM handle.
Previously, the handle for the control segment could not be zero, but
some other DSM segment could potentially have a handle value of zero.
However, that means that if someone wanted to store a dsm_handle that
might or might not be valid, they would need a separate boolean to
keep 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 to
add an malloc-like allocator for dynamic shared memory, but this part
seems like a good idea independently of the rest of the patch.
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r-- | src/backend/storage/ipc/dsm.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c index d8066647a07..8c6abe3b45b 100644 --- a/src/backend/storage/ipc/dsm.c +++ b/src/backend/storage/ipc/dsm.c @@ -182,7 +182,7 @@ dsm_postmaster_startup(PGShmemHeader *shim) Assert(dsm_control_address == NULL); Assert(dsm_control_mapped_size == 0); dsm_control_handle = random(); - if (dsm_control_handle == 0) + if (dsm_control_handle == DSM_HANDLE_INVALID) continue; if (dsm_impl_op(DSM_OP_CREATE, dsm_control_handle, segsize, &dsm_control_impl_private, &dsm_control_address, @@ -476,6 +476,8 @@ dsm_create(Size size, int flags) { Assert(seg->mapped_address == NULL && seg->mapped_size == 0); seg->handle = random(); + if (seg->handle == DSM_HANDLE_INVALID) /* Reserve sentinel */ + continue; if (dsm_impl_op(DSM_OP_CREATE, seg->handle, size, &seg->impl_private, &seg->mapped_address, &seg->mapped_size, ERROR)) break; |