Try to fix portability bugs in recent pgbench commits.
authorThomas Munro <tmunro@postgresql.org>
Wed, 10 Mar 2021 07:18:15 +0000 (20:18 +1300)
committerThomas Munro <tmunro@postgresql.org>
Wed, 10 Mar 2021 08:12:11 +0000 (21:12 +1300)
1.  pg_time_usec_t needs to be printed with INT64_FORMAT, not %ld, or 32
bit systems complain, per lapwing.

2.  Some Windows compilers didn't like a thread function not marked with
__stdcall, per whelk; let's see if this fixes the problem.

src/bin/pgbench/pgbench.c

index c0d2a124a92744eb8b2d52185658a6a771595852..e4dfbcf4720c3819732ca65b28d487e5e7d2b40c 100644 (file)
@@ -121,6 +121,7 @@ typedef struct socket_set
 #define THREAD_T HANDLE
 #define THREAD_FUNC_RETURN_TYPE unsigned
 #define THREAD_FUNC_RETURN return 0
+#define THREAD_FUNC_CC __stdcall
 #define THREAD_CREATE(handle, function, arg) \
    ((*(handle) = (HANDLE) _beginthreadex(NULL, 0, (function), (arg), 0, NULL)) == 0 ? errno : 0)
 #define THREAD_JOIN(handle) \
@@ -139,6 +140,7 @@ typedef struct socket_set
 #define THREAD_T pthread_t
 #define THREAD_FUNC_RETURN_TYPE void *
 #define THREAD_FUNC_RETURN return NULL
+#define THREAD_FUNC_CC
 #define THREAD_CREATE(handle, function, arg) \
    pthread_create((handle), NULL, (function), (arg))
 #define THREAD_JOIN(handle) \
@@ -153,6 +155,7 @@ typedef struct socket_set
 #define THREAD_T void *
 #define THREAD_FUNC_RETURN_TYPE void *
 #define THREAD_FUNC_RETURN return NULL
+#define THREAD_FUNC_CC
 #define THREAD_BARRIER_T int
 #define THREAD_BARRIER_INIT(barrier, n) (*(barrier) = 0)
 #define THREAD_BARRIER_WAIT(barrier)
@@ -639,7 +642,7 @@ static void doLog(TState *thread, CState *st,
 static void processXactStats(TState *thread, CState *st, pg_time_usec_t *now,
                             bool skipped, StatsData *agg);
 static void addScript(ParsedScript script);
-static THREAD_FUNC_RETURN_TYPE threadRun(void *arg);
+static THREAD_FUNC_RETURN_TYPE THREAD_FUNC_CC threadRun(void *arg);
 static void finishCon(CState *st);
 static void setalarm(int seconds);
 static socket_set *alloc_socket_set(int count);
@@ -3565,10 +3568,12 @@ doLog(TState *thread, CState *st,
    {
        /* no, print raw transactions */
        if (skipped)
-           fprintf(logfile, "%d " INT64_FORMAT " skipped %d %ld %ld",
+           fprintf(logfile, "%d " INT64_FORMAT " skipped %d " INT64_FORMAT " "
+                   INT64_FORMAT,
                    st->id, st->cnt, st->use_file, now / 1000000, now % 1000000);
        else
-           fprintf(logfile, "%d " INT64_FORMAT " %.0f %d %ld %ld",
+           fprintf(logfile, "%d " INT64_FORMAT " %.0f %d " INT64_FORMAT " "
+                   INT64_FORMAT,
                    st->id, st->cnt, latency, st->use_file,
                    now / 1000000, now % 1000000);
        if (throttle_delay)
@@ -6222,7 +6227,7 @@ main(int argc, char **argv)
    return exit_code;
 }
 
-static THREAD_FUNC_RETURN_TYPE
+static THREAD_FUNC_RETURN_TYPE THREAD_FUNC_CC
 threadRun(void *arg)
 {
    TState     *thread = (TState *) arg;