PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
thread-prep.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdint.h>
#include <stdlib.h>
#include "ecpg_config.h"
#include <pthread.h>
#include <stdio.h>
Include dependency graph for thread-prep.c:

Go to the source code of this file.

Data Structures

struct  sqlca_t
 

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 
#define THREADS   16
 
#define REPEATS   50
 
#define POSTGRES_SQLCA_H
 
#define PGDLLIMPORT
 
#define SQLERRMC_LEN   150
 
#define sqlca   (*ECPGget_sqlca())
 

Functions

struct sqlca_tECPGget_sqlca (void)
 
static void * fn (void *arg)
 
int main ()
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file thread-prep.c.

◆ PGDLLIMPORT

#define PGDLLIMPORT

Definition at line 36 of file thread-prep.c.

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

Definition at line 30 of file thread-prep.c.

◆ REPEATS

#define REPEATS   50

Definition at line 25 of file thread-prep.c.

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

Definition at line 87 of file thread-prep.c.

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 40 of file thread-prep.c.

◆ THREADS

#define THREADS   16

Definition at line 24 of file thread-prep.c.

Function Documentation

◆ ECPGget_sqlca()

struct sqlca_t * ECPGget_sqlca ( void  )

Definition at line 108 of file misc.c.

109{
110 struct sqlca_t *sqlca;
111
112 pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
113
115 if (sqlca == NULL)
116 {
117 sqlca = malloc(sizeof(struct sqlca_t));
118 if (sqlca == NULL)
119 return NULL;
122 }
123 return sqlca;
124}
#define malloc(a)
Definition: header.h:50
static pthread_key_t sqlca_key
Definition: misc.c:58
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
static void ecpg_sqlca_key_init(void)
Definition: misc.c:102
static pthread_once_t sqlca_key_once
Definition: misc.c:59
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20

References ecpg_init_sqlca(), ecpg_sqlca_key_init(), malloc, pthread_getspecific(), pthread_setspecific(), sqlca, sqlca_key, and sqlca_key_once.

Referenced by ecpg_get_data(), ECPG_informix_reset_sqlca(), ecpg_init(), ecpg_log(), ecpg_process_output(), ecpg_raise(), ecpg_raise_backend(), ECPGallocate_desc(), ECPGconnect(), ECPGdeallocate_desc(), ECPGdisconnect(), ECPGget_desc(), ECPGget_desc_header(), ECPGnoticeReceiver(), ECPGset_var(), and sqlprint().

◆ fn()

static void * fn ( void *  arg)
static

Definition at line 119 of file thread-prep.c.

121{
122 int i;
123
124 /* exec sql begin declare section */
125
126
127
128
129#line 33 "prep.pgc"
130 int value ;
131
132#line 34 "prep.pgc"
133 char name [ 100 ] ;
134
135#line 35 "prep.pgc"
136 char query [ 256 ] = "INSERT INTO T VALUES ( ? )" ;
137/* exec sql end declare section */
138#line 36 "prep.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 "prep.pgc"
146
147if (sqlca.sqlcode < 0) sqlprint();}
148#line 41 "prep.pgc"
149
150 { ECPGsetcommit(__LINE__, "on", NULL);
151#line 42 "prep.pgc"
152
153if (sqlca.sqlcode < 0) sqlprint();}
154#line 42 "prep.pgc"
155
156 for (i = 1; i <= REPEATS; ++i)
157 {
158 { ECPGprepare(__LINE__, NULL, 0, "i", query);
159#line 45 "prep.pgc"
160
161if (sqlca.sqlcode < 0) sqlprint();}
162#line 45 "prep.pgc"
163
164 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
165 ECPGt_int,&(value),(long)1,(long)1,sizeof(int),
166 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
167#line 46 "prep.pgc"
168
169if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
170#line 46 "prep.pgc"
171
172if (sqlca.sqlcode < 0) sqlprint();}
173#line 46 "prep.pgc"
174
175 }
176 { ECPGdeallocate(__LINE__, 0, NULL, "i");
177#line 48 "prep.pgc"
178
179if (sqlca.sqlcode < 0) sqlprint();}
180#line 48 "prep.pgc"
181
182 { ECPGdisconnect(__LINE__, name);
183#line 49 "prep.pgc"
184
185if (sqlca.sqlcode < 0) sqlprint();}
186#line 49 "prep.pgc"
187
188
189 return 0;
190}
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_execute
Definition: ecpgtype.h:98
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_EORT
Definition: ecpgtype.h:63
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
static struct @161 value
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
Definition: prepare.c:315
int i
Definition: isn.c:72
void * arg
#define sprintf
Definition: port.h:240
#define REPEATS
Definition: thread-prep.c:25
#define sqlca
Definition: thread-prep.c:87
const char * name

References arg, ECPG_NOT_FOUND, ECPGconnect(), ECPGdeallocate(), ECPGdisconnect(), ECPGdo(), ECPGprepare(), ECPGsetcommit(), ECPGst_execute, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, i, name, REPEATS, sprintf, sqlca, sqlprint(), and value.

Referenced by main().

◆ main()

int main ( void  )

Definition at line 192 of file thread-prep.c.

193{
194 intptr_t i;
195#ifdef WIN32
196 HANDLE threads[THREADS];
197#else
198 pthread_t threads[THREADS];
199#endif
200
201 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
202#line 63 "prep.pgc"
203
204if (sqlca.sqlcode < 0) sqlprint();}
205#line 63 "prep.pgc"
206
207 { ECPGsetcommit(__LINE__, "on", NULL);
208#line 64 "prep.pgc"
209
210if (sqlca.sqlcode < 0) sqlprint();}
211#line 64 "prep.pgc"
212
213 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table if exists T", ECPGt_EOIT, ECPGt_EORT);
214#line 65 "prep.pgc"
215
216if (sqlca.sqlcode < 0) sqlprint();}
217#line 65 "prep.pgc"
218
219 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( i int )", ECPGt_EOIT, ECPGt_EORT);
220#line 66 "prep.pgc"
221
222if (sqlca.sqlcode < 0) sqlprint();}
223#line 66 "prep.pgc"
224
225 { ECPGdisconnect(__LINE__, "CURRENT");
226#line 67 "prep.pgc"
227
228if (sqlca.sqlcode < 0) sqlprint();}
229#line 67 "prep.pgc"
230
231
232#ifdef WIN32
233 for (i = 0; i < THREADS; ++i)
234 {
235 unsigned id;
236 threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
237 }
238
239 WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
240 for (i = 0; i < THREADS; ++i)
241 CloseHandle(threads[i]);
242#else
243 for (i = 0; i < THREADS; ++i)
244 pthread_create(&threads[i], NULL, fn, (void *) i);
245 for (i = 0; i < THREADS; ++i)
246 pthread_join(threads[i], NULL);
247#endif
248
249 return 0;
250}
@ ECPGst_normal
Definition: ecpgtype.h:97
static void * fn(void *arg)
Definition: thread-prep.c:119
#define THREADS
Definition: thread-prep.c:24

References ECPGconnect(), ECPGdisconnect(), ECPGdo(), ECPGsetcommit(), ECPGst_normal, ECPGt_EOIT, ECPGt_EORT, fn(), i, sqlca, sqlprint(), and THREADS.