Skip to content

Commit 47932f3

Browse files
committed
Use consistent type for pgaio_io_get_id() result
The result of pgaio_io_get_id() was being assigned to a mix of int and uint32 variables. This fixes it to use int consistently, which seems the most correct. Also change the queue empty special value in method_worker.c to -1 from UINT32_MAX. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/70c784b3-f60b-4652-b8a6-75e5f051243e%40eisentraut.org
1 parent 12da457 commit 47932f3

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/backend/storage/aio/aio_funcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pg_get_aios(PG_FUNCTION_ARGS)
5656
for (uint64 i = 0; i < pgaio_ctl->io_handle_count; i++)
5757
{
5858
PgAioHandle *live_ioh = &pgaio_ctl->io_handles[i];
59-
uint32ioh_id = pgaio_io_get_id(live_ioh);
59+
intioh_id = pgaio_io_get_id(live_ioh);
6060
Datumvalues[PG_GET_AIOS_COLS] = {0};
6161
boolnulls[PG_GET_AIOS_COLS] = {0};
6262
ProcNumberowner;
@@ -152,7 +152,7 @@ pg_get_aios(PG_FUNCTION_ARGS)
152152
nulls[0] = false;
153153

154154
/* column: IO's id */
155-
values[1] = UInt32GetDatum(ioh_id);
155+
values[1] = Int32GetDatum(ioh_id);
156156

157157
/* column: IO's generation */
158158
values[2] = Int64GetDatum(start_generation);

src/backend/storage/aio/method_worker.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct PgAioWorkerSubmissionQueue
5858
uint32mask;
5959
uint32head;
6060
uint32tail;
61-
uint32sqes[FLEXIBLE_ARRAY_MEMBER];
61+
intsqes[FLEXIBLE_ARRAY_MEMBER];
6262
} PgAioWorkerSubmissionQueue;
6363

6464
typedef struct PgAioWorkerSlot
@@ -107,7 +107,7 @@ pgaio_worker_queue_shmem_size(int *queue_size)
107107
*queue_size = pg_nextpower2_32(io_worker_queue_size);
108108

109109
return offsetof(PgAioWorkerSubmissionQueue, sqes) +
110-
sizeof(uint32) * *queue_size;
110+
sizeof(int) * *queue_size;
111111
}
112112

113113
static size_t
@@ -198,15 +198,15 @@ pgaio_worker_submission_queue_insert(PgAioHandle *ioh)
198198
return true;
199199
}
200200

201-
static uint32
201+
static int
202202
pgaio_worker_submission_queue_consume(void)
203203
{
204204
PgAioWorkerSubmissionQueue *queue;
205-
uint32result;
205+
intresult;
206206

207207
queue = io_worker_submission_queue;
208208
if (queue->tail == queue->head)
209-
return UINT32_MAX;/* empty */
209+
return -1;/* empty */
210210

211211
result = queue->sqes[queue->tail];
212212
queue->tail = (queue->tail + 1) & (queue->size - 1);
@@ -470,7 +470,7 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
470470
* to ensure that we don't see an outdated data in the handle.
471471
*/
472472
LWLockAcquire(AioWorkerSubmissionQueueLock, LW_EXCLUSIVE);
473-
if ((io_index = pgaio_worker_submission_queue_consume()) == UINT32_MAX)
473+
if ((io_index = pgaio_worker_submission_queue_consume()) == -1)
474474
{
475475
/*
476476
* Nothing to do. Mark self idle.
@@ -500,7 +500,7 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
500500
for (int i = 0; i < nlatches; ++i)
501501
SetLatch(latches[i]);
502502

503-
if (io_index != UINT32_MAX)
503+
if (io_index != -1)
504504
{
505505
PgAioHandle *ioh = NULL;
506506

0 commit comments

Comments
 (0)