PostgreSQL Source Code  git master
thread-descriptor.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
Include dependency graph for thread-descriptor.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   50000
 
#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-descriptor.c.

◆ PGDLLIMPORT

#define PGDLLIMPORT

Definition at line 34 of file thread-descriptor.c.

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

Definition at line 28 of file thread-descriptor.c.

◆ REPEATS

#define REPEATS   50000

Definition at line 23 of file thread-descriptor.c.

Referenced by fn(), and main().

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

Definition at line 85 of file thread-descriptor.c.

Referenced by fn().

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 38 of file thread-descriptor.c.

◆ THREADS

#define THREADS   16

Definition at line 22 of file thread-descriptor.c.

Referenced by main().

Function Documentation

◆ ECPGget_sqlca()

struct sqlca_t* ECPGget_sqlca ( void  )

Definition at line 142 of file misc.c.

References ecpg_init_sqlca(), malloc, pthread_getspecific(), pthread_setspecific(), and sqlca.

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(), main(), and sqlprint().

143 {
144 #ifdef ENABLE_THREAD_SAFETY
145  struct sqlca_t *sqlca;
146 
147  pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
148 
149  sqlca = pthread_getspecific(sqlca_key);
150  if (sqlca == NULL)
151  {
152  sqlca = malloc(sizeof(struct sqlca_t));
153  if (sqlca == NULL)
154  return NULL;
155  ecpg_init_sqlca(sqlca);
156  pthread_setspecific(sqlca_key, sqlca);
157  }
158  return sqlca;
159 #else
160  return &sqlca;
161 #endif
162 }
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
#define malloc(a)
Definition: header.h:50
Definition: sqlca.h:19
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
static struct sqlca_t sqlca
Definition: misc.c:63
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24

◆ fn()

static void* fn ( void *  arg)
static

Definition at line 106 of file thread-descriptor.c.

References ECPGallocate_desc(), ECPGdeallocate_desc(), i, REPEATS, sqlca, and sqlprint().

Referenced by _ArchiveEntry(), check_foreign_key(), ECPGis_noind_null(), expand_tilde(), format_function_arguments(), format_function_arguments_old(), format_function_signature(), ltq_regex(), main(), open_walfile(), pgfnames_cleanup(), and SetOutput().

108 {
109  int i;
110 
111 #ifdef WIN32
112 #ifdef _MSC_VER /* requires MSVC */
113  _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
114 #endif
115 #endif
116 
117  for (i = 1; i <= REPEATS; ++i)
118  {
119  ECPGallocate_desc(__LINE__, "mydesc");
120 #line 36 "descriptor.pgc"
121 
122 if (sqlca.sqlcode < 0) sqlprint();
123 #line 36 "descriptor.pgc"
124 
125  ECPGdeallocate_desc(__LINE__, "mydesc");
126 #line 37 "descriptor.pgc"
127 
128 if (sqlca.sqlcode < 0) sqlprint();
129 #line 37 "descriptor.pgc"
130 
131  }
132 
133  return 0;
134 }
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:759
#define REPEATS
#define sqlca
void sqlprint(void)
Definition: error.c:336
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:712
int i

◆ main()

int main ( void  )

Definition at line 136 of file thread-descriptor.c.

References fn(), i, pthread_t, THREADS, and TRUE.

137 {
138 #ifdef ENABLE_THREAD_SAFETY
139  int i;
140 #ifdef WIN32
141  HANDLE threads[THREADS];
142 #else
143  pthread_t threads[THREADS];
144 #endif
145 
146 #ifdef WIN32
147  for (i = 0; i < THREADS; ++i)
148  {
149  unsigned id;
150  threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, NULL, 0, &id);
151  }
152 
153  WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
154  for (i = 0; i < THREADS; ++i)
155  CloseHandle(threads[i]);
156 #else
157  for (i = 0; i < THREADS; ++i)
158  pthread_create(&threads[i], NULL, fn, NULL);
159  for (i = 0; i < THREADS; ++i)
160  pthread_join(threads[i], NULL);
161 #endif
162 #else
163  fn(NULL);
164 #endif
165 
166  return 0;
167 }
#define TRUE
Definition: ecpglib.h:35
#define THREADS
static void * fn(void *arg)
int i
#define pthread_t
Definition: pgbench.c:79