PostgreSQL Source Code  git master
thread-descriptor.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 "descriptor.pgc"
10 #ifdef ENABLE_THREAD_SAFETY
11 #ifdef WIN32
12 #define WIN32_LEAN_AND_MEAN
13 #include <windows.h>
14 #include <process.h>
15 #include <locale.h>
16 #else
17 #include <pthread.h>
18 #endif
19 #endif
20 #include <stdio.h>
21 
22 #define THREADS 16
23 #define REPEATS 50000
24 
25 
26 #line 1 "sqlca.h"
27 #ifndef POSTGRES_SQLCA_H
28 #define POSTGRES_SQLCA_H
29 
30 #ifndef PGDLLIMPORT
31 #if defined(WIN32) || defined(__CYGWIN__)
32 #define PGDLLIMPORT __declspec (dllimport)
33 #else
34 #define PGDLLIMPORT
35 #endif /* __CYGWIN__ */
36 #endif /* PGDLLIMPORT */
37 
38 #define SQLERRMC_LEN 150
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 
45 struct sqlca_t
46 {
47  char sqlcaid[8];
48  long sqlabc;
49  long sqlcode;
50  struct
51  {
52  int sqlerrml;
53  char sqlerrmc[SQLERRMC_LEN];
54  } sqlerrm;
55  char sqlerrp[8];
56  long sqlerrd[6];
57  /* Element 0: empty */
58  /* 1: OID of processed tuple if applicable */
59  /* 2: number of rows processed */
60  /* after an INSERT, UPDATE or */
61  /* DELETE statement */
62  /* 3: empty */
63  /* 4: empty */
64  /* 5: empty */
65  char sqlwarn[8];
66  /* Element 0: set to 'W' if at least one other is 'W' */
67  /* 1: if 'W' at least one character string */
68  /* value was truncated when it was */
69  /* stored into a host variable. */
70 
71  /*
72  * 2: if 'W' a (hopefully) non-fatal notice occurred
73  */ /* 3: empty */
74  /* 4: empty */
75  /* 5: empty */
76  /* 6: empty */
77  /* 7: empty */
78 
79  char sqlstate[5];
80 };
81 
82 struct sqlca_t *ECPGget_sqlca(void);
83 
84 #ifndef POSTGRES_ECPG_INTERNAL
85 #define sqlca (*ECPGget_sqlca())
86 #endif
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif
93 
94 #line 16 "descriptor.pgc"
95 
96 /* exec sql whenever sqlerror sqlprint ; */
97 #line 17 "descriptor.pgc"
98 
99 /* exec sql whenever not found sqlprint ; */
100 #line 18 "descriptor.pgc"
101 
102 
103 #if defined(ENABLE_THREAD_SAFETY) && defined(WIN32)
104 static unsigned __stdcall fn(void* arg)
105 #else
106 static void* fn(void* arg)
107 #endif
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 }
135 
136 int main ()
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 }
long sqlabc
Definition: sqlca.h:22
#define TRUE
Definition: ecpglib.h:35
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:759
struct sqlca_t::@124 sqlerrm
char sqlwarn[8]
Definition: sqlca.h:39
#define THREADS
int sqlerrml
Definition: sqlca.h:26
char sqlcaid[8]
Definition: sqlca.h:21
#define REPEATS
Definition: sqlca.h:19
#define sqlca
long sqlerrd[6]
Definition: sqlca.h:30
char sqlstate[5]
Definition: sqlca.h:53
#define SQLERRMC_LEN
long sqlcode
Definition: sqlca.h:23
void sqlprint(void)
Definition: error.c:336
static void * fn(void *arg)
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:712
char sqlerrp[8]
Definition: sqlca.h:29
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
int i
void * arg
#define pthread_t
Definition: pgbench.c:79
int main()