PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
thread-alloc.c
Go to the documentation of this file.
1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8 
9 #line 1 "alloc.pgc"
10 #include <stdlib.h>
11 #include "ecpg_config.h"
12 
13 #ifndef ENABLE_THREAD_SAFETY
14 int
15 main(void)
16 {
17  printf("No threading enabled.\n");
18  return 0;
19 }
20 #else
21 #ifdef WIN32
22 #define WIN32_LEAN_AND_MEAN
23 #include <windows.h>
24 #include <process.h>
25 #else
26 #include <pthread.h>
27 #endif
28 #include <stdio.h>
29 
30 #define THREADS 16
31 #define REPEATS 50
32 
33 
34 #line 1 "sqlca.h"
35 #ifndef POSTGRES_SQLCA_H
36 #define POSTGRES_SQLCA_H
37 
38 #ifndef PGDLLIMPORT
39 #if defined(WIN32) || defined(__CYGWIN__)
40 #define PGDLLIMPORT __declspec (dllimport)
41 #else
42 #define PGDLLIMPORT
43 #endif /* __CYGWIN__ */
44 #endif /* PGDLLIMPORT */
45 
46 #define SQLERRMC_LEN 150
47 
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #endif
52 
53 struct sqlca_t
54 {
55  char sqlcaid[8];
56  long sqlabc;
57  long sqlcode;
58  struct
59  {
60  int sqlerrml;
61  char sqlerrmc[SQLERRMC_LEN];
62  } sqlerrm;
63  char sqlerrp[8];
64  long sqlerrd[6];
65  /* Element 0: empty */
66  /* 1: OID of processed tuple if applicable */
67  /* 2: number of rows processed */
68  /* after an INSERT, UPDATE or */
69  /* DELETE statement */
70  /* 3: empty */
71  /* 4: empty */
72  /* 5: empty */
73  char sqlwarn[8];
74  /* Element 0: set to 'W' if at least one other is 'W' */
75  /* 1: if 'W' at least one character string */
76  /* value was truncated when it was */
77  /* stored into a host variable. */
78 
79  /*
80  * 2: if 'W' a (hopefully) non-fatal notice occurred
81  */ /* 3: empty */
82  /* 4: empty */
83  /* 5: empty */
84  /* 6: empty */
85  /* 7: empty */
86 
87  char sqlstate[5];
88 };
89 
90 struct sqlca_t *ECPGget_sqlca(void);
91 
92 #ifndef POSTGRES_ECPG_INTERNAL
93 #define sqlca (*ECPGget_sqlca())
94 #endif
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif
101 
102 #line 24 "alloc.pgc"
103 
104 
105 #line 1 "regression.h"
106 
107 
108 
109 
110 
111 
112 #line 25 "alloc.pgc"
113 
114 
115 /* exec sql whenever sqlerror sqlprint ; */
116 #line 27 "alloc.pgc"
117 
118 /* exec sql whenever not found sqlprint ; */
119 #line 28 "alloc.pgc"
120 
121 
122 #ifdef WIN32
123 static unsigned __stdcall fn(void* arg)
124 #else
125 static void* fn(void* arg)
126 #endif
127 {
128  int i;
129 
130  /* exec sql begin declare section */
131 
132 
133 
134 
135 #line 39 "alloc.pgc"
136  int value ;
137 
138 #line 40 "alloc.pgc"
139  char name [ 100 ] ;
140 
141 #line 41 "alloc.pgc"
142  char ** r = NULL ;
143 /* exec sql end declare section */
144 #line 42 "alloc.pgc"
145 
146 
147  value = (long)arg;
148  sprintf(name, "Connection: %d", value);
149 
150  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , name, 0);
151 #line 47 "alloc.pgc"
152 
153 if (sqlca.sqlcode < 0) sqlprint();}
154 #line 47 "alloc.pgc"
155 
156  { ECPGsetcommit(__LINE__, "on", NULL);
157 #line 48 "alloc.pgc"
158 
159 if (sqlca.sqlcode < 0) sqlprint();}
160 #line 48 "alloc.pgc"
161 
162  for (i = 1; i <= REPEATS; ++i)
163  {
164  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select relname from pg_class where relname = 'pg_class'", ECPGt_EOIT,
165  ECPGt_char,&(r),(long)0,(long)0,(1)*sizeof(char),
166  ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
167 #line 51 "alloc.pgc"
168 
169 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
170 #line 51 "alloc.pgc"
171 
172 if (sqlca.sqlcode < 0) sqlprint();}
173 #line 51 "alloc.pgc"
174 
175  free(r);
176  r = NULL;
177  }
178  { ECPGdisconnect(__LINE__, name);
179 #line 55 "alloc.pgc"
180 
181 if (sqlca.sqlcode < 0) sqlprint();}
182 #line 55 "alloc.pgc"
183 
184 
185  return 0;
186 }
187 
188 int main ()
189 {
190  int i;
191 #ifdef WIN32
192  HANDLE threads[THREADS];
193 #else
194  pthread_t threads[THREADS];
195 #endif
196 
197 #ifdef WIN32
198  for (i = 0; i < THREADS; ++i)
199  {
200  unsigned id;
201  threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
202  }
203 
204  WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
205  for (i = 0; i < THREADS; ++i)
206  CloseHandle(threads[i]);
207 #else
208  for (i = 0; i < THREADS; ++i)
209  pthread_create(&threads[i], NULL, fn, (void *) (long) i);
210  for (i = 0; i < THREADS; ++i)
211  pthread_join(threads[i], NULL);
212 #endif
213 
214  return 0;
215 }
216 #endif
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
long sqlabc
Definition: sqlca.h:22
struct sqlca_t::@124 sqlerrm
#define sqlca
Definition: sqlca.h:59
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2030
char sqlwarn[8]
Definition: sqlca.h:39
#define THREADS
int sqlerrml
Definition: sqlca.h:26
char sqlcaid[8]
Definition: sqlca.h:21
int main(void)
Definition: thread-alloc.c:15
#define REPEATS
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
Definition: sqlca.h:19
long sqlerrd[6]
Definition: sqlca.h:30
char sqlstate[5]
Definition: sqlca.h:53
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
long sqlcode
Definition: sqlca.h:23
void sqlprint(void)
Definition: error.c:336
static void * fn(void *arg)
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#define SQLERRMC_LEN
Definition: sqlca.h:12
char sqlerrp[8]
Definition: sqlca.h:29
const char * name
Definition: encode.c:521
bool ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
Definition: connect.c:165
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
int i
void * arg
#define TRUE
Definition: c.h:217
#define pthread_t
Definition: pgbench.c:79
static struct @121 value