@@ -54,8 +54,8 @@ static bool parse_pair(const char buffer[], char key[], char value[]);
54
54
55
55
/* Connection routines */
56
56
static void init_cancel_handler (void );
57
- static void on_before_exec (PGconn * conn );
58
- static void on_after_exec (void );
57
+ static void on_before_exec (PGconn * conn , PGcancel * thread_cancel_conn );
58
+ static void on_after_exec (PGcancel * thread_cancel_conn );
59
59
static void on_interrupt (void );
60
60
static void on_cleanup (void );
61
61
static void exit_or_abort (int exitcode );
@@ -1512,7 +1512,7 @@ pgut_set_port(const char *new_port)
1512
1512
1513
1513
PGresult *
1514
1514
pgut_execute_parallel (PGconn * conn ,
1515
- PGconn * cancel_conn , const char * query ,
1515
+ PGcancel * thread_cancel_conn , const char * query ,
1516
1516
int nParams , const char * * params ,
1517
1517
bool text_result )
1518
1518
{
@@ -1540,7 +1540,7 @@ pgut_execute_parallel(PGconn* conn,
1540
1540
return NULL ;
1541
1541
}
1542
1542
1543
- // on_before_exec(conn);
1543
+ on_before_exec (conn , thread_cancel_conn );
1544
1544
if (nParams == 0 )
1545
1545
res = PQexec (conn , query );
1546
1546
else
@@ -1550,7 +1550,7 @@ pgut_execute_parallel(PGconn* conn,
1550
1550
* or one to obtain results in binary format.
1551
1551
*/
1552
1552
(text_result ) ? 0 : 1 );
1553
- // on_after_exec();
1553
+ on_after_exec (thread_cancel_conn );
1554
1554
1555
1555
switch (PQresultStatus (res ))
1556
1556
{
@@ -1594,7 +1594,7 @@ pgut_execute(PGconn* conn, const char *query, int nParams, const char **params,
1594
1594
return NULL ;
1595
1595
}
1596
1596
1597
- on_before_exec (conn );
1597
+ on_before_exec (conn , NULL );
1598
1598
if (nParams == 0 )
1599
1599
res = PQexec (conn , query );
1600
1600
else
@@ -1604,7 +1604,7 @@ pgut_execute(PGconn* conn, const char *query, int nParams, const char **params,
1604
1604
* or one to obtain results in binary format.
1605
1605
*/
1606
1606
(text_result ) ? 0 : 1 );
1607
- on_after_exec ();
1607
+ on_after_exec (NULL );
1608
1608
1609
1609
switch (PQresultStatus (res ))
1610
1610
{
@@ -1745,7 +1745,7 @@ static CRITICAL_SECTION cancelConnLock;
1745
1745
* Set cancel_conn to point to the current database connection.
1746
1746
*/
1747
1747
static void
1748
- on_before_exec (PGconn * conn )
1748
+ on_before_exec (PGconn * conn , PGcancel * thread_cancel_conn )
1749
1749
{
1750
1750
PGcancel * old ;
1751
1751
@@ -1756,16 +1756,32 @@ on_before_exec(PGconn *conn)
1756
1756
EnterCriticalSection (& cancelConnLock );
1757
1757
#endif
1758
1758
1759
- /* Free the old one if we have one */
1760
- old = cancel_conn ;
1759
+ if (thread_cancel_conn )
1760
+ {
1761
+ elog (WARNING , "Handle tread_cancel_conn. on_before_exec" );
1762
+ old = thread_cancel_conn ;
1763
+
1764
+ /* be sure handle_sigint doesn't use pointer while freeing */
1765
+ thread_cancel_conn = NULL ;
1766
+
1767
+ if (old != NULL )
1768
+ PQfreeCancel (old );
1769
+
1770
+ thread_cancel_conn = PQgetCancel (conn );
1771
+ }
1772
+ else
1773
+ {
1774
+ /* Free the old one if we have one */
1775
+ old = cancel_conn ;
1761
1776
1762
- /* be sure handle_sigint doesn't use pointer while freeing */
1763
- cancel_conn = NULL ;
1777
+ /* be sure handle_sigint doesn't use pointer while freeing */
1778
+ cancel_conn = NULL ;
1764
1779
1765
- if (old != NULL )
1766
- PQfreeCancel (old );
1780
+ if (old != NULL )
1781
+ PQfreeCancel (old );
1767
1782
1768
- cancel_conn = PQgetCancel (conn );
1783
+ cancel_conn = PQgetCancel (conn );
1784
+ }
1769
1785
1770
1786
#ifdef WIN32
1771
1787
LeaveCriticalSection (& cancelConnLock );
@@ -1778,7 +1794,7 @@ on_before_exec(PGconn *conn)
1778
1794
* Free the current cancel connection, if any, and set to NULL.
1779
1795
*/
1780
1796
static void
1781
- on_after_exec (void )
1797
+ on_after_exec (PGcancel * thread_cancel_conn )
1782
1798
{
1783
1799
PGcancel * old ;
1784
1800
@@ -1789,14 +1805,27 @@ on_after_exec(void)
1789
1805
EnterCriticalSection (& cancelConnLock );
1790
1806
#endif
1791
1807
1792
- old = cancel_conn ;
1808
+ if (thread_cancel_conn )
1809
+ {
1810
+ elog (WARNING , "Handle tread_cancel_conn. on_after_exec" );
1811
+ old = thread_cancel_conn ;
1793
1812
1794
- /* be sure handle_sigint doesn't use pointer while freeing */
1795
- cancel_conn = NULL ;
1813
+ /* be sure handle_sigint doesn't use pointer while freeing */
1814
+ thread_cancel_conn = NULL ;
1796
1815
1797
- if (old != NULL )
1798
- PQfreeCancel (old );
1816
+ if (old != NULL )
1817
+ PQfreeCancel (old );
1818
+ }
1819
+ else
1820
+ {
1821
+ old = cancel_conn ;
1822
+
1823
+ /* be sure handle_sigint doesn't use pointer while freeing */
1824
+ cancel_conn = NULL ;
1799
1825
1826
+ if (old != NULL )
1827
+ PQfreeCancel (old );
1828
+ }
1800
1829
#ifdef WIN32
1801
1830
LeaveCriticalSection (& cancelConnLock );
1802
1831
#endif
0 commit comments