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