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