Header And Logo

PostgreSQL
| The world's most advanced open source database.

thread-alloc.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* End of automatic include section */
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008 
00009 #line 1 "alloc.pgc"
00010 #include <stdlib.h>
00011 #include "ecpg_config.h"
00012 
00013 #ifndef ENABLE_THREAD_SAFETY
00014 int
00015 main(void)
00016 {
00017     printf("No threading enabled.\n");
00018     return 0;
00019 }
00020 #else
00021 #ifdef WIN32
00022 #define WIN32_LEAN_AND_MEAN
00023 #include <windows.h>
00024 #include <process.h>
00025 #else
00026 #include <pthread.h>
00027 #endif
00028 #include <stdio.h>
00029 
00030 #define THREADS     16
00031 #define REPEATS     50
00032 
00033 
00034 #line 1 "sqlca.h"
00035 #ifndef POSTGRES_SQLCA_H
00036 #define POSTGRES_SQLCA_H
00037 
00038 #ifndef PGDLLIMPORT
00039 #if  defined(WIN32) || defined(__CYGWIN__)
00040 #define PGDLLIMPORT __declspec (dllimport)
00041 #else
00042 #define PGDLLIMPORT
00043 #endif   /* __CYGWIN__ */
00044 #endif   /* PGDLLIMPORT */
00045 
00046 #define SQLERRMC_LEN    150
00047 
00048 #ifdef __cplusplus
00049 extern      "C"
00050 {
00051 #endif
00052 
00053 struct sqlca_t
00054 {
00055     char        sqlcaid[8];
00056     long        sqlabc;
00057     long        sqlcode;
00058     struct
00059     {
00060         int         sqlerrml;
00061         char        sqlerrmc[SQLERRMC_LEN];
00062     }           sqlerrm;
00063     char        sqlerrp[8];
00064     long        sqlerrd[6];
00065     /* Element 0: empty                     */
00066     /* 1: OID of processed tuple if applicable          */
00067     /* 2: number of rows processed              */
00068     /* after an INSERT, UPDATE or               */
00069     /* DELETE statement                 */
00070     /* 3: empty                     */
00071     /* 4: empty                     */
00072     /* 5: empty                     */
00073     char        sqlwarn[8];
00074     /* Element 0: set to 'W' if at least one other is 'W'   */
00075     /* 1: if 'W' at least one character string      */
00076     /* value was truncated when it was          */
00077     /* stored into a host variable.             */
00078 
00079     /*
00080      * 2: if 'W' a (hopefully) non-fatal notice occurred
00081      */ /* 3: empty */
00082     /* 4: empty                     */
00083     /* 5: empty                     */
00084     /* 6: empty                     */
00085     /* 7: empty                     */
00086 
00087     char        sqlstate[5];
00088 };
00089 
00090 struct sqlca_t *ECPGget_sqlca(void);
00091 
00092 #ifndef POSTGRES_ECPG_INTERNAL
00093 #define sqlca (*ECPGget_sqlca())
00094 #endif
00095 
00096 #ifdef __cplusplus
00097 }
00098 #endif
00099 
00100 #endif
00101 
00102 #line 24 "alloc.pgc"
00103 
00104 
00105 #line 1 "regression.h"
00106 
00107 
00108 
00109 
00110 
00111 
00112 #line 25 "alloc.pgc"
00113 
00114 
00115 /* exec sql whenever sqlerror  sqlprint ; */
00116 #line 27 "alloc.pgc"
00117 
00118 /* exec sql whenever not found  sqlprint ; */
00119 #line 28 "alloc.pgc"
00120 
00121 
00122 #ifdef WIN32
00123 static unsigned __stdcall fn(void* arg)
00124 #else
00125 static void* fn(void* arg)
00126 #endif
00127 {
00128     int i;
00129 
00130     /* exec sql begin declare section */
00131       
00132      
00133        
00134     
00135 #line 39 "alloc.pgc"
00136  int value ;
00137  
00138 #line 40 "alloc.pgc"
00139  char name [ 100 ] ;
00140  
00141 #line 41 "alloc.pgc"
00142  char ** r = NULL ;
00143 /* exec sql end declare section */
00144 #line 42 "alloc.pgc"
00145 
00146 
00147     value = (long)arg;
00148     sprintf(name, "Connection: %d", value);
00149 
00150     { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , name, 0); 
00151 #line 47 "alloc.pgc"
00152 
00153 if (sqlca.sqlcode < 0) sqlprint();}
00154 #line 47 "alloc.pgc"
00155 
00156     { ECPGsetcommit(__LINE__, "on", NULL);
00157 #line 48 "alloc.pgc"
00158 
00159 if (sqlca.sqlcode < 0) sqlprint();}
00160 #line 48 "alloc.pgc"
00161 
00162     for (i = 1; i <= REPEATS; ++i)
00163     {
00164         { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT, 
00165     ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char), 
00166     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00167 #line 51 "alloc.pgc"
00168 
00169 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
00170 #line 51 "alloc.pgc"
00171 
00172 if (sqlca.sqlcode < 0) sqlprint();}
00173 #line 51 "alloc.pgc"
00174 
00175         free(r);
00176         r = NULL;
00177     }
00178     { ECPGdisconnect(__LINE__, name);
00179 #line 55 "alloc.pgc"
00180 
00181 if (sqlca.sqlcode < 0) sqlprint();}
00182 #line 55 "alloc.pgc"
00183 
00184 
00185     return 0;
00186 }
00187 
00188 int main ()
00189 {
00190     int i;
00191 #ifdef WIN32
00192     HANDLE threads[THREADS];
00193 #else
00194     pthread_t threads[THREADS];
00195 #endif
00196 
00197 #ifdef WIN32
00198     for (i = 0; i < THREADS; ++i)
00199     {
00200         unsigned id;
00201         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
00202     }
00203 
00204     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
00205     for (i = 0; i < THREADS; ++i)
00206         CloseHandle(threads[i]);
00207 #else
00208     for (i = 0; i < THREADS; ++i)
00209         pthread_create(&threads[i], NULL, fn, (void *) (long) i);
00210     for (i = 0; i < THREADS; ++i)
00211         pthread_join(threads[i], NULL);
00212 #endif
00213 
00214     return 0;
00215 }
00216 #endif