@@ -575,10 +575,9 @@ static void setNullValue(PgBenchValue *pv);
575575static void setBoolValue (PgBenchValue * pv , bool bval );
576576static void setIntValue (PgBenchValue * pv , int64 ival );
577577static void setDoubleValue (PgBenchValue * pv , double dval );
578- static bool evaluateExpr (TState * thread , CState * st , PgBenchExpr * expr ,
578+ static bool evaluateExpr (CState * st , PgBenchExpr * expr ,
579579 PgBenchValue * retval );
580- static ConnectionStateEnum executeMetaCommand (TState * thread , CState * st ,
581- instr_time * now );
580+ static ConnectionStateEnum executeMetaCommand (CState * st , instr_time * now );
582581static void doLog (TState * thread , CState * st ,
583582 StatsData * agg , bool skipped , double latency , double lag );
584583static void processXactStats (TState * thread , CState * st , instr_time * now ,
@@ -1744,7 +1743,7 @@ isLazyFunc(PgBenchFunction func)
17441743
17451744/* lazy evaluation of some functions */
17461745static bool
1747- evalLazyFunc (TState * thread , CState * st ,
1746+ evalLazyFunc (CState * st ,
17481747 PgBenchFunction func , PgBenchExprLink * args , PgBenchValue * retval )
17491748{
17501749 PgBenchValue a1 ,
@@ -1755,7 +1754,7 @@ evalLazyFunc(TState *thread, CState *st,
17551754 Assert (isLazyFunc (func ) && args != NULL && args -> next != NULL );
17561755
17571756 /* args points to first condition */
1758- if (!evaluateExpr (thread , st , args -> expr , & a1 ))
1757+ if (!evaluateExpr (st , args -> expr , & a1 ))
17591758 return false;
17601759
17611760 /* second condition for AND/OR and corresponding branch for CASE */
@@ -1779,7 +1778,7 @@ evalLazyFunc(TState *thread, CState *st,
17791778 return true;
17801779 }
17811780
1782- if (!evaluateExpr (thread , st , args -> expr , & a2 ))
1781+ if (!evaluateExpr (st , args -> expr , & a2 ))
17831782 return false;
17841783
17851784 if (a2 .type == PGBT_NULL )
@@ -1814,7 +1813,7 @@ evalLazyFunc(TState *thread, CState *st,
18141813 return true;
18151814 }
18161815
1817- if (!evaluateExpr (thread , st , args -> expr , & a2 ))
1816+ if (!evaluateExpr (st , args -> expr , & a2 ))
18181817 return false;
18191818
18201819 if (a2 .type == PGBT_NULL )
@@ -1833,17 +1832,17 @@ evalLazyFunc(TState *thread, CState *st,
18331832 case PGBENCH_CASE :
18341833 /* when true, execute branch */
18351834 if (valueTruth (& a1 ))
1836- return evaluateExpr (thread , st , args -> expr , retval );
1835+ return evaluateExpr (st , args -> expr , retval );
18371836
18381837 /* now args contains next condition or final else expression */
18391838 args = args -> next ;
18401839
18411840 /* final else case? */
18421841 if (args -> next == NULL )
1843- return evaluateExpr (thread , st , args -> expr , retval );
1842+ return evaluateExpr (st , args -> expr , retval );
18441843
18451844 /* no, another when, proceed */
1846- return evalLazyFunc (thread , st , PGBENCH_CASE , args , retval );
1845+ return evalLazyFunc (st , PGBENCH_CASE , args , retval );
18471846
18481847 default :
18491848 /* internal error, cannot get here */
@@ -1861,7 +1860,7 @@ evalLazyFunc(TState *thread, CState *st,
18611860 * which do not require lazy evaluation.
18621861 */
18631862static bool
1864- evalStandardFunc (TState * thread , CState * st ,
1863+ evalStandardFunc (CState * st ,
18651864 PgBenchFunction func , PgBenchExprLink * args ,
18661865 PgBenchValue * retval )
18671866{
@@ -1873,7 +1872,7 @@ evalStandardFunc(TState *thread, CState *st,
18731872
18741873 for (nargs = 0 ; nargs < MAX_FARGS && l != NULL ; nargs ++ , l = l -> next )
18751874 {
1876- if (!evaluateExpr (thread , st , l -> expr , & vargs [nargs ]))
1875+ if (!evaluateExpr (st , l -> expr , & vargs [nargs ]))
18771876 return false;
18781877 has_null |= vargs [nargs ].type == PGBT_NULL ;
18791878 }
@@ -2408,13 +2407,13 @@ evalStandardFunc(TState *thread, CState *st,
24082407
24092408/* evaluate some function */
24102409static bool
2411- evalFunc (TState * thread , CState * st ,
2410+ evalFunc (CState * st ,
24122411 PgBenchFunction func , PgBenchExprLink * args , PgBenchValue * retval )
24132412{
24142413 if (isLazyFunc (func ))
2415- return evalLazyFunc (thread , st , func , args , retval );
2414+ return evalLazyFunc (st , func , args , retval );
24162415 else
2417- return evalStandardFunc (thread , st , func , args , retval );
2416+ return evalStandardFunc (st , func , args , retval );
24182417}
24192418
24202419/*
@@ -2424,7 +2423,7 @@ evalFunc(TState *thread, CState *st,
24242423 * the value itself is returned through the retval pointer.
24252424 */
24262425static bool
2427- evaluateExpr (TState * thread , CState * st , PgBenchExpr * expr , PgBenchValue * retval )
2426+ evaluateExpr (CState * st , PgBenchExpr * expr , PgBenchValue * retval )
24282427{
24292428 switch (expr -> etype )
24302429 {
@@ -2453,7 +2452,7 @@ evaluateExpr(TState *thread, CState *st, PgBenchExpr *expr, PgBenchValue *retval
24532452 }
24542453
24552454 case ENODE_FUNCTION :
2456- return evalFunc (thread , st ,
2455+ return evalFunc (st ,
24572456 expr -> u .function .function ,
24582457 expr -> u .function .args ,
24592458 retval );
@@ -3072,7 +3071,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
30723071 * - on sleep CSTATE_SLEEP
30733072 * - else CSTATE_END_COMMAND
30743073 */
3075- st -> state = executeMetaCommand (thread , st , & now );
3074+ st -> state = executeMetaCommand (st , & now );
30763075 }
30773076
30783077 /*
@@ -3304,7 +3303,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
33043303 * take no time to execute.
33053304 */
33063305static ConnectionStateEnum
3307- executeMetaCommand (TState * thread , CState * st , instr_time * now )
3306+ executeMetaCommand (CState * st , instr_time * now )
33083307{
33093308 Command * command = sql_script [st -> use_file ].commands [st -> command ];
33103309 int argc ;
@@ -3348,7 +3347,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now)
33483347 PgBenchExpr * expr = command -> expr ;
33493348 PgBenchValue result ;
33503349
3351- if (!evaluateExpr (thread , st , expr , & result ))
3350+ if (!evaluateExpr (st , expr , & result ))
33523351 {
33533352 commandFailed (st , argv [0 ], "evaluation of meta-command failed" );
33543353 return CSTATE_ABORTED ;
@@ -3367,7 +3366,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now)
33673366 PgBenchValue result ;
33683367 bool cond ;
33693368
3370- if (!evaluateExpr (thread , st , expr , & result ))
3369+ if (!evaluateExpr (st , expr , & result ))
33713370 {
33723371 commandFailed (st , argv [0 ], "evaluation of meta-command failed" );
33733372 return CSTATE_ABORTED ;
@@ -3390,7 +3389,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now)
33903389 return CSTATE_END_COMMAND ;
33913390 }
33923391
3393- if (!evaluateExpr (thread , st , expr , & result ))
3392+ if (!evaluateExpr (st , expr , & result ))
33943393 {
33953394 commandFailed (st , argv [0 ], "evaluation of meta-command failed" );
33963395 return CSTATE_ABORTED ;
@@ -4773,7 +4772,7 @@ addScript(ParsedScript script)
47734772 * progress report. On exit, they are updated with the new stats.
47744773 */
47754774static void
4776- printProgressReport (TState * thread , int64 test_start , int64 now ,
4775+ printProgressReport (TState * threads , int64 test_start , int64 now ,
47774776 StatsData * last , int64 * last_report )
47784777{
47794778 /* generate and show report */
@@ -4801,10 +4800,10 @@ printProgressReport(TState *thread, int64 test_start, int64 now,
48014800 initStats (& cur , 0 );
48024801 for (int i = 0 ; i < nthreads ; i ++ )
48034802 {
4804- mergeSimpleStats (& cur .latency , & thread [i ].stats .latency );
4805- mergeSimpleStats (& cur .lag , & thread [i ].stats .lag );
4806- cur .cnt += thread [i ].stats .cnt ;
4807- cur .skipped += thread [i ].stats .skipped ;
4803+ mergeSimpleStats (& cur .latency , & threads [i ].stats .latency );
4804+ mergeSimpleStats (& cur .lag , & threads [i ].stats .lag );
4805+ cur .cnt += threads [i ].stats .cnt ;
4806+ cur .skipped += threads [i ].stats .skipped ;
48084807 }
48094808
48104809 /* we count only actually executed transactions */
@@ -4874,7 +4873,7 @@ printSimpleStats(const char *prefix, SimpleStats *ss)
48744873
48754874/* print out results */
48764875static void
4877- printResults (TState * threads , StatsData * total , instr_time total_time ,
4876+ printResults (StatsData * total , instr_time total_time ,
48784877 instr_time conn_total_time , int64 latency_late )
48794878{
48804879 double time_include ,
@@ -5887,7 +5886,7 @@ main(int argc, char **argv)
58875886 */
58885887 INSTR_TIME_SET_CURRENT (total_time );
58895888 INSTR_TIME_SUBTRACT (total_time , start_time );
5890- printResults (threads , & stats , total_time , conn_total_time , latency_late );
5889+ printResults (& stats , total_time , conn_total_time , latency_late );
58915890
58925891 if (exit_code != 0 )
58935892 fprintf (stderr , "Run was aborted; the above results are incomplete.\n" );
@@ -6146,7 +6145,14 @@ threadRun(void *arg)
61466145 now = INSTR_TIME_GET_MICROSEC (now_time );
61476146 if (now >= next_report )
61486147 {
6149- printProgressReport (thread , thread_start , now , & last , & last_report );
6148+ /*
6149+ * Horrible hack: this relies on the thread pointer we are
6150+ * passed to be equivalent to threads[0], that is the first
6151+ * entry of the threads array. That is why this MUST be done
6152+ * by thread 0 and not any other.
6153+ */
6154+ printProgressReport (thread , thread_start , now ,
6155+ & last , & last_report );
61506156
61516157 /*
61526158 * Ensure that the next report is in the future, in case
0 commit comments