static void AtProcExit_Buffers(int code, Datum arg);
static void CheckForBufferLeaks(void);
static int rnode_comparator(const void *p1, const void *p2);
-static int buffertag_comparator(const void *p1, const void *p2);
-static int ckpt_buforder_comparator(const void *pa, const void *pb);
+static inline int buffertag_comparator(const BufferTag *a, const BufferTag *b);
+static inline int ckpt_buforder_comparator(const CkptSortItem *a, const CkptSortItem *b);
static int ts_ckpt_progress_comparator(Datum a, Datum b, void *arg);
}
}
+#define ST_SORT sort_checkpoint_bufferids
+#define ST_ELEMENT_TYPE CkptSortItem
+#define ST_COMPARE(a, b) ckpt_buforder_comparator(a, b)
+#define ST_SCOPE static
+#define ST_DEFINE
+#include <lib/sort_template.h>
+
/*
* BufferSync -- Write out all dirty buffers in the pool.
*
* end up writing to the tablespaces one-by-one; possibly overloading the
* underlying system.
*/
- qsort(CkptBufferIds, num_to_scan, sizeof(CkptSortItem),
- ckpt_buforder_comparator);
+ sort_checkpoint_bufferids(CkptBufferIds, num_to_scan);
num_spaces = 0;
/*
* BufferTag comparator.
*/
-static int
-buffertag_comparator(const void *a, const void *b)
+static inline int
+buffertag_comparator(const BufferTag *ba, const BufferTag *bb)
{
- const BufferTag *ba = (const BufferTag *) a;
- const BufferTag *bb = (const BufferTag *) b;
int ret;
ret = rnode_comparator(&ba->rnode, &bb->rnode);
* It is important that tablespaces are compared first, the logic balancing
* writes between tablespaces relies on it.
*/
-static int
-ckpt_buforder_comparator(const void *pa, const void *pb)
+static inline int
+ckpt_buforder_comparator(const CkptSortItem *a, const CkptSortItem *b)
{
- const CkptSortItem *a = (const CkptSortItem *) pa;
- const CkptSortItem *b = (const CkptSortItem *) pb;
-
/* compare tablespace */
if (a->tsId < b->tsId)
return -1;
IssuePendingWritebacks(context);
}
+#define ST_SORT sort_pending_writebacks
+#define ST_ELEMENT_TYPE PendingWriteback
+#define ST_COMPARE(a, b) buffertag_comparator(&a->tag, &b->tag)
+#define ST_SCOPE static
+#define ST_DEFINE
+#include <lib/sort_template.h>
+
/*
* Issue all pending writeback requests, previously scheduled with
* ScheduleBufferTagForWriteback, to the OS.
* Executing the writes in-order can make them a lot faster, and allows to
* merge writeback requests to consecutive blocks into larger writebacks.
*/
- qsort(&context->pending_writebacks, context->nr_pending,
- sizeof(PendingWriteback), buffertag_comparator);
+ sort_pending_writebacks(context->pending_writebacks, context->nr_pending);
/*
* Coalesce neighbouring writes, but nothing else. For that we iterate