@@ -488,8 +488,8 @@ static void FindAndDropRelFileNodeBuffers(RelFileNode rnode,
488
488
static void AtProcExit_Buffers (int code , Datum arg );
489
489
static void CheckForBufferLeaks (void );
490
490
static int rnode_comparator (const void * p1 , const void * p2 );
491
- static int buffertag_comparator (const void * p1 , const void * p2 );
492
- static int ckpt_buforder_comparator (const void * pa , const void * pb );
491
+ static inline int buffertag_comparator (const BufferTag * a , const BufferTag * b );
492
+ static inline int ckpt_buforder_comparator (const CkptSortItem * a , const CkptSortItem * b );
493
493
static int ts_ckpt_progress_comparator (Datum a , Datum b , void * arg );
494
494
495
495
@@ -1831,6 +1831,13 @@ UnpinBuffer(BufferDesc *buf, bool fixOwner)
1831
1831
}
1832
1832
}
1833
1833
1834
+ #define ST_SORT sort_checkpoint_bufferids
1835
+ #define ST_ELEMENT_TYPE CkptSortItem
1836
+ #define ST_COMPARE (a , b ) ckpt_buforder_comparator(a, b)
1837
+ #define ST_SCOPE static
1838
+ #define ST_DEFINE
1839
+ #include <lib/sort_template.h>
1840
+
1834
1841
/*
1835
1842
* BufferSync -- Write out all dirty buffers in the pool.
1836
1843
*
@@ -1931,8 +1938,7 @@ BufferSync(int flags)
1931
1938
* end up writing to the tablespaces one-by-one; possibly overloading the
1932
1939
* underlying system.
1933
1940
*/
1934
- qsort (CkptBufferIds , num_to_scan , sizeof (CkptSortItem ),
1935
- ckpt_buforder_comparator );
1941
+ sort_checkpoint_bufferids (CkptBufferIds , num_to_scan );
1936
1942
1937
1943
num_spaces = 0 ;
1938
1944
@@ -4567,11 +4573,9 @@ WaitBufHdrUnlocked(BufferDesc *buf)
4567
4573
/*
4568
4574
* BufferTag comparator.
4569
4575
*/
4570
- static int
4571
- buffertag_comparator (const void * a , const void * b )
4576
+ static inline int
4577
+ buffertag_comparator (const BufferTag * ba , const BufferTag * bb )
4572
4578
{
4573
- const BufferTag * ba = (const BufferTag * ) a ;
4574
- const BufferTag * bb = (const BufferTag * ) b ;
4575
4579
int ret ;
4576
4580
4577
4581
ret = rnode_comparator (& ba -> rnode , & bb -> rnode );
@@ -4598,12 +4602,9 @@ buffertag_comparator(const void *a, const void *b)
4598
4602
* It is important that tablespaces are compared first, the logic balancing
4599
4603
* writes between tablespaces relies on it.
4600
4604
*/
4601
- static int
4602
- ckpt_buforder_comparator (const void * pa , const void * pb )
4605
+ static inline int
4606
+ ckpt_buforder_comparator (const CkptSortItem * a , const CkptSortItem * b )
4603
4607
{
4604
- const CkptSortItem * a = (const CkptSortItem * ) pa ;
4605
- const CkptSortItem * b = (const CkptSortItem * ) pb ;
4606
-
4607
4608
/* compare tablespace */
4608
4609
if (a -> tsId < b -> tsId )
4609
4610
return -1 ;
@@ -4694,6 +4695,13 @@ ScheduleBufferTagForWriteback(WritebackContext *context, BufferTag *tag)
4694
4695
IssuePendingWritebacks (context );
4695
4696
}
4696
4697
4698
+ #define ST_SORT sort_pending_writebacks
4699
+ #define ST_ELEMENT_TYPE PendingWriteback
4700
+ #define ST_COMPARE (a , b ) buffertag_comparator(&a->tag, &b->tag)
4701
+ #define ST_SCOPE static
4702
+ #define ST_DEFINE
4703
+ #include <lib/sort_template.h>
4704
+
4697
4705
/*
4698
4706
* Issue all pending writeback requests, previously scheduled with
4699
4707
* ScheduleBufferTagForWriteback, to the OS.
@@ -4713,8 +4721,7 @@ IssuePendingWritebacks(WritebackContext *context)
4713
4721
* Executing the writes in-order can make them a lot faster, and allows to
4714
4722
* merge writeback requests to consecutive blocks into larger writebacks.
4715
4723
*/
4716
- qsort (& context -> pending_writebacks , context -> nr_pending ,
4717
- sizeof (PendingWriteback ), buffertag_comparator );
4724
+ sort_pending_writebacks (context -> pending_writebacks , context -> nr_pending );
4718
4725
4719
4726
/*
4720
4727
* Coalesce neighbouring writes, but nothing else. For that we iterate
0 commit comments