Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c85a5af

Browse files
anarazelCommitfest Bot
authored and
Commitfest Bot
committed
instr_time: Add INSTR_TIME_SET_SECONDS(), INSTR_TIME_IS_LT()
INSTR_TIME_SET_SECONDS() is useful to calculate the end of a time-bound loop without having to convert into time units (which is costly). INSTR_TIME_IS_LT() can be used to check the loop condition. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch:
1 parent 06eae9e commit c85a5af

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/include/portability/instr_time.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
*
1616
* INSTR_TIME_IS_ZERO(t) is t equal to zero?
1717
*
18+
* INSTR_TIME_IS_LT(x, y) x < y
19+
*
1820
* INSTR_TIME_SET_ZERO(t) set t to zero (memset is acceptable too)
1921
*
2022
* INSTR_TIME_SET_CURRENT(t) set t to current time
2123
*
2224
* INSTR_TIME_SET_CURRENT_LAZY(t) set t to current time if t is zero,
2325
* evaluates to whether t changed
2426
*
27+
* INSTR_TIME_SET_SECONDS(t, s) set t to s seconds
28+
*
2529
* INSTR_TIME_ADD(x, y) x += y
2630
*
2731
* INSTR_TIME_SUBTRACT(x, y) x -= y
@@ -122,6 +126,9 @@ pg_clock_gettime_ns(void)
122126
#define INSTR_TIME_SET_CURRENT(t) \
123127
((t) = pg_clock_gettime_ns())
124128

129+
#define INSTR_TIME_SET_SECONDS(t, s) \
130+
((t).ticks = NS_PER_S * (s))
131+
125132
#define INSTR_TIME_GET_NANOSEC(t) \
126133
((int64) (t).ticks)
127134

@@ -156,6 +163,9 @@ GetTimerFrequency(void)
156163
#define INSTR_TIME_SET_CURRENT(t) \
157164
((t) = pg_query_performance_counter())
158165

166+
#define INSTR_TIME_SET_SECONDS(t, s) \
167+
((t).ticks = s * GetTimerFrequency())
168+
159169
#define INSTR_TIME_GET_NANOSEC(t) \
160170
((int64) ((t).ticks * ((double) NS_PER_S / GetTimerFrequency())))
161171

@@ -168,6 +178,8 @@ GetTimerFrequency(void)
168178

169179
#define INSTR_TIME_IS_ZERO(t) ((t).ticks == 0)
170180

181+
#define INSTR_TIME_IS_LT(x, y) ((x).ticks < (y).ticks)
182+
171183

172184
#define INSTR_TIME_SET_ZERO(t) ((t).ticks = 0)
173185

0 commit comments

Comments
 (0)