PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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

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

#define PGDLLIMPORT

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

#define POSTGRES_SQLCA_H

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

#define REPEATS   50000

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

Referenced by fn().

#define sqlca   (*ECPGget_sqlca())

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

Referenced by fn().

#define SQLERRMC_LEN   150

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

#define THREADS   16

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

Referenced by main().

Function Documentation

struct sqlca_t* ECPGget_sqlca ( void  )

Definition at line 142 of file misc.c.

References ecpg_init_sqlca(), malloc, NULL, 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(), 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
#define NULL
Definition: c.h:229
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
static void* fn ( void *  arg)
static

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

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

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

107 {
108  int i;
109 
110  for (i = 1; i <= REPEATS; ++i)
111  {
112  ECPGallocate_desc(__LINE__, "mydesc");
113 #line 29 "descriptor.pgc"
114 
115 if (sqlca.sqlcode < 0) sqlprint();
116 #line 29 "descriptor.pgc"
117 
118  ECPGdeallocate_desc(__LINE__, "mydesc");
119 #line 30 "descriptor.pgc"
120 
121 if (sqlca.sqlcode < 0) sqlprint();
122 #line 30 "descriptor.pgc"
123 
124  }
125 
126  return 0;
127 }
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
int main ( void  )

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

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

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