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