Header And Logo

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

thread-descriptor.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 "descriptor.pgc"
00010 #ifdef ENABLE_THREAD_SAFETY
00011 #ifdef WIN32
00012 #define WIN32_LEAN_AND_MEAN
00013 #include <windows.h>
00014 #include <process.h>
00015 #else
00016 #include <pthread.h>
00017 #endif
00018 #endif
00019 #include <stdio.h>
00020 
00021 #define THREADS     16
00022 #define REPEATS     50000
00023 
00024 
00025 #line 1 "sqlca.h"
00026 #ifndef POSTGRES_SQLCA_H
00027 #define POSTGRES_SQLCA_H
00028 
00029 #ifndef PGDLLIMPORT
00030 #if  defined(WIN32) || defined(__CYGWIN__)
00031 #define PGDLLIMPORT __declspec (dllimport)
00032 #else
00033 #define PGDLLIMPORT
00034 #endif   /* __CYGWIN__ */
00035 #endif   /* PGDLLIMPORT */
00036 
00037 #define SQLERRMC_LEN    150
00038 
00039 #ifdef __cplusplus
00040 extern      "C"
00041 {
00042 #endif
00043 
00044 struct sqlca_t
00045 {
00046     char        sqlcaid[8];
00047     long        sqlabc;
00048     long        sqlcode;
00049     struct
00050     {
00051         int         sqlerrml;
00052         char        sqlerrmc[SQLERRMC_LEN];
00053     }           sqlerrm;
00054     char        sqlerrp[8];
00055     long        sqlerrd[6];
00056     /* Element 0: empty                     */
00057     /* 1: OID of processed tuple if applicable          */
00058     /* 2: number of rows processed              */
00059     /* after an INSERT, UPDATE or               */
00060     /* DELETE statement                 */
00061     /* 3: empty                     */
00062     /* 4: empty                     */
00063     /* 5: empty                     */
00064     char        sqlwarn[8];
00065     /* Element 0: set to 'W' if at least one other is 'W'   */
00066     /* 1: if 'W' at least one character string      */
00067     /* value was truncated when it was          */
00068     /* stored into a host variable.             */
00069 
00070     /*
00071      * 2: if 'W' a (hopefully) non-fatal notice occurred
00072      */ /* 3: empty */
00073     /* 4: empty                     */
00074     /* 5: empty                     */
00075     /* 6: empty                     */
00076     /* 7: empty                     */
00077 
00078     char        sqlstate[5];
00079 };
00080 
00081 struct sqlca_t *ECPGget_sqlca(void);
00082 
00083 #ifndef POSTGRES_ECPG_INTERNAL
00084 #define sqlca (*ECPGget_sqlca())
00085 #endif
00086 
00087 #ifdef __cplusplus
00088 }
00089 #endif
00090 
00091 #endif
00092 
00093 #line 15 "descriptor.pgc"
00094 
00095 /* exec sql whenever sqlerror  sqlprint ; */
00096 #line 16 "descriptor.pgc"
00097 
00098 /* exec sql whenever not found  sqlprint ; */
00099 #line 17 "descriptor.pgc"
00100 
00101 
00102 #if defined(ENABLE_THREAD_SAFETY) && defined(WIN32)
00103 static unsigned __stdcall fn(void* arg)
00104 #else
00105 static void* fn(void* arg)
00106 #endif
00107 {
00108     int i;
00109 
00110     for (i = 1; i <= REPEATS; ++i)
00111     {
00112         ECPGallocate_desc(__LINE__, "mydesc");
00113 #line 29 "descriptor.pgc"
00114 
00115 if (sqlca.sqlcode < 0) sqlprint();
00116 #line 29 "descriptor.pgc"
00117 
00118         ECPGdeallocate_desc(__LINE__, "mydesc");
00119 #line 30 "descriptor.pgc"
00120 
00121 if (sqlca.sqlcode < 0) sqlprint();
00122 #line 30 "descriptor.pgc"
00123 
00124     }
00125 
00126     return 0;
00127 }
00128 
00129 int main ()
00130 {
00131 #ifdef ENABLE_THREAD_SAFETY
00132     int i;
00133 #ifdef WIN32
00134     HANDLE threads[THREADS];
00135 #else
00136     pthread_t threads[THREADS];
00137 #endif
00138 
00139 #ifdef WIN32
00140     for (i = 0; i < THREADS; ++i)
00141     {
00142         unsigned id;
00143         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, NULL, 0, &id);
00144     }
00145 
00146     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
00147     for (i = 0; i < THREADS; ++i)
00148         CloseHandle(threads[i]);
00149 #else
00150     for (i = 0; i < THREADS; ++i)
00151         pthread_create(&threads[i], NULL, fn, NULL);
00152     for (i = 0; i < THREADS; ++i)
00153         pthread_join(threads[i], NULL);
00154 #endif
00155 #else
00156     fn(NULL);
00157 #endif
00158 
00159     return 0;
00160 }