PostgreSQL Source Code  git master
thread-alloc.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-alloc.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-alloc.c.

◆ PGDLLIMPORT

#define PGDLLIMPORT

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

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

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

◆ REPEATS

#define REPEATS   50

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

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

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

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

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

◆ THREADS

#define THREADS   16

Definition at line 24 of file thread-alloc.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_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20

◆ fn()

static void* fn ( void *  arg)
static

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

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 
147 if (sqlca.sqlcode < 0) sqlprint();}
148 #line 41 "alloc.pgc"
149 
150  { ECPGsetcommit(__LINE__, "on", NULL);
151 #line 42 "alloc.pgc"
152 
153 if (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 
163 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
164 #line 45 "alloc.pgc"
165 
166 if (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 
175 if (sqlca.sqlcode < 0) sqlprint();}
176 #line 49 "alloc.pgc"
177 
178 
179  return 0;
180 }
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:2277
#define free(a)
Definition: header.h:65
static struct @157 value
int i
Definition: isn.c:73
void * arg
#define sprintf
Definition: port.h:240
#define REPEATS
Definition: thread-alloc.c:25
#define sqlca
Definition: thread-alloc.c:87
const char * name

References arg, ECPG_NOT_FOUND, ECPGconnect(), ECPGdisconnect(), ECPGdo(), ECPGsetcommit(), ECPGst_normal, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_NO_INDICATOR, free, i, name, REPEATS, sprintf, sqlca, sqlprint(), and value.

Referenced by _ArchiveEntry(), check_foreign_key(), close_walfile(), create_LifetimeEnd(), expand_tilde(), fmgr_symbol(), format_function_arguments(), format_function_signature(), main(), open_walfile(), ParseFuncOrColumn(), pgfnames_cleanup(), scan_directory(), scan_file(), SetOutput(), skipfile(), sql_check(), and transformFuncCall().

◆ main()

int main ( void  )

Definition at line 182 of file thread-alloc.c.

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 }
static void * fn(void *arg)
Definition: thread-alloc.c:119
#define THREADS
Definition: thread-alloc.c:24

References fn(), i, and THREADS.