]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
mythread.h: Make MYTHREAD_POSIX compatible with MinGW-w64's winpthreads.
authorLasse Collin <lasse.collin@tukaani.org>
Sun, 24 Sep 2023 22:39:26 +0000 (01:39 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Sun, 22 Oct 2023 15:59:45 +0000 (18:59 +0300)
This might be almost useless but it doesn't need much extra code either.

src/common/mythread.h

index 4495e017b290926ea72b19f5f78abc924662a8d7..7be94567eb2472169c0637bc62b43adcce20e5b6 100644 (file)
@@ -112,6 +112,25 @@ mythread_sigmask(int how, const sigset_t *restrict set,
 #      include <sys/time.h>
 #endif
 
+// MinGW-w64 with winpthreads:
+//
+// NOTE: Typical builds with MinGW-w64 don't use this code (MYTHREAD_POSIX).
+// Instead, native Windows threading APIs are used (MYTHREAD_VISTA or
+// MYTHREAD_WIN95).
+//
+// MinGW-w64 has _sigset_t (an integer type) in <sys/types.h>.
+// If _POSIX was #defined, the header would add the alias sigset_t too.
+// Let's keep this working even without _POSIX.
+//
+// There are no functions that actually do something with sigset_t
+// because signals barely exist on Windows. The sigfillset macro below
+// is just to silence warnings. There is no sigfillset() in MinGW-w64.
+#ifdef __MINGW32__
+#      include <sys/types.h>
+#      define sigset_t _sigset_t
+#      define sigfillset(set_ptr) do { *(set_ptr) = 0; } while (0)
+#endif
+
 #define MYTHREAD_RET_TYPE void *
 #define MYTHREAD_RET_VALUE NULL
 
@@ -140,11 +159,13 @@ typedef struct timespec mythread_condtime;
 
 // Use pthread_sigmask() to set the signal mask in multi-threaded programs.
 // Do nothing on OpenVMS since it lacks pthread_sigmask().
+// Do nothing on MinGW-w64 too to silence warnings (its pthread_sigmask()
+// is #defined to 0 so it's a no-op).
 static inline void
 mythread_sigmask(int how, const sigset_t *restrict set,
                sigset_t *restrict oset)
 {
-#ifdef __VMS
+#if defined(__VMS) || defined(__MINGW32__)
        (void)how;
        (void)set;
        (void)oset;