mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Make ECPG regression tests use native threading instead of pthreads, now that
ecpglib supports it. Change configure (patch from Bruce) and msvc build system to no longer require pthreads on win32, since all parts of postgresql can be thread-safe using the native platform functions.
This commit is contained in:
@ -23,7 +23,11 @@ main(void)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
#line 1 "regression.h"
|
||||
@ -33,7 +37,7 @@ main(void)
|
||||
|
||||
|
||||
|
||||
#line 18 "thread.pgc"
|
||||
#line 22 "thread.pgc"
|
||||
|
||||
|
||||
void *test_thread(void *arg);
|
||||
@ -43,15 +47,19 @@ int iterations = 20;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_t *threads;
|
||||
#else
|
||||
HANDLE *threads;
|
||||
#endif
|
||||
int n;
|
||||
/* exec sql begin declare section */
|
||||
|
||||
|
||||
#line 30 "thread.pgc"
|
||||
#line 38 "thread.pgc"
|
||||
int l_rows ;
|
||||
/* exec sql end declare section */
|
||||
#line 31 "thread.pgc"
|
||||
#line 39 "thread.pgc"
|
||||
|
||||
|
||||
/* Do not switch on debug output for regression tests. The threads get executed in
|
||||
@ -60,26 +68,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* setup test_thread table */
|
||||
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
|
||||
#line 38 "thread.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 39 "thread.pgc"
|
||||
/* DROP might fail */
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 40 "thread.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "create table test_thread ( tstamp timestamp not null default cast( timeofday () as timestamp ) , thread TEXT not null , iteration integer not null , primary key( thread , iteration ) ) ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 45 "thread.pgc"
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 46 "thread.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");}
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 47 "thread.pgc"
|
||||
/* DROP might fail */
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 48 "thread.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "create table test_thread ( tstamp timestamp not null default cast( timeofday () as timestamp ) , thread TEXT not null , iteration integer not null , primary key( thread , iteration ) ) ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 53 "thread.pgc"
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 54 "thread.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");}
|
||||
#line 55 "thread.pgc"
|
||||
|
||||
|
||||
/* create, and start, threads */
|
||||
threads = calloc(nthreads, sizeof(pthread_t));
|
||||
threads = calloc(nthreads, sizeof(threads[0]));
|
||||
if( threads == NULL )
|
||||
{
|
||||
fprintf(stderr, "Cannot alloc memory\n");
|
||||
@ -87,30 +95,38 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
|
||||
#else
|
||||
threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_thread, (void *) (n + 1), 0, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* wait for thread completion */
|
||||
#ifndef WIN32
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
pthread_join(threads[n], NULL);
|
||||
}
|
||||
#else
|
||||
WaitForMultipleObjects(nthreads, threads, TRUE, INFINITE);
|
||||
#endif
|
||||
free(threads);
|
||||
|
||||
/* and check results */
|
||||
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
|
||||
#line 69 "thread.pgc"
|
||||
#line 85 "thread.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "select count (*) from test_thread ", ECPGt_EOIT,
|
||||
ECPGt_int,&(l_rows),(long)1,(long)1,sizeof(int),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
||||
#line 70 "thread.pgc"
|
||||
#line 86 "thread.pgc"
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 71 "thread.pgc"
|
||||
#line 87 "thread.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");}
|
||||
#line 72 "thread.pgc"
|
||||
#line 88 "thread.pgc"
|
||||
|
||||
if( l_rows == (nthreads * iterations) )
|
||||
printf("Success.\n");
|
||||
@ -127,25 +143,25 @@ void *test_thread(void *arg)
|
||||
|
||||
|
||||
|
||||
#line 85 "thread.pgc"
|
||||
#line 101 "thread.pgc"
|
||||
int l_i ;
|
||||
|
||||
#line 86 "thread.pgc"
|
||||
#line 102 "thread.pgc"
|
||||
char l_connection [ 128 ] ;
|
||||
/* exec sql end declare section */
|
||||
#line 87 "thread.pgc"
|
||||
#line 103 "thread.pgc"
|
||||
|
||||
|
||||
/* build up connection name, and connect to database */
|
||||
snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum);
|
||||
/* exec sql whenever sqlerror sqlprint ; */
|
||||
#line 91 "thread.pgc"
|
||||
#line 107 "thread.pgc"
|
||||
|
||||
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , l_connection, 0);
|
||||
#line 92 "thread.pgc"
|
||||
#line 108 "thread.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 92 "thread.pgc"
|
||||
#line 108 "thread.pgc"
|
||||
|
||||
if( sqlca.sqlcode != 0 )
|
||||
{
|
||||
@ -153,10 +169,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
return( NULL );
|
||||
}
|
||||
{ ECPGtrans(__LINE__, l_connection, "begin transaction ");
|
||||
#line 98 "thread.pgc"
|
||||
#line 114 "thread.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 98 "thread.pgc"
|
||||
#line 114 "thread.pgc"
|
||||
|
||||
|
||||
/* insert into test_thread table */
|
||||
@ -167,10 +183,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_int,&(l_i),(long)1,(long)1,sizeof(int),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 103 "thread.pgc"
|
||||
#line 119 "thread.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 103 "thread.pgc"
|
||||
#line 119 "thread.pgc"
|
||||
|
||||
if( sqlca.sqlcode != 0 )
|
||||
printf("%s: ERROR: insert failed!\n", l_connection);
|
||||
@ -178,16 +194,16 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
/* all done */
|
||||
{ ECPGtrans(__LINE__, l_connection, "commit");
|
||||
#line 109 "thread.pgc"
|
||||
#line 125 "thread.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 109 "thread.pgc"
|
||||
#line 125 "thread.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, l_connection);
|
||||
#line 110 "thread.pgc"
|
||||
#line 126 "thread.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 110 "thread.pgc"
|
||||
#line 126 "thread.pgc"
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
@ -24,7 +24,11 @@ main(void)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
#line 1 "regression.h"
|
||||
@ -34,7 +38,7 @@ main(void)
|
||||
|
||||
|
||||
|
||||
#line 19 "thread_implicit.pgc"
|
||||
#line 23 "thread_implicit.pgc"
|
||||
|
||||
|
||||
void *test_thread(void *arg);
|
||||
@ -44,15 +48,19 @@ int iterations = 20;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_t *threads;
|
||||
#else
|
||||
HANDLE *threads;
|
||||
#endif
|
||||
int n;
|
||||
/* exec sql begin declare section */
|
||||
|
||||
|
||||
#line 31 "thread_implicit.pgc"
|
||||
#line 39 "thread_implicit.pgc"
|
||||
int l_rows ;
|
||||
/* exec sql end declare section */
|
||||
#line 32 "thread_implicit.pgc"
|
||||
#line 40 "thread_implicit.pgc"
|
||||
|
||||
|
||||
/* Do not switch on debug output for regression tests. The threads get executed in
|
||||
@ -61,26 +69,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* setup test_thread table */
|
||||
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
|
||||
#line 39 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 40 "thread_implicit.pgc"
|
||||
/* DROP might fail */
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 41 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "create table test_thread ( tstamp timestamp not null default cast( timeofday () as timestamp ) , thread TEXT not null , iteration integer not null , primary key( thread , iteration ) ) ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 46 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 47 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");}
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 48 "thread_implicit.pgc"
|
||||
/* DROP might fail */
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 49 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "create table test_thread ( tstamp timestamp not null default cast( timeofday () as timestamp ) , thread TEXT not null , iteration integer not null , primary key( thread , iteration ) ) ", ECPGt_EOIT, ECPGt_EORT);}
|
||||
#line 54 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 55 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");}
|
||||
#line 56 "thread_implicit.pgc"
|
||||
|
||||
|
||||
/* create, and start, threads */
|
||||
threads = calloc(nthreads, sizeof(pthread_t));
|
||||
threads = calloc(nthreads, sizeof(threads[0]));
|
||||
if( threads == NULL )
|
||||
{
|
||||
fprintf(stderr, "Cannot alloc memory\n");
|
||||
@ -88,30 +96,38 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
|
||||
#else
|
||||
threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_thread, (void *) (n+1), 0, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* wait for thread completion */
|
||||
#ifndef WIN32
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
pthread_join(threads[n], NULL);
|
||||
}
|
||||
#else
|
||||
WaitForMultipleObjects(nthreads, threads, TRUE, INFINITE);
|
||||
#endif
|
||||
free(threads);
|
||||
|
||||
/* and check results */
|
||||
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
|
||||
#line 70 "thread_implicit.pgc"
|
||||
#line 86 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "select count (*) from test_thread ", ECPGt_EOIT,
|
||||
ECPGt_int,&(l_rows),(long)1,(long)1,sizeof(int),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
||||
#line 71 "thread_implicit.pgc"
|
||||
#line 87 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");}
|
||||
#line 72 "thread_implicit.pgc"
|
||||
#line 88 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");}
|
||||
#line 73 "thread_implicit.pgc"
|
||||
#line 89 "thread_implicit.pgc"
|
||||
|
||||
if( l_rows == (nthreads * iterations) )
|
||||
printf("Success.\n");
|
||||
@ -128,25 +144,25 @@ void *test_thread(void *arg)
|
||||
|
||||
|
||||
|
||||
#line 86 "thread_implicit.pgc"
|
||||
#line 102 "thread_implicit.pgc"
|
||||
int l_i ;
|
||||
|
||||
#line 87 "thread_implicit.pgc"
|
||||
#line 103 "thread_implicit.pgc"
|
||||
char l_connection [ 128 ] ;
|
||||
/* exec sql end declare section */
|
||||
#line 88 "thread_implicit.pgc"
|
||||
#line 104 "thread_implicit.pgc"
|
||||
|
||||
|
||||
/* build up connection name, and connect to database */
|
||||
snprintf(l_connection, sizeof(l_connection), "thread_%03ld", threadnum);
|
||||
/* exec sql whenever sqlerror sqlprint ; */
|
||||
#line 92 "thread_implicit.pgc"
|
||||
#line 108 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , l_connection, 0);
|
||||
#line 93 "thread_implicit.pgc"
|
||||
#line 109 "thread_implicit.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 93 "thread_implicit.pgc"
|
||||
#line 109 "thread_implicit.pgc"
|
||||
|
||||
if( sqlca.sqlcode != 0 )
|
||||
{
|
||||
@ -154,10 +170,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
return( NULL );
|
||||
}
|
||||
{ ECPGtrans(__LINE__, NULL, "begin transaction ");
|
||||
#line 99 "thread_implicit.pgc"
|
||||
#line 115 "thread_implicit.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 99 "thread_implicit.pgc"
|
||||
#line 115 "thread_implicit.pgc"
|
||||
|
||||
|
||||
/* insert into test_thread table */
|
||||
@ -168,10 +184,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_int,&(l_i),(long)1,(long)1,sizeof(int),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 104 "thread_implicit.pgc"
|
||||
#line 120 "thread_implicit.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 104 "thread_implicit.pgc"
|
||||
#line 120 "thread_implicit.pgc"
|
||||
|
||||
if( sqlca.sqlcode != 0 )
|
||||
printf("%s: ERROR: insert failed!\n", l_connection);
|
||||
@ -179,16 +195,16 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
/* all done */
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");
|
||||
#line 110 "thread_implicit.pgc"
|
||||
#line 126 "thread_implicit.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 110 "thread_implicit.pgc"
|
||||
#line 126 "thread_implicit.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, l_connection);
|
||||
#line 111 "thread_implicit.pgc"
|
||||
#line 127 "thread_implicit.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 111 "thread_implicit.pgc"
|
||||
#line 127 "thread_implicit.pgc"
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
@ -13,7 +13,11 @@ main(void)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
exec sql include ../regression;
|
||||
|
||||
@ -24,7 +28,11 @@ int iterations = 20;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_t *threads;
|
||||
#else
|
||||
HANDLE *threads;
|
||||
#endif
|
||||
int n;
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
int l_rows;
|
||||
@ -47,7 +55,7 @@ int main(int argc, char *argv[])
|
||||
EXEC SQL DISCONNECT;
|
||||
|
||||
/* create, and start, threads */
|
||||
threads = calloc(nthreads, sizeof(pthread_t));
|
||||
threads = calloc(nthreads, sizeof(threads[0]));
|
||||
if( threads == NULL )
|
||||
{
|
||||
fprintf(stderr, "Cannot alloc memory\n");
|
||||
@ -55,14 +63,22 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
|
||||
#else
|
||||
threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)test_thread, (void *) (n + 1), 0, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* wait for thread completion */
|
||||
#ifndef WIN32
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
pthread_join(threads[n], NULL);
|
||||
}
|
||||
#else
|
||||
WaitForMultipleObjects(nthreads, threads, TRUE, INFINITE);
|
||||
#endif
|
||||
free(threads);
|
||||
|
||||
/* and check results */
|
||||
|
@ -14,7 +14,11 @@ main(void)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
exec sql include ../regression;
|
||||
|
||||
@ -25,7 +29,11 @@ int iterations = 20;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_t *threads;
|
||||
#else
|
||||
HANDLE *threads;
|
||||
#endif
|
||||
int n;
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
int l_rows;
|
||||
@ -48,7 +56,7 @@ int main(int argc, char *argv[])
|
||||
EXEC SQL DISCONNECT;
|
||||
|
||||
/* create, and start, threads */
|
||||
threads = calloc(nthreads, sizeof(pthread_t));
|
||||
threads = calloc(nthreads, sizeof(threads[0]));
|
||||
if( threads == NULL )
|
||||
{
|
||||
fprintf(stderr, "Cannot alloc memory\n");
|
||||
@ -56,14 +64,22 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
#ifndef WIN32
|
||||
pthread_create(&threads[n], NULL, test_thread, (void *) (n + 1));
|
||||
#else
|
||||
threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) test_thread, (void *) (n+1), 0, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* wait for thread completion */
|
||||
#ifndef WIN32
|
||||
for( n = 0; n < nthreads; n++ )
|
||||
{
|
||||
pthread_join(threads[n], NULL);
|
||||
}
|
||||
#else
|
||||
WaitForMultipleObjects(nthreads, threads, TRUE, INFINITE);
|
||||
#endif
|
||||
free(threads);
|
||||
|
||||
/* and check results */
|
||||
|
Reference in New Issue
Block a user