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 WIN32
11 #define WIN32_LEAN_AND_MEAN
12 #include <windows.h>
13 #include <process.h>
14 #include <locale.h>
15 #else
16 #include <pthread.h>
17 #endif
18 #include <stdio.h>
19 
20 #define THREADS 16
21 #define REPEATS 50000
22 
23 
24 #line 1 "sqlca.h"
25 #ifndef POSTGRES_SQLCA_H
26 #define POSTGRES_SQLCA_H
27 
28 #ifndef PGDLLIMPORT
29 #if defined(WIN32) || defined(__CYGWIN__)
30 #define PGDLLIMPORT __declspec (dllimport)
31 #else
32 #define PGDLLIMPORT
33 #endif /* __CYGWIN__ */
34 #endif /* PGDLLIMPORT */
35 
36 #define SQLERRMC_LEN 150
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 struct sqlca_t
44 {
45  char sqlcaid[8];
46  long sqlabc;
47  long sqlcode;
48  struct
49  {
50  int sqlerrml;
51  char sqlerrmc[SQLERRMC_LEN];
53  char sqlerrp[8];
54  long sqlerrd[6];
55  /* Element 0: empty */
56  /* 1: OID of processed tuple if applicable */
57  /* 2: number of rows processed */
58  /* after an INSERT, UPDATE or */
59  /* DELETE statement */
60  /* 3: empty */
61  /* 4: empty */
62  /* 5: empty */
63  char sqlwarn[8];
64  /* Element 0: set to 'W' if at least one other is 'W' */
65  /* 1: if 'W' at least one character string */
66  /* value was truncated when it was */
67  /* stored into a host variable. */
68 
69  /*
70  * 2: if 'W' a (hopefully) non-fatal notice occurred
71  */ /* 3: empty */
72  /* 4: empty */
73  /* 5: empty */
74  /* 6: empty */
75  /* 7: empty */
76 
77  char sqlstate[5];
78 };
79 
80 struct sqlca_t *ECPGget_sqlca(void);
81 
82 #ifndef POSTGRES_ECPG_INTERNAL
83 #define sqlca (*ECPGget_sqlca())
84 #endif
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif
91 
92 #line 14 "descriptor.pgc"
93 
94 /* exec sql whenever sqlerror sqlprint ; */
95 #line 15 "descriptor.pgc"
96 
97 /* exec sql whenever not found sqlprint ; */
98 #line 16 "descriptor.pgc"
99 
100 
101 #if defined(WIN32)
102 static unsigned __stdcall fn(void* arg)
103 #else
104 static void* fn(void* arg)
105 #endif
106 {
107  int i;
108 
109  for (i = 1; i <= REPEATS; ++i)
110  {
111  ECPGallocate_desc(__LINE__, "mydesc");
112 #line 28 "descriptor.pgc"
113 
114 if (sqlca.sqlcode < 0) sqlprint();
115 #line 28 "descriptor.pgc"
116 
117  ECPGdeallocate_desc(__LINE__, "mydesc");
118 #line 29 "descriptor.pgc"
119 
120 if (sqlca.sqlcode < 0) sqlprint();
121 #line 29 "descriptor.pgc"
122 
123  }
124 
125  return 0;
126 }
127 
128 int main ()
129 {
130  int i;
131 #ifdef WIN32
132  HANDLE threads[THREADS];
133 #else
134  pthread_t threads[THREADS];
135 #endif
136 
137 #ifdef WIN32
138  for (i = 0; i < THREADS; ++i)
139  {
140  unsigned id;
141  threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, NULL, 0, &id);
142  }
143 
144  WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
145  for (i = 0; i < THREADS; ++i)
146  CloseHandle(threads[i]);
147 #else
148  for (i = 0; i < THREADS; ++i)
149  pthread_create(&threads[i], NULL, fn, NULL);
150  for (i = 0; i < THREADS; ++i)
151  pthread_join(threads[i], NULL);
152 #endif
153 
154  return 0;
155 }
bool ECPGdeallocate_desc(int line, const char *name)
Definition: descriptor.c:748
bool ECPGallocate_desc(int line, const char *name)
Definition: descriptor.c:792
void sqlprint(void)
Definition: error.c:334
int i
Definition: isn.c:73
void * arg
Definition: sqlca.h:20
char sqlerrp[8]
Definition: sqlca.h:29
long sqlerrd[6]
Definition: sqlca.h:30
char sqlstate[5]
Definition: sqlca.h:53
char sqlwarn[8]
Definition: sqlca.h:39
long sqlabc
Definition: sqlca.h:22
char sqlcaid[8]
Definition: sqlca.h:21
struct sqlca_t::@153 sqlerrm
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
long sqlcode
Definition: sqlca.h:23
int sqlerrml
Definition: sqlca.h:26
static void * fn(void *arg)
#define THREADS
#define SQLERRMC_LEN
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:108
#define REPEATS
#define sqlca
int main()