* AddInvalidationMessage * Add an invalidation message to a list (of chunks). * * Note that we do not pay any great attention to maintaining the original * ordering of the messages. */
| 251 | * ordering of the messages. |
| 252 | */ |
| 253 | static void |
| 254 | AddInvalidationMessage(InvalidationChunk **listHdr, |
| 255 | SharedInvalidationMessage *msg) |
| 256 | { |
| 257 | InvalidationChunk *chunk = *listHdr; |
| 258 | |
| 259 | if (chunk == NULL) |
| 260 | { |
| 261 | /* First time through; create initial chunk */ |
| 262 | #define FIRSTCHUNKSIZE 32 |
| 263 | chunk = (InvalidationChunk *) |
| 264 | MemoryContextAlloc(CurTransactionContext, |
| 265 | offsetof(InvalidationChunk, msgs) + |
| 266 | FIRSTCHUNKSIZE * sizeof(SharedInvalidationMessage)); |
| 267 | chunk->nitems = 0; |
| 268 | chunk->maxitems = FIRSTCHUNKSIZE; |
| 269 | chunk->next = *listHdr; |
| 270 | *listHdr = chunk; |
| 271 | } |
| 272 | else if (chunk->nitems >= chunk->maxitems) |
| 273 | { |
| 274 | /* Need another chunk; double size of last chunk */ |
| 275 | int chunksize = 2 * chunk->maxitems; |
| 276 | |
| 277 | /* |
| 278 | * Keep in mind: the max allowed alloc size is about 1GB, for |
| 279 | * simplification we set the upper limit to half of that. |
| 280 | */ |
| 281 | #define MAXCHUNKSIZE (MaxAllocSize / 2 / sizeof(SharedInvalidationMessage)) |
| 282 | if (chunksize > MAXCHUNKSIZE) |
| 283 | chunksize >>= 1; |
| 284 | |
| 285 | chunk = (InvalidationChunk *) |
| 286 | MemoryContextAlloc(CurTransactionContext, |
| 287 | offsetof(InvalidationChunk, msgs) + |
| 288 | chunksize * sizeof(SharedInvalidationMessage)); |
| 289 | chunk->nitems = 0; |
| 290 | chunk->maxitems = chunksize; |
| 291 | chunk->next = *listHdr; |
| 292 | *listHdr = chunk; |
| 293 | } |
| 294 | /* Okay, add message to current chunk */ |
| 295 | chunk->msgs[chunk->nitems] = *msg; |
| 296 | chunk->nitems++; |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * Append one list of invalidation message chunks to another, resetting |
no test coverage detected