---
mingw-w64-libraries/winpthreads/src/misc.h | 27 +++++++++++++++-----
mingw-w64-libraries/winpthreads/src/thread.c | 11 +++-----
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/mingw-w64-libraries/winpthreads/src/misc.h
b/mingw-w64-libraries/winpthreads/src/misc.h
index f954ad451c14..109cdf1c5801 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.h
+++ b/mingw-w64-libraries/winpthreads/src/misc.h
@@ -40,13 +40,28 @@ typedef long LONGBAG;
#define GetHandleInformation(h,f) (1)
#endif
-#define CHECK_HANDLE(h) \
+/* For gcc and clang define DUMMY_WRITABLE_DWORD as C99 compound literal.
+ * For other pre-C99 compilers declare DUMMY_WRITABLE_DWORD as static variable.
+ */
+#if defined(__GNUC__) || defined(__clang__)
+#define DUMMY_WRITABLE_DWORD (DWORD){0}
+#else
+static DWORD DUMMY_WRITABLE_DWORD;
+#endif
+
+#define TEST_HANDLE(h) \
+ (((h) != NULL && (h) != INVALID_HANDLE_VALUE) && ( \
+ GetHandleInformation((h), &DUMMY_WRITABLE_DWORD) \
+ ))
+
+#define CHECK_HANDLE2(h, e) \
do { \
- DWORD dwFlags; \
- if (!(h) || ((h) == INVALID_HANDLE_VALUE) || !GetHandleInformation((h),
&dwFlags)) \
- return EINVAL; \
+ if (!TEST_HANDLE(h)) \
+ return e; \
} while (0)
+#define CHECK_HANDLE(h) CHECK_HANDLE2(h, EINVAL)
+
#define CHECK_PTR(p) do { if (!(p)) return EINVAL; } while (0)
#define UPD_RESULT(x,r) do { int _r = (x); (r) = (r) ? (r) : _r; } while (0)
@@ -59,10 +74,8 @@ typedef long LONGBAG;
#define CHECK_OBJECT(o, e) \
do { \
- DWORD dwFlags; \
if (!(o)) return e; \
- if (!((o)->h) || (((o)->h) == INVALID_HANDLE_VALUE) ||
!GetHandleInformation(((o)->h), &dwFlags)) \
- return e; \
+ CHECK_HANDLE2((o)->h, e); \
} while (0)
#define VALID(x) if (!(p)) return EINVAL;
diff --git a/mingw-w64-libraries/winpthreads/src/thread.c
b/mingw-w64-libraries/winpthreads/src/thread.c
index 0a5e909a4422..173e0666c15c 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -1727,12 +1727,11 @@ pthread_create (pthread_t *th, const pthread_attr_t
*attr, void *(* func)(void *
int
pthread_join (pthread_t t, void **res)
{
- DWORD dwFlags;
struct _pthread_v *tv = __pth_gpointer_locked (t);
pthread_spinlock_t new_spin_keys = PTHREAD_SPINLOCK_INITIALIZER;
- if (!tv || tv->h == NULL || !GetHandleInformation(tv->h, &dwFlags))
- return ESRCH;
+ CHECK_OBJECT(tv, ESRCH);
+
if ((tv->p_state & PTHREAD_CREATE_DETACHED) != 0)
return EINVAL;
if (pthread_equal(pthread_self(), t))
@@ -1758,14 +1757,13 @@ pthread_join (pthread_t t, void **res)
int
_pthread_tryjoin (pthread_t t, void **res)
{
- DWORD dwFlags;
struct _pthread_v *tv;
pthread_spinlock_t new_spin_keys = PTHREAD_SPINLOCK_INITIALIZER;
pthread_mutex_lock (&mtx_pthr_locked);
tv = __pthread_get_pointer (t);
- if (!tv || tv->h == NULL || !GetHandleInformation(tv->h, &dwFlags))
+ if (!tv || !TEST_HANDLE(tv->h))
{
pthread_mutex_unlock (&mtx_pthr_locked);
return ESRCH;
@@ -1812,13 +1810,12 @@ int
pthread_detach (pthread_t t)
{
int r = 0;
- DWORD dwFlags;
struct _pthread_v *tv = __pth_gpointer_locked (t);
HANDLE dw;
pthread_spinlock_t new_spin_keys = PTHREAD_SPINLOCK_INITIALIZER;
pthread_mutex_lock (&mtx_pthr_locked);
- if (!tv || tv->h == NULL || !GetHandleInformation(tv->h, &dwFlags))
+ if (!tv || !TEST_HANDLE(tv->h))
{
pthread_mutex_unlock (&mtx_pthr_locked);
return ESRCH;
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public