Thread: [Patch] Use internal pthreads reimplementation only when buildingwith MSVC

[Patch] Use internal pthreads reimplementation only when buildingwith MSVC

From
Sandro Mani
Date:
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




Re: [Patch] Use internal pthreads reimplementation only whenbuilding with MSVC

From
Alvaro Herrera
Date:
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



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

From
Daniel Gustafsson
Date:
> 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


Attachment

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

From
Daniel Gustafsson
Date:
> 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