[Patch] Use internal pthreads reimplementation only when building with MSVC

Started by Sandro Manialmost 6 years ago4 messages
#1Sandro Mani
manisandro@gmail.com

Hi

The following patch, which we added to build mingw-postgresql on Fedora,
makes the internal minimal pthreads reimplementation only used when
building with MSVC, as on MINGW it causes symbol collisions with the
symbols provided my winpthreads.

Thanks
Sandro

diff -rupN postgresql-11.5/src/interfaces/ecpg/ecpglib/misc.c 
postgresql-11.5-new/src/interfaces/ecpg/ecpglib/misc.c
--- postgresql-11.5/src/interfaces/ecpg/ecpglib/misc.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/ecpg/ecpglib/misc.c 2020-04-08 
11:20:39.850738296 +0200
@@ -449,7 +449,7 @@ ECPGis_noind_null(enum ECPGttype type, c
      return false;
  }
-#ifdef WIN32
+#ifdef _MSC_VER
  #ifdef ENABLE_THREAD_SAFETY
  void
diff -rupN 
postgresql-11.5/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
postgresql-11.5-new/src/interfaces/ecpg/include/ecpg-pthread-win32.h
--- postgresql-11.5/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
2019-08-05 23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
2020-04-08 11:20:39.851738296 +0200
@@ -7,7 +7,7 @@

 #ifdef ENABLE_THREAD_SAFETY

-#ifndef WIN32
+#ifndef _MSC_VER
  #include <pthread.h>
  #else
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-connect.c 
postgresql-11.5-new/src/interfaces/libpq/fe-connect.c
--- postgresql-11.5/src/interfaces/libpq/fe-connect.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-connect.c 2020-04-08 
11:20:39.853738297 +0200
@@ -50,7 +50,7 @@
  #endif
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-secure.c 
postgresql-11.5-new/src/interfaces/libpq/fe-secure.c
--- postgresql-11.5/src/interfaces/libpq/fe-secure.c    2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-secure.c 2020-04-08 
11:20:39.854738297 +0200
@@ -48,7 +48,7 @@
  #include <sys/stat.h>
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-secure-openssl.c 
postgresql-11.5-new/src/interfaces/libpq/fe-secure-openssl.c
--- postgresql-11.5/src/interfaces/libpq/fe-secure-openssl.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-secure-openssl.c 
2020-04-08 11:20:39.855738298 +0200
@@ -47,7 +47,7 @@
  #include <sys/stat.h>
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/libpq-int.h 
postgresql-11.5-new/src/interfaces/libpq/libpq-int.h
--- postgresql-11.5/src/interfaces/libpq/libpq-int.h    2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/libpq-int.h 2020-04-08 
11:20:39.855738298 +0200
@@ -29,7 +29,7 @@
  #endif
  #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
  #include "pthread-win32.h"
  #else
  #include <pthread.h>
diff -rupN postgresql-11.5/src/interfaces/libpq/pthread-win32.c 
postgresql-11.5-new/src/interfaces/libpq/pthread-win32.c
--- postgresql-11.5/src/interfaces/libpq/pthread-win32.c 2019-08-05 
23:14:59.000000000 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/pthread-win32.c 2020-04-08 
11:21:51.674766968 +0200
@@ -10,10 +10,13 @@
  *-------------------------------------------------------------------------
  */
+#ifdef _MSC_VER
+
  #include "postgres_fe.h"

 #include "pthread-win32.h"

+
 DWORD
 pthread_self(void)
 {
@@ -58,3 +61,5 @@ pthread_mutex_unlock(pthread_mutex_t *mp
     LeaveCriticalSection(*mp);
     return 0;
 }
+
+#endif // _MSC_VER

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Sandro Mani (#1)
Re: [Patch] Use internal pthreads reimplementation only when building with MSVC

Hello,

On 2020-Apr-08, Sandro Mani wrote:

The following patch, which we added to build mingw-postgresql on Fedora,
makes the internal minimal pthreads reimplementation only used when building
with MSVC, as on MINGW it causes symbol collisions with the symbols provided
my winpthreads.

Are there any build-system tweaks needed to enable use of winpthreads?
If none are needed, why are all our mingw buildfarm members building
correctly? I suggest that if you want to maintain "mingw-postgresql
built on Fedora", it would be a good idea to have a buildfarm animal
that tests it on a recurring basis.

Please do submit patches as separate attachments rather than in the
email body.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Alvaro Herrera (#2)
1 attachment(s)
Re: [Patch] Use internal pthreads reimplementation only when building with MSVC

On 9 Apr 2020, at 23:57, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Please do submit patches as separate attachments rather than in the
email body.

Since the CF app is unable to see that there is a patch at all, I took the
liberty to resubmit the posted patch rebased on top of HEAD and with the C++
replaced with a C /* */ comment.

Marking this entry Waiting on Author based on Alvaros questions.

cheers ./daniel

Attachments:

msvc_pthreads.diffapplication/octet-stream; name=msvc_pthreads.diff; x-unix-mode=0644Download
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index a07d0dfb9f..cea5ed3c22 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -451,7 +451,7 @@ ECPGis_noind_null(enum ECPGttype type, const void *ptr)
 	return false;
 }
 
-#ifdef WIN32
+#ifdef _MSC_VER
 #ifdef ENABLE_THREAD_SAFETY
 
 void
diff --git a/src/interfaces/ecpg/include/ecpg-pthread-win32.h b/src/interfaces/ecpg/include/ecpg-pthread-win32.h
index 33c897b633..3c7cee0593 100644
--- a/src/interfaces/ecpg/include/ecpg-pthread-win32.h
+++ b/src/interfaces/ecpg/include/ecpg-pthread-win32.h
@@ -7,7 +7,7 @@
 
 #ifdef ENABLE_THREAD_SAFETY
 
-#ifndef WIN32
+#ifndef _MSC_VER
 
 #include <pthread.h>
 #else
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 27c9bb46ee..3f49e363a0 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -56,7 +56,7 @@
 #endif
 
 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include <pthread.h>
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index d609a38bbe..bbfc962800 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -48,7 +48,7 @@
 #include <sys/stat.h>
 
 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include <pthread.h>
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 3311fd7a5b..c9a40fcbc9 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -44,7 +44,7 @@
 #include <sys/stat.h>
 
 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include <pthread.h>
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 1de91ae295..b0b5995f65 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -29,7 +29,7 @@
 #endif
 
 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include <pthread.h>
diff --git a/src/interfaces/libpq/pthread-win32.c b/src/interfaces/libpq/pthread-win32.c
index fd801c1a21..0c4ddd0a1c 100644
--- a/src/interfaces/libpq/pthread-win32.c
+++ b/src/interfaces/libpq/pthread-win32.c
@@ -10,10 +10,13 @@
 *-------------------------------------------------------------------------
 */
 
+#ifdef _MSC_VER
+
 #include "postgres_fe.h"
 
 #include "pthread-win32.h"
 
+
 DWORD
 pthread_self(void)
 {
@@ -58,3 +61,5 @@ pthread_mutex_unlock(pthread_mutex_t *mp)
 	LeaveCriticalSection(*mp);
 	return 0;
 }
+
+#endif						/* _MSC_VER */
#4Daniel Gustafsson
daniel@yesql.se
In reply to: Daniel Gustafsson (#3)
Re: [Patch] Use internal pthreads reimplementation only when building with MSVC

On 2 Jul 2020, at 16:35, Daniel Gustafsson <daniel@yesql.se> wrote:

On 9 Apr 2020, at 23:57, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Please do submit patches as separate attachments rather than in the
email body.

Since the CF app is unable to see that there is a patch at all, I took the
liberty to resubmit the posted patch rebased on top of HEAD and with the C++
replaced with a C /* */ comment.

This version now applies and builds but..

Marking this entry Waiting on Author based on Alvaros questions.

..since the thread has stalled with no response to review questions I'm marking
this Returned with Feedback.

cheers ./daniel